question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Spyder with Different Environments

See original GitHub issue

Problem 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.

  1. 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.

  2. 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.

image

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.

  1. https://stackoverflow.com/questions/30170468/how-to-run-spyder-in-virtual-environment
  2. 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:closed
  • Created 2 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
rhkarlscommented, Jun 16, 2021

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 in spyder\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):

import sys; get_ipython().banner1='\nCurrent interpreter: ' + sys.executable

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

1reaction
ccordoba12commented, Jun 23, 2021

I am using Spyder with Anaconda and wanted to use it with different environments

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.

As you said import sys; print(f"Current interpreter: {sys.executable}") should work and it sometimes work.

The problem with the sys module was fixed in our 5.0.4 version, released two weeks ago. Please update.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Easy Way to switch Environments in Spyder? - Google Groups
Install Spyder in an environment created by pip and activated using source command rather than command. The reason being when you switch conda...
Read more >
Using Conda Python Environments with Spyder IDE and ...
1. Creating new environment with pip. This step has lot of help everywhere, just to refresh up. Use Anaconda Prompt for the following...
Read more >
How to run Spyder in virtual environment? - Stack Overflow
To use Spyder with another environment, the simplest way is to just install it directly into the environment from which you'd like to...
Read more >
Working with packages and environments in Spyder - GitHub
If you're looking for a way to use Spyder with different environments (e.g. one for simple data analysis, one for machine learning, one...
Read more >
How to manage projects and Environments using Python and ...
Create a virtual environment. · Activate it. Pip install the modules required. · Open spyder, and modify the python interpreter location. · Create ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found