我已经安装了Anaconda并创建了两个额外的环境:py3k(包含Python 3.3)和py34(包含Python 3.4)。除此之外,我还有一个名为“root”的默认环境,它是Anaconda安装程序默认创建的,并保存Python 2.7。最后一个是默认的,每当我从终端启动'ipython'时,它都会给我2.7版本。为了使用Python 3.4,我需要发出命令(在shell中)

source activate py34
ipython

将默认环境更改为Python 3.4。这很好,但这很烦人,因为大部分时间我都在使用Python 3.4,而不是Python 2.7(我使用Python 2.7是为了教学目的,说来话长)。无论如何,我想知道如何将默认环境更改为Python 3.4,请记住,我不想从头开始重新安装所有内容。


当前回答

正确答案(截至2018年12月)是……你不能。升级conda install python=3.6可能会工作,但如果你有必要的包,但不能卸载,则可能不会。

Anaconda uses a default environment named base and you cannot create a new (e.g. python 3.6) environment with the same name. This is intentional. If you want your base Anaconda to be python 3.6, the right way to do this is to install Anaconda for python 3.6. As a package manager, the goal of Anaconda is to make different environments encapsulated, hence why you must source activate into them and why you can't just quietly switch the base package at will as this could lead to many issues on production systems.

其他回答

我对这里给出的任何答案都不满意,因为在我的平台上激活一个环境需要几秒钟(无论出于什么原因)

我修改了我的路径变量,这样我想要的默认环境比实际的默认环境具有优先级。

在我的例子中,我使用以下命令来完成环境“py35”:

setx PATH "%userprofile%\Anaconda3\envs\py35\;%PATH%"
setx PATH "%userprofile%\Anaconda3\envs\py35\Scripts;%PATH%"

要找出您的环境存储在哪里,请激活它并输入where python。 我还不确定这种方法是否有任何缺点。因为它也改变了conda可执行文件的默认路径。如果是这样的话,请发表评论。

在桌面或任务栏上创建一个anaconda提示的快捷方式,然后在快捷方式的属性中确保将“Target:”中的最后一个路径修改为你的环境的路径:

C:\Users\BenBouali\Anaconda3\ WILL CHANGE INTO C:\Users\BenBouali\Anaconda3\envs\ tensorflow-gpu

预览

这样你就可以使用这个快捷方式在点击它的时候打开一个特定的环境,你也可以把它添加到你的路径中,现在你就可以从Windows运行框中运行它了,只需要输入快捷方式的名称。

对于Jupyter和Windows用户,您可以将Jupyter Notebook (anaconda3)快捷方式中的目标路径从C:\Users\<YourUserName>\anaconda3更改为C:\Users\<YourUserName>\anaconda3\envs\<YourEnvironmentName>

你也可以对Anaconda Prompt做同样的事情,等等。

在改变路径之后,您可以通过在Jupyter中打开一个终端并运行conda info——envs来检查您的活动环境。

尝试了source activate default_3_9和source conda activate default_3_9

但是conda激活了default_3_9

我试图更新蟒蛇,以便使用Python 3.10.4和Spyder 5.3.2。实际上,我想在Spyder控制台中设置Pycharm使用的Python解释器,但它需要最新的Spyder版本。我没有尝试所有可能的解决方案(它等待我使用窗口批处理和修改这里给出的路径解决方案),但是:

Since I couldn't update the Anaconda base due to the well-known error on the "Solving environment". Then Python and Spyder remain the same. Creating a new env allows to get the last Python and then his newest Spyder version but it doesn't actualize the Anaconda shortcuts and even the Anaconda navigator if you set it to this new env still has some inconsistencies like keeping the older Spyder version in his menu. Besides, on point 2, changing the shortcuts target path doesn't work for me. Finally, I create a new shortcut of the Spyder file from the Scripts folder inside the environment directory ( C:\Users<userName>>\Anaconda3\envs<EnvName>\Scripts )

我不能使用默认的Anaconda快捷方式,但我有我想要的和快速访问。