Using Spyder with Different Environments
See original GitHub issueProblem Description
Sorry if this is not the right place to write a suggestion-ish post, I could not find the best place to post it. Not a problem exactly, more like a suggestion. I am using Spyder with Anaconda and wanted to use it with different environments. I decided to use the modular approach, which works fine. However, I have two problems\requests with it.
-
Each time I switch between environments, activating the environment from command prompt then executing the following command python -c “import sys; print(sys.executable)” is a bit exhaustive (File explore in Python interpreter works fine, if all the environments are in the same directory like …/anaconda3/envs/). Instead it would be nice to have a saved list of the old interpreters used. Having this selection on the console (right below) wouldn’t hurt either.
-
When I start a new console with a different environment, I would like to know which environment I am working with. It is again a bit exhaustive to check the interpreter every time if I am on the right environment or not. So when giving the info message, an additional information about the environment can be given.
Current info message: Python 3.8.10 (default, May 19 2021, 13:12:57) [MSC v.1916 64 bit (AMD64)] Type “copyright”, “credits” or “license” for more information.
IPython – An enhanced Interactive Python.
An example info message: Python 3.8.10 (default, May 19 2021, 13:12:57) [MSC v.1916 64 bit (AMD64)] Type “copyright”, “credits” or “license” for more information.
IPython – An enhanced Interactive Python. Current interpreter – C:\Users\theuser\anaconda3\envs\myEnv\python.exe
or
the active environment – myEnv
What steps reproduce the problem?
I used the following two links to use my own virtual environment with Spyder.
- https://stackoverflow.com/questions/30170468/how-to-run-spyder-in-virtual-environment
- https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder#working-with-other-environments-and-python-installations
What is the expected output? What do you see instead?
After Spyder has started, navigate to Preferences > Python Interpreter > Use the following interpreter and paste the path from Step 3 into the text box.
Versions
- Spyder version: 5.0.3
- Python version: 3.8.5
- Qt version: 5.9.7
- PyQt version: 5.9.2
- Operating System name/version: Windows 10
Dependencies
# Mandatory:
atomicwrites >=1.2.0 : 1.4.0 (OK)
chardet >=2.0.0 : 4.0.0 (OK)
cloudpickle >=0.5.0 : 1.6.0 (OK)
cookiecutter >=1.6.0 : 1.7.2 (OK)
diff_match_patch >=20181111 : 20200713 (OK)
intervaltree >=3.0.2 : 3.1.0 (OK)
IPython >=7.6.0 : 7.22.0 (OK)
jedi =0.17.2 : 0.17.2 (OK)
jsonschema >=3.2.0 : 3.2.0 (OK)
keyring >=17.0.0 : 23.0.1 (OK)
nbconvert >=4.0 : 6.0.7 (OK)
numpydoc >=0.6.0 : 1.1.0 (OK)
paramiko >=2.4.0 : 2.7.2 (OK)
parso =0.7.0 : 0.7.0 (OK)
pexpect >=4.4.0 : 4.8.0 (OK)
pickleshare >=0.4 : 0.7.5 (OK)
psutil >=5.3 : 5.8.0 (OK)
pygments >=2.0 : 2.9.0 (OK)
pylint >=1.0 : 2.8.3 (OK)
pyls >=0.36.2;<1.0.0 : 0.36.2 (OK)
pyls_black >=0.4.6 : 0.4.6 (OK)
pyls_spyder >=0.3.2;<0.4.0 : 0.3.2 (OK)
qdarkstyle =3.0.2 : 3.0.2 (OK)
qstylizer >=0.1.10 : 0.1.10 (OK)
qtawesome >=1.0.2 : 1.0.2 (OK)
qtconsole >=5.1.0 : 5.1.0 (OK)
qtpy >=1.5.0 : 1.9.0 (OK)
rtree >=0.9.7 : 0.9.7 (OK)
setuptools >=39.0.0 : 52.0.0.post20210125 (OK)
sphinx >=0.6.6 : 4.0.1 (OK)
spyder_kernels >=2.0.3;<2.1.0 : 2.0.3 (OK)
textdistance >=4.2.0 : 4.2.1 (OK)
three_merge >=0.1.1 : 0.1.1 (OK)
watchdog >=0.10.3;<2.0.0 : 1.0.2 (OK)
zmq >=17 : 20.0.0 (OK)
# Optional:
cython >=0.21 : 0.29.23 (OK)
matplotlib >=2.0.0 : 3.3.4 (OK)
numpy >=1.7 : 1.20.2 (OK)
pandas >=1.1.1 : 1.2.4 (OK)
scipy >=0.17.0 : 1.6.2 (OK)
sympy >=0.7.3 : 1.8 (OK)
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
My bad for suggesting those particular start-up lines and not making it clear that the IPython console currently does not support print statements like that at startup. I also tested to
import sys
and as you said notice it’s not imported - and the reason appears that its later deleted (del sys
is executed later in the startup internally inspyder\external-deps\spyder-kernels\spyder_kernels\console\start.py
- a separate bug if that is the case).However, I found a little workaround for your print issue and this works for me (add this to start up lines as you did above):
You can make it prettier of course, but this prints the path to the current interpreter each time a console is opened. You can also add something to get_ipython().banner2. They both appear blank by default, but if Spyder devs decide to use these banners you might overwrite something. Perhaps someone with more knowledge how this works internally can chime in
This is a duplicate of issue https://github.com/spyder-ide/ux-improvements/issues/10 and we’ll try to implement it in the coming months.
The problem with the sys module was fixed in our 5.0.4 version, released two weeks ago. Please update.