我正在使用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时,我得到
从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(( 导入错误: 没有名为 _check_build 的模块 ____sklearn/check_build的内容:setup.py
__init.py _check_build.pyx _check_build.c setup.pyc init.pyc ____似乎scikit-learn没有正确构建。如果您已经安装了scikit-learnfrom source,请不要忘记 若要在使用包之前生成包:运行
python setup.py install
或make
源目录中。如果您使用过安装程序,请检查它是否适合您的 Python版本,您的操作系统和平台。
我不知道sklearn/check_build在哪里。
我在/usr/lib/python2.7/dist-packages 中的文件夹是空的,但我可以在 python 中导入 numpy。就像我说的,我使用 ubuntu 软件中心来安装 numpy,但不是为了 sklearn,我现在后悔这样做了。
我建议使用 Anaconda 包安装 sklearn 和所有依赖项: https://www.continuum.io/downloads#_unix
它将与 numpy 和其他软件包一起安装,完整列表可在此处获得:http://docs.continuum.io/anaconda/pkg-docs
如果您希望包管理器处理所有内容,这通常有效,尽管您不一定使用最新版本
否则,请执行类似操作的操作:
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 搜索会为你找到正确的命名
处理环境问题的新方法之一是使用 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
免责声明:我在达特莫工作