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

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

问题描述

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

在线研究后的前两个建议是:

  1. 首先设置虚拟环境并点更改 Spyder 的首选项,例如

    来自读者的

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

    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?

    解决方案

    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
    

    EDIT from a reader:

    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天全站免登陆