问题
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
To activate it :
source activate myenv # (in linux, you can use . as a shortcut for "source")
activate myenv # (in windows - note that you should be in your c:\anaconda2 directory)
UPDATE. I have tested it with Ubuntu 18.04. Now you have to install spyder additionally for the new environment with this command (after the activation of the environment with the command above):
conda install spyder
(I have also tested the installation with pip, but for Python 3.4 or older versions, it breaks with the library dependencies error that requires manual installation.)
And now to run Spyder with Python 3.4 just type:
spyder
回答2:
Here is a quick way to do it in 2019. 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"
There are still some minor bugs when setting up your environment (most of which are solved by restarting the Navigator), if you find a bug, please post it in Anaconda Issues bug-tracker. Thanks.
If even then this doesn't work, Navigator could still be useful, clicking on >Enviroments takes you to a management window for the modules installed on such enviroment, searching and selecting the spyder related ones, and then clicking on Apply will install them and their dependencies.
回答3:
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)
回答4:
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.
回答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:
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.
来源:https://stackoverflow.com/questions/30170468/how-to-run-spyder-in-virtual-environment