简体   繁体   English

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

[英]How to set the default python path for anaconda on Linux?

I have installed anaconda on a Linux machine.我已经在 Linux 机器上安装了 anaconda。 I noticed that after deactivating the anaconda environment with:我注意到在停用 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?如何恢复此设置?

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.当您安装 Anaconda 时,您必须同意将其添加到您的 PATH 中。 You'll want to check in your ~/.bash* files and look for any export PATH= lines to check this.您需要检查~/.bash*文件并查找任何export PATH=行以进行检查。 So Anaconda is always on your path.因此,Anaconda始终在您的道路上。 The source deactivate command will only deactivate "sub" Conda environments. source deactivate命令只会停用“子”Conda 环境。 It will never remove what is called the "root" Conda environment (the one you originally installed).它永远不会删除所谓的“根”Conda 环境(您最初安装的环境)。 If you don't want Anaconda on your PATH by default then remove it from your ~/.bash* startup files.如果默认情况下您不希望 Anaconda 出现在PATH ,则将其从您的~/.bash*启动文件中删除。 Then when you want to use Anaconda you'll need to add it to your PATH .然后,当您想使用 Anaconda 时,您需要将其添加到PATH Or just add the specific Conda environment you are interested in to your PATH directly, and don't worry about the activate and deactivate scripts.或者直接将您感兴趣的特定 Conda 环境添加到您的PATH ,而不必担心activatedeactivate脚本。 At their core all they do is modify PATH .他们所做的核心就是修改PATH

I hope that helps clarify things.我希望这有助于澄清事情。

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. Anaconda 自带一切,他们会询问您是否希望在安装时默认使用他们的软件,方法是首先将其 bin 添加到您的 PATH 变量中。 If you do that, you can only manually remove it later from .bashrc to undo this action.如果这样做,您只能稍后从 .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='\[\033[1;34m\](A)\w:\[\033[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 等等......完成后,我杀死了终端! :) :)

To get back to the former default, I comment out the entry setting the pathbin the .bashrc file and get these results:为了恢复到以前的默认值,我注释掉了设置 pathbin .bashrc文件的条目并得到以下结果:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM