【发布时间】:2019-01-19 03:46:12
【问题描述】:
我刚刚使用这里的教程重建了我的 mac 环境:
https://hackercodex.com/guide/mac-development-configuration/ & 这里:https://hackercodex.com/guide/python-development-environment-on-mac-osx/
我想为 pip 需要一个 virtualenv,并通过打开来设置它:
vim ~/Library/Application\ Support/pip/pip.conf
并添加:
[install]
require-virtualenv = true
[uninstall]
require-virtualenv = true
然后,我按照指南设置带有 tensorflow 的 jupyter 笔记本,因为我正在尝试学习机器学习的 udemy 课程,该课程需要两者:https://medium.com/@margaretmz/anaconda-jupyter-notebook-tensorflow-and-keras-b91f381405f8
在本教程中,它提到您应该为 tensorflow 使用 pip install 而不是 conda install,因为 conda 包不受官方支持。
我可以通过运行在 conda 上安装 pip:
conda install pip
但是当我尝试运行时:
pip3 install tensorflow
我得到错误:
“找不到激活的 virtualenv(必需)。”
我知道为什么会出现此错误,只是不知道如何将代码更改为也接受在 anaconda venvs 中使用 pip 和 pip3。
我的 anaconda3 文件夹与我的所有其他虚拟环境一起位于我的 Virtualenvs 文件夹中。
我尝试通过在 ~/.bashrc 中定义一个新函数来暂时关闭限制:
cpip(){
PIP_REQUIRE_VIRTUALENV="0" pip3 "$@"
}
并使用它来代替,没有运气,不足为奇。
我认为问题可能出在我的 bash_profile 中:
# How to Set Up Mac For Dev:
# https://hackercodex.com/guide/mac-development-configuration/
# Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH
# Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc
# Activate Bash Completion:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
source $(brew --prefix)/etc/bash_completion
fi
# Toggle for installing global packages:
gpip(){
PIP_REQUIRE_VIRTUALENV="0" pip3 "$@"
}
# Toggle for installing conda packages:
cpip(){
PIP_REQUIRE_VIRTUALENV="0" pip3 "$@"
}
# Be sure to run "source ~/.bash_profile after toggle for changes to
take effect.
# Run "gpip install" (i.e. "gpip install --upgrade pip setuptools
wheel virtualenv")
# added by Anaconda3 2018.12 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false
'/Users/erikhayton/Virtualenvs/anaconda3/bin/conda' shell.bash hook
2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f
"/Users/erikhayton/Virtualenvs/anaconda3/etc/profile.d/conda.sh" ];
then
.
"/Users/erikhayton/Virtualenvs/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export
PATH="/Users/erikhayton/Virtualenvs/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
我希望能够在 anaconda3 的激活 'env's 中(& 仅在)中使用 pip (& pip3, pip2) 和 virtualenvs。
【问题讨论】:
标签: python python-3.x anaconda virtualenv conda