Python没有安装sklearn
Posted
技术标签:
【中文标题】Python没有安装sklearn【英文标题】:Python not installing sklearn 【发布时间】:2014-10-03 07:30:55 【问题描述】:我正在使用 ubuntu 14。我已经下载了 sklearn 的 dpkg 包并将其解压缩。我尝试运行sudo python setup.py install
但它似乎陷入了循环
compiling C++ sources
C compiler: c++ -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC
creating build/temp.linux-x86_64-2.7/sklearn/utils/src
compile options: '-Isklearn/utils/src -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
c++: sklearn/utils/src/MurmurHash3.cpp
c++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/sklearn/utils/murmurhash.o build/temp.linux-x86_64-2.7/sklearn/utils/src/MurmurHash3.o -Lbuild/temp.linux-x86_64-2.7 -o build/lib.linux-x86_64-2.7/sklearn/utils/murmurhash.so
building 'sklearn.utils.lgamma' extension
compiling C sources
C compiler: x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC
compile options: '-Isklearn/utils/src -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
x86_64-linux-gnu-gcc: sklearn/utils/lgamma.c
x86_64-linux-gnu-gcc: sklearn/utils/src/gamma.c
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/sklearn/utils/lgamma.o build/temp.linux-x86_64-2.7/sklearn/utils/src/gamma.o -Lbuild/temp.linux-x86_64-2.7 -lm -o build/lib.linux-x86_64-2.7/sklearn/utils/lgamma.so
building 'sklearn.utils.graph_shortest_path' extension
compiling C sources
C compiler: x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC
compile options: '-I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
x86_64-linux-gnu-gcc: sklearn/utils/graph_shortest_path.c
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1761:0,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from sklearn/utils/graph_shortest_path.c:256:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it by " \
^
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ufuncobject.h:327:0,
from sklearn/utils/graph_shortest_path.c:257:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__ufunc_api.h:241:1: warning: ‘_import_umath’ defined but not used [-Wunused-function]
_import_umath(void)
^
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/sklearn/utils/graph_shortest_path.o -Lbuild/temp.linux-x86_64-2.7 -o build/lib.linux-x86_64-2.7/sklearn/utils/graph_shortest_path.so
building 'sklearn.utils.fast_dict' extension
compiling C++ sources
C compiler: c++ -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC
compile options: '-I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c'
c++: sklearn/utils/fast_dict.cpp
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1761:0,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:17,
from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from sklearn/utils/fast_dict.cpp:320:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it by " \
^
sklearn/utils/fast_dict.cpp: In function ‘PyObject* __pyx_pw_7sklearn_5utils_9fast_dict_1argmin(PyObject*, PyObject*)’:
sklearn/utils/fast_dict.cpp:18786:44: warning: ‘__pyx_v_min_key’ may be used uninitialized in this function [-Wmaybe-uninitialized]
return PyInt_FromLong((long)val);
^
sklearn/utils/fast_dict.cpp:3316:46: note: ‘__pyx_v_min_key’ was declared here
__pyx_t_7sklearn_5utils_9fast_dict_ITYPE_t __pyx_v_min_key;
^
In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ufuncobject.h:327:0,
from sklearn/utils/fast_dict.cpp:321:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__ufunc_api.h: At global scope:
/usr/lib/python2.7/dist-packages/numpy/core/include/numpy/__ufunc_api.h:241:1: warning: ‘int _import_umath()’ defined but not used [-Wunused-function]
_import_umath(void)
^
.. 并继续这样。
我已经安装了numpy,但是我是通过ubuntu的软件中心安装的。当我尝试在 python 中导入 sklearn 时,我得到了
from sklearn.ensemble import RandomForestClassifier Traceback(大多数 最近通话最后一次):文件“”,第 1 行,在文件中 “sklearn/init.py”,第 37 行,在 从 。导入 check_build 文件“sklearn/__check_build/__init.py”,第 46 行,在 raise_build_error(e) 文件“sklearn/check_build/__init.py”,第 41 行,在 raise_build_error %s""" % (e, local_dir, ''.join(dir_content).strip(), msg)) ImportError: No module named _check_build _____________________________________________________________ sklearn/check_build 的内容:setup.py __init.py _check_build.pyx _check_build.c setup.pyc init.pyc _____________________________________________________________ scikit-learn 似乎没有正确构建。
如果你已经从源代码安装了 scikit-learn,请不要忘记 在使用之前构建包:运行
python setup.py install
或make
在源目录中。如果您使用过安装程序,请检查它是否适合您的 Python 版本、您的操作系统和您的平台。
我不知道 sklearn/check_build 的位置。
我在 /usr/lib/python2.7/dist-packages 中的文件夹是空的,但我可以在 python 中导入 numpy。就像我说的,我使用 ubuntu 软件中心安装了 numpy,但没有安装我现在后悔的 sklearn。
【问题讨论】:
首先,永远不应该(很少)这样做sudo pip
,因为这样可能会破坏您的操作系统和 Python 包安装。相反,应该使用virtualenv
在非root 用户下本地安装包:opensourcehacker.com/2012/09/16/…
你能得到编译输出的结尾吗?您粘贴的内容是警告,并且那里存在实际错误。
很高兴知道,谢谢。
这是输出汇编程序消息:致命错误:无法创建 build/temp.linux-x86_64-2.7/sklearn/utils/fast_dict.o:权限被拒绝错误:命令“c++ -pthread -fno -strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -fPIC -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/lib/python2.7/dist-packages /numpy/core/include -I/usr/include/python2.7 -c sklearn/utils/fast_dict.cpp -o build/temp.linux-x86_64-2.7/sklearn/utils/fast_dict.o" 退出状态为 1
好的,谢谢大家。我看到我已经在 ubuntu 中更新了我的 python,但是现在一切都运行了。当我有时间时,我会尝试通过 virtualenv 卸载所有内容并重新安装所有内容,谢谢您的帮助。
【参考方案1】:
我建议使用 Anaconda 包安装 sklearn 和所有依赖项:https://www.continuum.io/downloads#_unix
它将与 numpy 和其他软件包一起安装,完整列表在这里:http://docs.continuum.io/anaconda/pkg-docs
【讨论】:
【参考方案2】:如果你想让你的包管理器处理所有事情,这通常是可行的,尽管你不一定使用最新版本
否则做一些类似的事情
sudo apt-get install build-essential gcc g++ python-dev python3-dev python-scipy python3-scipy
并尝试再次安装/编译。编译 python 扩展模块依赖于有一个工作编译环境,以及 python 的扩展或开发头文件。我不确定这些依赖项是否 100% 完全适合 Ubuntu b/c 我最近一直在使用更多的 openSUSE,但是如果我打错了,apt-cache search 会为您提供正确的命名
【讨论】:
【参考方案3】:处理环境问题的一种新方法是使用 docker 映像来处理它。这允许任何开发人员在一分钟内在任何服务器中重新创建环境。您可以从here 拉取图像。
这也可以使用 datmo CLI 工具非常轻松地执行。我们自己也遇到了这些问题,并决定建造它。
编辑:您可以按如下方式安装,
apt-get update; \
apt-get install -y python python-pip \
python-numpy \
python-scipy \
build-essential \
python-dev \
python-setuptools \
libatlas-dev \
libatlas3gf-base
update-alternatives --set libblas.so.3 /usr/lib/atlas-base/atlas/libblas.so.3; update-alternatives --set liblapack.so.3 /usr/lib/atlas-base/atlas/liblapack.so.3
pip install -U scikit-learn
免责声明:我在Datmo工作
【讨论】:
目前还不清楚这如何回答 OP 的问题。我确信 docker 镜像可以解决这个问题,但就目前而言,你所做的只是链接到存在一些 docker 镜像的地方。为什么 docker 会解决这个问题?我该如何设置图像?究竟是什么导致了这个问题? @ymbirtt 我还添加了来自 Dockerfile 的代码段,让我们安装 sklearn。希望有帮助!以上是关于Python没有安装sklearn的主要内容,如果未能解决你的问题,请参考以下文章