问题描述
我已经使用anaconda一段时间了,它的Python可执行文件位于/ Users / ufo / opt / anaconda3 / bin / python。我试图用conda创建一个环境,新环境将使用将此Python复制到环境的bin中。
I have been using anaconda for a while, and its Python executable is located at /Users/ufo/opt/anaconda3/bin/python. I have tried to create an environment with conda, and the new environment would use copy this Python to environment's bin.
但是,在当前的Anaconda版本中,新环境不会使用anaconda的Python,但使用Mac OS上预装的原始Python,即python 2。*。
However, with current Anaconda versation, the new environment will not use anaconda's Python, but use the original Python pre-installed with Mac OS, which was python 2.*.
以下是检查anaconda python版本,创建/激活新环境,然后再次检查。从片段中,我注意到$ PATH以及Python版本的变化。
Here is a snip of checking anaconda python version, creating/activating new environment, and checking again. From the snip I noticed the change of $PATH as well as Python versions.
我如何在新环境中仍然使用anaconda的Python?
How can I still use anaconda's Python in new environment?
(base) ufo@ufodeMacBook-Pro:~$ echo $PATH
/Users/ufo/opt/anaconda3/bin:/Users/ufo/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(base) ufo@ufodeMacBook-Pro:~$ which python
/Users/ufo/opt/anaconda3/bin/python
(base) ufo@ufodeMacBook-Pro:~$ python -V
Python 3.7.5
(base) ufo@ufodeMacBook-Pro:~$ conda info -e
# conda environments:
#
base * /Users/ufo/opt/anaconda3
(base) ufo@ufodeMacBook-Pro:~$ conda create -n msg
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /Users/ufo/opt/anaconda3/envs/msg
Proceed ([y]/n)?
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate msg
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) ufo@ufodeMacBook-Pro:~$ conda activate msg
(msg) ufo@ufodeMacBook-Pro:~$ which python
/usr/bin/python
(msg) ufo@ufodeMacBook-Pro:~$ echo $PATH
/Users/ufo/opt/anaconda3/envs/msg/bin:/Users/ufo/opt/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(msg) ufo@ufodeMacBook-Pro:~$ conda info -e
# conda environments:
#
base /Users/ufo/opt/anaconda3
msg * /Users/ufo/opt/anaconda3/envs/msg
(msg) ufo@ufodeMacBook-Pro:~$ python -V
Python 2.7.10
(msg) ufo@ufodeMacBook-Pro:~$
推荐答案
一个简单的解决方法是将路径导出到激活环境后需要的python。如下面的片段所示。
An easy workaround would be to export the path to the python you require once you activate the environment. As can be seen in the below snipet.
export PATH=/Users/ufo/opt/anaconda3/bin/:$PATH
然后可以使用哪个python
来查看如果您的python设置正确
you can then use which python
to see if your python is rightly set
要使用您的环境python
To use your environments python do
export PATH=/Users/ufo/opt/anaconda3/envs/msg/bin/:$PATH
这篇关于python conda:创建了一个环境,但是没有使用conda的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!