gpt4 book ai didi

python-2.7 - 如何在python虚拟环境中导入scikit-learn?

转载 作者:行者123 更新时间:2023-12-02 17:30:40 29 4
gpt4 key购买 nike

问题

我正在尝试在虚拟环境中使用 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 应用程序的一些故障排除。

最佳答案

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

如果您想使用不同版本的 Python 包(包括已编译的扩展)管理多个环境,最好的工具可能是 conda ,特别是 conda environments .

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

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

然后你就可以开始了。

关于python-2.7 - 如何在python虚拟环境中导入scikit-learn?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33792543/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com