【问题标题】:Unable to pip install packages in Anaconda无法在 Anaconda 中 pip 安装包
【发布时间】:2014-10-17 12:32:22
【问题描述】:

刚刚在 Mac OSX Mavericks 上下载并安装了 anaconda 3.6.2,我需要安装一个未预安装 anaconda 的包 seaborn

$ conda install seaborn
Fetching package metadata: ..
Error: No packages found in current osx-64 channels matching: seaborn

You can search for this package on Binstar with

    binstar search -t conda seaborn

You may need to install the Binstar command line client with

    conda install binstar

接下来我尝试使用pip来安装包

$ which pip
/Users/username/anaconda/bin/pip

$ pip install seaborn
Could not find an activated virtualenv (required).

尝试再次激活root Anaconda env,但仍然无法正常工作

$ source activate root
discarding /Users/username/anaconda/bin from PATH
prepending /Users/username/anaconda/bin to PATH

$ pip install seaborn
Could not find an activated virtualenv (required).

接下来我尝试激活一个virualenv,pip install 工作正常。

workon testEnv
pip install seaborn

现在我从 Anaconda 的启动器启动了iPython notebook。但是seaborn这个包好像没有找到!

seaborn 包真的安装了吗?

~/bashprofile,我有:

# virutalenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /Users/username/.virtualenvs/datasci/bin/virtualenvwrapper.sh

# added by Anaconda 2.0.1 installer
export PATH="/Users/username/anaconda/bin:$PATH"

更新

删除了 2 个 virtualenvwrapper 行,重新加载了 .bash_profile,但 pip install 仍然给出错误 Could not find an activated virtualenv (required). 激活另一个 conda 环境 source activate testenv 没有帮助。

$ source activate ~/.bash_profile
$ pip install seaborn
Could not find an activated virtualenv (required).

$ source activate testenv
discarding /Users/username/anaconda/bin from PATH
prepending /Users/username/anaconda/envs/testenv/bin to PATH
$ pip install seaborn
Could not find an activated virtualenv (required).

【问题讨论】:

  • 这个问题你解决了吗?

标签: python macos pip anaconda


【解决方案1】:

您需要安装 anaconda 版本的 pip。运行:

conda install pip

这将在激活的 conda 环境中安装 pip

【讨论】:

  • 在“conda install pip”之后,我发现我需要先停用然后重新激活,才能让 pip 在我所在的 conda 环境中工作。症状是即使 'which pip'在anaconda下显示了正确的可执行文件,它引用了/usr/local/lib/python2.7/site-packages。停用/激活更正了这一点。
  • 您可以做的另一件事是在创建 conda 环境时安装 pip。只需将 pip 附加到 conda create 命令的末尾
【解决方案2】:

我在使用 Mac 安装 ggplot 时遇到了同样的问题。 如果您从终端执行:

/anaconda/bin/pip install module_name

它有效。 希望能帮到你!

MC

【讨论】:

  • 我和发帖人有类似的问题。但是我在 //anaconda/bin/pip 中没有 pip 可执行文件。我只有一个 conda-pipbuild 可执行文件。但是,如果我执行 conda install pip 它会显示所有请求的软件包已安装。 # 环境中的包 //anaconda:
  • 我刚刚做了~/Anaconda/envs/env_name/bin/pip install module_name
【解决方案3】:

从您的 bashprofile 中删除 virtualenvwrapper 行。使用 Anaconda,您应该使用 conda 环境而不是 virtualenvs,并且使用 virtualenvs 最终会破坏您的 conda 环境。

【讨论】:

  • 删除了 2 个 virtualenvwrapper 行,使用 source ~/.bash_profile 重新加载了 .bash_profile。 pip install 仍然给出错误 Could not find an activated virtualenv (required). 激活另一个 conda 环境 source activate testenv 没有帮助
  • 严格来说,获取您的 bash 配置文件并不会重新加载它,它只是再次运行它。但是仍然会设置从 virtualenv 脚本设置的环境变量。您应该开始一个新的终端会话。
  • 我退出了终端程序并再次启动它。执行pip install 时仍然收到错误Could not find an activated virtualenv (required).
【解决方案4】:

也许只是把它放在你的 bash_profile 中:

export PIP_REQUIRE_VIRTUALENV=false

那是我的问题,我忘了我是这样设置 PIP 的。

【讨论】:

    【解决方案5】:

    尝试在 Anaconda Prompt 中输入命令,而不是在命令提示符中输入。

    【讨论】:

    • 这无关紧要,因为 OP 在 $PATH 上已经有 anaconda:export PATH="/Users/username/anaconda/bin:$PATH"
    猜你喜欢
    • 2020-05-10
    • 2019-05-24
    • 2020-08-23
    • 2016-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-28
    • 2023-04-09
    相关资源
    最近更新 更多