可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have been using Spyder installed with with Anaconda distribution which uses Python 2.7 as default. Currently I need to set up a development virtual environment with Python 3.4.
Top two suggestions after research online are:
- to set up virtual environment first and to point change the preferences of Spyder , e.g here;
- to install all Spyder dependencies, like PyQt4, in the virtual environment itself, e. g. here ;
Both recommendations are cumbersome and do not look like smart options for development.
Is there a solution that would allow to run Spyder with required Python version automatically after activating the required virtual environment?
回答1:
There is an option to create virtual environments in Anaconda with required Python version.
conda create -n myenv python=3.4 anaconda
This will create virtual environment to virtualenv
. To activate it :
source activate myenv # (in linux) activate myenv # (in windows - note that you should be in your c:\anaconda2 directory)
To check the current environment has been changed:
conda info -e
And now to run Spyder with Python 3.4 just type:
spyder
回答2:
Additional to tomaskazemekas's answer: you should install spyder in that virtual environment by:
conda install -n myenv spyder
(on Windows, for Linux or MacOS, you can search for similar commands)
回答3:
Here is a quick way to do it in 2018. Using the Anaconda Navigator:
- Open Anaconda Navigator
- Create your new environment as you wish. I named this environment "test". Click on it to activate it.

- Go to "Home" and click on "Install" under the Spyder box.

- Click "Launch/Run"
If you find a bug in Anaconda Navigator please post it in Anaconda Issues bug-tracker. Thanks.
回答4:
I just had the same problem trying to get Spyder to run in Virtual Environment.
The solution is simple:
Activate your virtual environment.
Then pip install Spyder and its dependencies (PyQt5) in your virtual environment.
Then launch Spyder3 from your virtual environment CLI.
It works fine for me now.
回答5:
The above answers are correct but I calling spyder
within my virtualenv would still use my PATH
to look up the version of spyder in my default anaconda env. I found this answer which gave the following workaround:
source activate my_env # activate your target env with spyder installed conda info -e # look up the directory of your conda env find /path/to/my/env -name spyder # search for the spyder executable in your env /path/to/my/env/then/to/spyder # run that executable directly
I chose this over modifying PATH
or adding a link to the executable at a higher priority in PATH
since I felt this was less likely to break other programs. However, I did add an alias to the executable in ~/.bash_aliases
.
回答6:
What worked for me :
- run spyder from the environment (after source activate)
- go to Tools --> preferences --> python Interpreter and select the python file from the env you want to link to
spyder
ex : /home/you/anaconda3/envs/your_env/bin/python
Worked on ubuntu 16, spyder3, python3.6.