如何更改默认 Anaconda python 环境

时间:2023-01-24
本文介绍了如何更改默认 Anaconda python 环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

I've installed Anaconda and created two extra environments: py3k (which holds Python 3.3) and py34 (which holds Python 3.4). Besides those, I have a default environment named 'root' which the Anaconda installer created by default and which holds Python 2.7. This last one is the default, whenever I launch 'ipython' from the terminal it gives me version 2.7. In order to work with Python 3.4, I need to issue the commands (in the shell)

source activate py34
ipython

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

which change the default environment to Python 3.4. This works fine, but it's annoying since most of the time I work on Python 3.4, instead of Python 2.7 (which I hold for teaching purposes, it's a rather long story). Anyway, I'll like to know how to change the default environment to Python 3.4, bearing in mind that I don't want to reinstall everything from scratch.

推荐答案

如果你只是想暂时换个环境,用

If you just want to temporarily change to another environment, use

source activate environment-name

ETA:这可能已被弃用.我相信当前正确的命令是:

ETA: This may be deprecated. I believe the current correct command is:

source conda activate environment-name

(您可以使用 conda create 创建 environment-name)

(you can create environment-name with conda create)

永久更改,除了创建一个运行上述代码的启动脚本之外别无他法.

To change permanently, there is no method except creating a startup script that runs the above code.

通常最好只创建新环境.但是,如果你真的想在默认环境下更改 Python 版本,你可以这样做:

Typically it's best to just create new environments. However, if you really want to change the Python version in the default environment, you can do so as follows:

首先,通过运行确保您拥有最新版本的 conda

First, make sure you have the latest version of conda by running

conda update conda

然后运行

conda install python=3.5

这将尝试将根环境中的所有包更新到 Python 3 版本.如果不可能(例如,因为某些包不是为 Python 3.5 构建的),它会给您一条错误消息,指出是哪个包导致了问题.

This will attempt to update all your packages in your root environment to Python 3 versions. If it is not possible (e.g., because some package is not built for Python 3.5), it will give you an error message indicating which package(s) caused the issue.

如果您使用 pip 安装软件包,则必须重新安装它们.

If you installed packages with pip, you'll have to reinstall them.

这篇关于如何更改默认 Anaconda python 环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 Windows 10 上无法识别 Conda 命令 下一篇:配置 Spark 以使用 Jupyter Notebook 和 Anaconda

相关文章

最新文章