How to run Spyder in virtual environment?

匿名 (未验证) 提交于 2019-12-03 03:02:02

问题:

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:

  1. to set up virtual environment first and to point change the preferences of Spyder , e.g here;
  2. 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:

  1. Open Anaconda Navigator
  2. Create your new environment as you wish. I named this environment "test". Click on it to activate it.

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

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

  1. run spyder from the environment (after source activate)
  2. 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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!