Max*_*ons 13 python anaconda pyenv
我正在使用 pyenv 来管理 python 安装和虚拟环境 - 我希望 anaconda 成为这样的安装之一,并且能够使用 anaconda python 创建虚拟环境。使用pyenv install anaconda3-2019.03成功安装,我可以激活版本pyenv global anaconda3-2019.03:
SamLee-PC:~ max$ pyenv versions
system
2.7.10
2.7.10/envs/flask_tutorial
* 3.7.4 (set by /Users/max/.pyenv/version)
3.7.4/envs/learning_python
3.7.4/envs/microblog
3.7.4/envs/stocktool
3.7.4/envs/test1
anaconda3-2019.03
anaconda3-2019.03/envs/datsci
datsci
flask_tutorial
learning_python
microblog
stocktool
test1
SamLee-PC:~ max$ pyenv which python
/Users/max/.pyenv/versions/3.7.4/bin/python
SamLee-PC:~ max$ pyenv global anaconda3-2019.03
(anaconda3-2019.03) SamLee-PC:~ max$ pyenv which python
/Users/max/.pyenv/versions/anaconda3-2019.03/bin/python
(anaconda3-2019.03) SamLee-PC:~ max$ pyenv which conda
/Users/max/.pyenv/versions/anaconda3-2019.03/bin/conda
Run Code Online (Sandbox Code Playgroud)
(不知道为什么只有anaconda安装才在命令提示符中添加python版本)
当我创建一个新的虚拟环境 ( pyenv virtualenv anaconda3-2019.03 datsci) 时,它似乎按预期工作:
SamLee-PC:~ max$ pyenv which python
/Users/max/.pyenv/versions/3.7.4/bin/python
SamLee-PC:~ max$ cd code/linkedin/datsci
(datsci) SamLee-PC:datsci max$ pyenv which python
/Users/max/.pyenv/versions/datsci/bin/python
(datsci) SamLee-PC:datsci max$
Run Code Online (Sandbox Code Playgroud)
这是pyenv which python在我的其他虚拟环境中返回的相同相对位置,它们都可以正常工作。
问题是在虚拟环境中运行的 python 版本无法访问所有 anaconda 的包:
(datsci) SamLee-PC:datsci max$ anaconda-navigator
pyenv: anaconda-navigator: command not found
The `anaconda-navigator' command exists in these Python versions:
anaconda3-2019.03
(datsci) SamLee-PC:datsci max$
Run Code Online (Sandbox Code Playgroud)
虽然如果我手动激活 python 安装它会:
SamLee-PC:~ max$ pyenv global anaconda3-2019.03
(anaconda3-2019.03) SamLee-PC:~ max$ anaconda-navigator
WARNING: The conda.compat module is deprecated and will be removed in a future release.
/Users/max/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/anaconda_navigator/api/conda_api.py:1364: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
data = yaml.load(f)
2019-09-21 14:03:38,666 - ERROR download_api._download:234
Invalid url https://www.anaconda.com/wp-content/uploads/2017/05/Webinar20-20Three20Ways20to20Move20your20Data20Science20Projects20to20Production.png
#anaconda navigator GUI opens
Run Code Online (Sandbox Code Playgroud)
(奇怪的是,蟒蛇版本,datsci点不似乎认识到畅达:
(datsci) SamLee-PC:datsci max$ pyenv which python
/Users/max/.pyenv/versions/datsci/bin/python
(datsci) SamLee-PC:datsci max$ conda
usage: conda [-h] [-V] command ...
conda is a tool for managing and deploying applications, environments and packages.
...
Run Code Online (Sandbox Code Playgroud)
问题是,据我所知,每当我想要 anaconda 时以这种方式激活 python 版本意味着我只能访问一个版本的 anaconda python - 违背了在虚拟环境中使用它的目的。
还有一个难题 - 我注意到对于我的其他虚拟环境,~/.pyenv/versions/name-of-virtualenv包含一个文件pyvenv.cfg,其中包含例如以下内容:
1 home = /Users/max/.pyenv/versions/3.7.4/bin
2 include-system-site-packages = false
3 version = 3.7.4
Run Code Online (Sandbox Code Playgroud)
中没有这样的文件~/.pyenv/versions/datsci,所以我添加了一个:
1 home = /Users/max/.pyenv/versions/anaconda3-2019.03/bin
2 include-system-site-packages = false
3 version = anaconda3-2019.03
Run Code Online (Sandbox Code Playgroud)
无济于事。
FWIW该目录的内容是:
(anaconda3-2019.03) SamLee-PC:datsci max$ pwd
/Users/max/.pyenv/versions/datsci
(anaconda3-2019.03) SamLee-PC:datsci max$ ls
bin conda-meta include lib pyvenv.cfg share ssl
(anaconda3-2019.03) SamLee-PC:datsci max$
Run Code Online (Sandbox Code Playgroud)
我想知道我的pyvenv.cfgdatsci 文件中是否有错误的内容......但我不知所措。
我真的很喜欢 pyenv 的工作方式,我想继续使用它。有没有办法将 anaconda 配置为在 pyenv 下正常运行?
我卸载了 pyenv 管理的 anaconda,并按照 Simba 的建议进行了全新安装。现在默认情况下 pyenv 确定活动的 python 安装,我可以使用以下命令激活 conda conda activate base:
Maxs-MacBook-Air:~ max$ which python
/Users/max/.pyenv/shims/python
Maxs-MacBook-Air:~ max$ conda activate base
(base) Maxs-MacBook-Air:~ max$ which python
/Users/max/anaconda3/bin/python
(base) Maxs-MacBook-Air:~ max$
Run Code Online (Sandbox Code Playgroud)
但是,在使用 创建新的 conda 环境后conda create --name datsci,新的 conda 环境似乎无法正确激活:
Maxs-MacBook-Air:~ max$ conda activate datsci
(datsci) Maxs-MacBook-Air:~ max$ which python
/Users/max/.pyenv/shims/python
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
以下是我的内容.bash_profile:
1 export PATH="/Users/max/.pyenv/bin:$PATH"
2 eval "$(pyenv init -)"
3 eval "$(pyenv virtualenv-init -)"
4
5 # >>> conda initialize >>>
6 # !! Contents within this block are managed by 'conda init' !!
7 __conda_setup="$('/Users/max/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
8 if [ $? -eq 0 ]; then
9 eval "$__conda_setup"
10 else
11 if [ -f "/Users/max/anaconda3/etc/profile.d/conda.sh" ]; then
12 . "/Users/max/anaconda3/etc/profile.d/conda.sh"
13 else
14 export PATH="/Users/max/anaconda3/bin:$PATH"
15 fi
16 fi
17 unset __conda_setup
18 # <<< conda initialize <<<
Run Code Online (Sandbox Code Playgroud)
复制 Simba 中的 if 语句是否重要 .bash_profile?
问题解决了,我不得不在新环境中安装python。
Sim*_*mba 47
个人建议:不要pyenv用来安装Anaconda或Miniconda。
双方pyenv并conda能够管理不同的Python环境。该anaconda由安装pyenv只宜作为一个Python解释器。Python环境创建从蟒蛇的安装pyenv仍然被处理pyenv virtualenv,但没有conda env create。
我一直在使用这两个工具。事实证明,最好的解决方案是单独安装conda、pyenv单独管理它们的虚拟环境。
pyenvconda但不激活任何环境安装pyenv.
正常安装 Anaconda 或 Miniconda,而不是通过pyenv install.
确保pyenv和conda命令在交互式 shell 中可用。
初始化pyenv通过将下面的内容放入外壳初始化文件(.bashrc用于猛砸,.zshrc为ZSH)。
# Put the content into ~/.bashrc or ~/.bash_profile for Bash,
# .zshrc for ZSH
# you may need to add dir of command `pyenv` into PATH,
# if command pyenv is not available yet
if command -v pyenv &>/dev/null; then
eval "$(pyenv init -)"
fi
if command -v pyenv-virtualenv &>/dev/null; then
eval "$(pyenv virtualenv-init -)"
fi
Run Code Online (Sandbox Code Playgroud)
公开命令conda但不激活任何环境,甚至base环境。在您的 shell 中执行以下命令。
# Run the content in the shell
# init conda, the following command write scripts into your shell init file automatically
conda init
# disable init of env "base"
conda config --set auto_activate_base false
Run Code Online (Sandbox Code Playgroud)
注意:此设置后,默认 python 是由pyenv global. 使用pyenv和conda分别管理环境。
管理虚拟环境的示例。
# virtual environments from pyenv
pyenv install 3.6.9
pyenv virtualenv 3.6.9 new-env
pyenv activate new-env
pyenv deactive
# You can also use `pyenv local`
# virtual environments from conda
conda env create new-env python=3.6
conda env list
conda activate new-env
conda deactivate
Run Code Online (Sandbox Code Playgroud)
的默认环境位置pyenv是~/.pyenv/versions。
的默认环境位置conda,检查conda info.
| 归档时间: |
|
| 查看次数: |
11329 次 |
| 最近记录: |