【问题标题】:Where does `pip` install libraries compared to where `python` from terminal runs?与终端中的 `python` 运行位置相比,`pip` 安装库的位置在哪里?
【发布时间】:2017-01-11 20:40:46
【问题描述】:

我正在尝试安装 python's scikit learn 以进行某些机器学习,并且它似乎成功地完成了(即它已经安装)。但是,当我尝试在终端的python 中实际使用它时,它给了我一个错误,如下所示。

23:39 $ sudo pip install sklearn
The directory '/Users/username/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/username/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting sklearn
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in /Library/Python/2.7/site-packages (from sklearn)
Installing collected packages: sklearn
Successfully installed sklearn-0.0
✔ /usr/bin 
23:42 $ python
Python 2.7.12rc1 (v2.7.12rc1:13912cd1e7e8, Jun 11 2016, 15:32:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/sklearn/__init__.py", line 57, in <module>
    from .base import clone
  File "/Library/Python/2.7/site-packages/sklearn/base.py", line 11, in <module>
    from .utils.fixes import signature
  File "/Library/Python/2.7/site-packages/sklearn/utils/__init__.py", line 11, in <module>
    from .validation import (as_float_array,
  File "/Library/Python/2.7/site-packages/sklearn/utils/validation.py", line 16, in <module>
    from ..utils.fixes import signature
  File "/Library/Python/2.7/site-packages/sklearn/utils/fixes.py", line 324, in <module>
    from scipy.sparse.linalg import lsqr as sparse_lsqr
  File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/__init__.py", line 112, in <module>
    from .isolve import *
  File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module>
    from .iterative import *
  File "/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module>
    from . import _iterative
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Symbol not found: ___addtf3
  Referenced from: /usr/local/opt/gcc/lib/gcc/6/libquadmath.0.dylib
  Expected in: /usr/lib/libSystem.B.dylib
 in /usr/local/opt/gcc/lib/gcc/6/libquadmath.0.dylib
>>> exit()
✔ /usr/bin 
23:43 $ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

我认为pip install &lt;package name&gt; 安装软件包的位置与我在终端中调用python 时实际访问它们的位置之间肯定存在一些差异。

有什么区别:

1) 通过pip install &lt;package name&gt; 安装软件包的位置?

2) 从终端调用python 时在哪里搜索包?

我将which python 的结果放在底部,因为我认为这可能有用。 另外,伙计们,我正在使用 Mac OS El Capitan 10.11.4 版。

【问题讨论】:

  • 似乎缺少依赖项,可能是 BLAS。尝试从您的发行版的包管理器安装 scikit,pip 无论如何都是discouraged
  • @TobiaTesan 不鼓励在 Linux 上使用。看来这个问题正在使用 OSX
  • 您不应将 sudo 与 pip 一起使用,但您的问题的答案存在于这些日志中。软件包安装到 python 安装的 site-packages 目录。不过,您需要确定为什么有 /Library/Python/2.7/site-packages/usr/local/lib/python2.7/site-packages 相比
  • @cricket_007:啊,我瞎了,对不起。

标签: python python-2.7 terminal scikit-learn


【解决方案1】:

这个问题与python包路径无关。这是由于未解析的符号___addtf3gfortran 库提供的GCC 软件浮点例程。通过正确设置DYLD_LIBRARY_PATH 环境变量解决了similar issue with a different application(与python 完全无关)。当然,您必须在系统上安装这些库,这可能是您的实际问题。

【讨论】:

  • @Candic3 可能是因为sklearn 是您身边第一个需要scipy 的包(这又取决于那些浮点例程)。
  • 谢谢@Leon。好像我安装了gcc 库,因为我看到这里安装了libquadmath.0.dylib 之类的文件:/usr/local/opt/gcc/lib/gcc/6/libquadmath.0.dylib。而且,我尝试设置DYLD_LIBRARY_PATH 变量,但它似乎不起作用:export DYLD_LIBRARY_PATH="/usr/local/opt/gcc/lib/gcc/6"。您还有什么可以建议的吗?
  • @Candic3 libquadmath 使用___addtf3 例程,而不是定义它。请发布以下命令的输出:find /usr -name '*.dylib' -exec nm -D {} \; 2&gt; /dev/null|grep ___addtf3
猜你喜欢
  • 2020-11-15
  • 2020-11-20
  • 2018-08-20
  • 1970-01-01
  • 2014-07-20
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多