2

问题

我正在尝试在虚拟环境中使用 scikit-learn,但我无法让它运行。

因此,例如,我转到一个项目文件夹并安装 NumPy、SciPy 和 scikit-learn

virtualenv venv source venv/bin/activate pip install numpy pip install scipy pip install scikit-learn

然后我打开 python 并尝试导入它们中的每一个。

import numpy import scipy import sklearn

NumPy 和 SciPy 导入正常,但是当我尝试导入时,我收到一条错误消息Library not loaded: @rpath/./libgfortran.3.dylib

我在安装中缺少什么吗?

完整的错误信息: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/__init__.py", line 57, in <module> from .base import clone File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/base.py", line 11, in <module> from .utils.fixes import signature File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/__init__.py", line 11, in <module> from .validation import (as_float_array, File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/validation.py", line 16, in <module> from ..utils.fixes import signature File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/sklearn/utils/fixes.py", line 324, in <module> from scipy.sparse.linalg import lsqr as sparse_lsqr File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/__init__.py", line 109, in <module> from .isolve import * File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/__init__.py", line 6, in <module> from .iterative import * File "/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/iterative.py", line 7, in <module> from . import _iterative ImportError: dlopen(/Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Library not loaded: @rpath/./libgfortran.3.dylib Referenced from: /Users/Peter/git/dataSandbox/flaskApps/sfSalary/venv/lib/python2.7/site-packages/scipy/sparse/linalg/isolve/_iterative.so Reason: image not found

编辑:这是使用 sklearn 托管 Heroku 应用程序的一些故障排除。

4

1 回答 1

5

我强烈建议不要对 NumPy/SciPy/Scikit-learn 和其他包含编译代码的包使用虚拟环境。虚拟环境可以很好地处理纯 Python 依赖项,但是对于具有 Python 外部依赖项的编译扩展,它们可能会以意想不到的方式失败(如您所见)。

如果您想使用不同版本的 Python 包(包括已编译的扩展)来管理多个环境,那么最好的工具可能是conda,尤其是conda environment

有了它,您可以运行以下命令:

$ conda create -n myenv python=3.4 numpy scipy scikit-learn
$ source activate myenv
(myenv) $ python
Python 3.4.3
>>> import sklearn

你会很高兴的。

于 2015-11-19T20:29:30.063 回答