12

Is there a way to force conda to use the system version of python (along with all of the system libraries) in a given env?

I have conda enabled by default in my shell, which can get a bit annoying, because if I try to run a system python app, it gets a different version of python to what it is expecting (python still defaults to 2.7 on *buntu), and often won't run. I would like the root env of conda to just be a redirect to the system python install.

4

2 回答 2

1

您需要编辑所有用户 shell 运行命令,例如您的 .bashrc 文件,以将 anaconda 的 bin 目录添加到 pathexport PATH=~/anaconda/bin:$PATH中,而在您的 root 运行命令中添加export PATH=$PATH:~/anaconda/bin。在这两种情况下,您都可以访问该conda命令。您可以通过键入来检查将运行哪个 python $env python --version。您还可以使用 . 检查哪些其他版本可用以及它们的优先级顺序(如果另一个被删除)$type -a python。当然,请确保您的可执行 python 文件具有#!/usr/bin/env python而不是其他指向 python 可执行文件的直接路径。有关更多信息 Google BASH Shell 查找查询,例如http://www.cyberciti.biz/tips/an-example-how-shell-understand-which-program-to-run-part-ii.html

于 2015-04-29T17:52:37.373 回答
1

只需从中删除python符号链接~/miniconda3/bin/似乎就可以完成这项工作。

$ which python           
/home/naught101/miniconda3/bin/python
$ rm /home/naught101/miniconda3/bin/python
$ which python                            
/usr/bin/python
$ source activate science                 
discarding /home/naught101/miniconda3/bin from PATH
prepending /home/naught101/miniconda3/envs/science/bin to PATH
(science)$ which python           
/home/naught101/miniconda3/envs/science/bin/python
(science)$ source deactivate                       
discarding /home/naught101/miniconda3/envs/science/bin from PATH
$ which python     
/usr/bin/python

到目前为止,这似乎并没有给我带来任何问题。不幸的是,这同样不适用于~/miniconda/bin/python3,因为 conda 在切换到使用相同 python 版本的其他环境时需要它。然而,这个问题并没有从一开始就引起那么多问题。

如果这确实引起了问题,那么撤消很容易,只是cd ~/miniconda/bin/; ln -s python3 python(或您在 conda root 环境中使用的任何版本的 python)。您可能需要激活/停用 env 以使该版本的 python 回到您的 PATH 中。

于 2015-05-05T03:25:56.560 回答