如何为anaconda设置默认的python路径?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39438049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 22:16:23  来源:igfitidea点击:

How to set the default python path for anaconda?

pythonanaconda

提问by catthe

i have installed anaconda on a linux machine. I noticed that after deactivating the anaconda environment with:

我已经在 linux 机器上安装了 anaconda。我注意到在停用 anaconda 环境后:

source deactivate

When running:

运行时:

which python

I get:

我得到:

/home/user/anaconda/bin/python

Instead of

代替

/usr/bin/python

How can i restore this setting?

我怎样才能恢复这个设置?

回答by IanSR

The comments somewhat cover the answer to the question, but to clarify:

评论在某种程度上涵盖了问题的答案,但要澄清:

When you installed Anaconda you must have agreed to have it added to your PATH. You'll want to check in your ~/.bash*files and look for any export PATH=lines to check this. So Anaconda is alwayson your path. The source deactivatecommand will only deactivate "sub" Conda environments. It will never remove what is called the "root" Conda environment (the one you originally installed). If you don't want Anaconda on your PATHby default then remove it from your ~/.bash*startup files. Then when you want to use Anaconda you'll need to add it to your PATH. Or just add the specific Conda environment you are interested in to your PATHdirectly, and don't worry about the activateand deactivatescripts. At their core all they do is modify PATH.

当您安装 Anaconda 时,您必须同意将其添加到您的 PATH 中。您需要检入您的~/.bash*文件并查找任何export PATH=行来检查这一点。因此,Anaconda始终在您的道路上。该source deactivate命令只会停用“子”Conda 环境。它永远不会删除所谓的“根”Conda 环境(您最初安装的环境)。如果您不希望在PATH默认情况下使用Anaconda,请将其从~/.bash*启动文件中删除。然后当你想使用 Anaconda 时,你需要将它添加到你的PATH. 或者直接将您感兴趣的特定 Conda 环境添加到您的PATH,而不必担心activatedeactivate脚本。在他们的核心,他们所做的就是修改PATH.

I hope that helps clarify things.

我希望这有助于澄清事情。

回答by Kevin Chou

To get back to the former default, I comment out the entry setting the pathbin the .bashrcfile and get these results:

为了恢复到以前的默认设置,我注释掉了设置 pathbin.bashrc文件的条目并得到以下结果:

$ which python
/usr/bin/python
$ python -v
python 2.7.*

回答by Pierre ALBARèDE

If you have installed something, you want to use it before older installs, in general.

如果您已经安装了某些东西,一般来说,您希望在较旧的安装之前使用它。

Your path is well set: your install is searched before system install.

您的路径设置得很好:在系统安装之前搜索您的安装。

If you want to use system python, run % /usr/bin/python.

如果你想使用系统 python,运行% /usr/bin/python.

If you don't want anaconda, just trash it (or move it somewhere ouside of path).

如果您不想要 anaconda,只需将其丢弃(或将其移到路径之外的某个地方)。

This may help: % which -a python.

这可能有帮助: % which -a python.

回答by vuvu

Anaconda comes with its own everything, and they ask if you wish to use their software as a default when you install it by adding their bin first to your PATH variable. If you do that, you can only manually remove it later from .bashrc to undo this action.

Anaconda 自带一切,他们会询问您是否希望在安装时默认使用他们的软件,方法是首先将其 bin 添加到您的 PATH 变量中。如果这样做,您只能稍后从 .bashrc 中手动删除它以撤消此操作。

I chose not to do it, but i made a shell script to start spyder and use the anaconda distribution when i wish to, without altering my PATH by calling spyder like this from the shell script:

我选择不这样做,但我制作了一个 shell 脚本来启动 spyder 并在我愿意时使用 anaconda 发行版,而无需通过从 shell 脚本中这样调用 spyder 来更改我的 PATH:

PATH=/home/<... path to where i installed anaconda>/bin:$PATH spyder &

This means that i am adding their distribution's bin to the path only for the extent of running that command (spyder), otherwise my environment is unaffected by anaconda.

这意味着我仅在运行该命令 (spyder) 的范围内将其发行版的 bin 添加到路径中,否则我的环境不受 anaconda 的影响。

If i wish to add things to it, i pass an option to the shell when i source it and that triggers these actions:

如果我想向其中添加内容,我会在获取它时将一个选项传递给 shell,这会触发以下操作:

PATH=/home/<... path to where i installed anaconda>/bin:$PATH
PS1='\[3[1;34m\](A)\w:\[3[0m\] '

so that i see (with colors!) that in this terminal i am using an altered PATH, the one with python3 and such from anaconda, etc... When done, i kill the terminal! :)

这样我就可以看到(带有颜色!)在这个终端中我使用了一个改变过的路径,那个带有 python3 的路径,等等来自 anaconda 等等......完成后,我杀死了终端!:)