【问题标题】:Wrongly installed module in pythonpython中错误安装的模块
【发布时间】:2015-03-12 23:06:30
【问题描述】:

我尝试在 ubuntu 上的 python 中安装 sci-kit learn 模块。正如他们的教程中所解释的,我做到了:

pip install --user --install-option="--prefix=" -U scikit-learn

但是当我在 python 控制台中尝试时

import sklearn

我明白了:

ImportError: No module named sklearn

如果我这样做了

pip list

sklearn 没有出现在列表中。

如果我尝试:

sudo pip install scikit-learn

我明白了:

Requirement already satisfied (use --upgrade to upgrade): scikit-learn in ./.local/lib/python2.7/site-packages

【问题讨论】:

  • 你有没有机会使用 virtualenv?

标签: python python-2.7 pip scikit-learn


【解决方案1】:

这可能是由于文件夹~/.local/lib 没有出现在您的sys.path 中。您可以通过多种方式更新sys.path。在运行控制台之前设置PYTHONPATH 环境变量,或者只是附加到sys.path 数组。

您可以卸载模块,然后以 root 身份重新安装:

pip uninstall scikit-learn ; sudo pip install scikit-learn

您也可以只删除~/.local/lib 文件夹并重新安装软件包。

【讨论】:

  • 卸载是个好建议,但我得到:无法卸载要求 scikit-learn,未安装 在 /home/ubuntu/.pip/pip.log 中存储失败的调试日志
  • 也许你应该删除 ~/.local/lib 文件夹。这应该相当于卸载包。您可能希望将 virtualenvwrapper 视为将来处理这些依赖项的一种方式:virtualenvwrapper.readthedocs.org/en/latest
  • 当我想删除 scikit-learn 包时,我正在处理这个错误:Cannot uninstall 'scikit-learn'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
【解决方案2】:

我遇到了同样的问题,但是当我使用 sudo pip uninstall scikit-learnsudo pip install -U scikit-learn 时,我正在处理以下错误:

Cannot uninstall 'scikit-learn'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

以下行解决了我的问题:

sudo pip install --ignore-installed scikit-learn==0.18

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-12
    • 2022-01-11
    • 1970-01-01
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    相关资源
    最近更新 更多