如何在虚拟环境中运行Spyder? [英] How to run Spyder in virtual environment?

查看:1790
本文介绍了如何在虚拟环境中运行Spyder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用随Anaconda发行版安装的Spyder,该发行版默认使用Python 2.7.当前,我需要使用Python 3.4设置开发虚拟环境.

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. 首先设置虚拟环境并指向更改Spyder的首选项,例如此处;
  2. 在虚拟环境本身中安装所有Spyder依赖项(例如PyQt4),例如G. 此处;
  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.

是否存在一种解决方案,可以在激活所需的虚拟环境后自动使用所需的Python版本运行Spyder?

Is there a solution that would allow to run Spyder with required Python version automatically after activating the required virtual environment?

推荐答案

可以选择使用所需的Python版本在Anaconda中创建虚拟环境.

conda create -n myenv python=3.4

要激活它:

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)

更新.我已经在Ubuntu 18.04上对其进行了测试.现在,您必须使用此命令为新环境另外安装spyder(在使用上述命令激活环境之后):

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

(我还用pip测试了安装,但是对于Python 3.4或更早版本,它会因需要手动安装而导致库依赖错误而中断.)

(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.)

现在要在Python 3.4中运行Spyder,只需键入:

And now to run Spyder with Python 3.4 just type:

spyder

阅读者的

对于正常打开,请使用"Anaconda Prompt"(Anaconda提示) > activate myenv> spyder(然后"Anaconda Prompt"必须保持打开状态,您不能将其用于其他命令,并且强制关闭将关闭Spyder).当然,这比"Anaconda Navigator"的长负载要快. >切换环境>启动Spyder(@adelriosantiago的答案).

For a normal opening, use "Anaconda Prompt" > activate myenv > spyder (then the "Anaconda Prompt" must stay open, you cannot use it for other commands, and a force-close will shut down Spyder). This is of course faster than the long load of "Anaconda Navigator" > switch environment > launch Spyder (@adelriosantiago's answer).

这篇关于如何在虚拟环境中运行Spyder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆