Python无法安装sklearn
我在使用 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 追踪(最近的调用最后): 文件 "", 第 1 行, 在 文件 "sklearn/init.py", 第 37 行, 在 from . import 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)) 导入错误:没有名为 _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 不是,我现在很后悔这样做。
3 个回答
处理环境问题的新方法之一是使用 Docker 镜像。这样,任何开发者都可以在一分钟内在任何服务器上重建相同的环境。你可以从 这里 下载这个镜像。
使用 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 工作
如果你希望你的包管理工具能处理所有事情,这通常是可行的,不过你可能不会使用到最新版本。
否则,可以尝试以下步骤:
sudo apt-get install build-essential gcc g++ python-dev python3-dev python-scipy python3-scipy
然后再试着安装或编译一次。编译Python扩展模块需要有一个正常工作的编译环境,以及Python的扩展或开发头文件。我不太确定这些依赖项在Ubuntu上是否完全正确,因为我最近主要在使用openSUSE,但你可以通过apt-cache search来找到正确的名称,如果我有打错的话。
我建议你通过Anaconda这个工具来安装sklearn和它需要的所有依赖包。你可以在这里找到下载链接:https://www.continuum.io/downloads#_unix
这样安装的时候,numpy和其他一些包也会一起安装,具体的包列表可以在这里查看:http://docs.continuum.io/anaconda/pkg-docs