2

I am working with ubuntu 14. I have downloaded the dpkg package for sklearn and unpacked it. i try to run sudo python setup.py installBut it seems to be stuck in a loop

    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)
 ^

.. and continues on like that.

I have installed numpy, but I did it through ubuntu's software center. When I try to import sklearn within python I get

from sklearn.ensemble import RandomForestClassifier Traceback (most recent call last): File "", line 1, in File "sklearn/init.py", line 37, in from . import check_build File "sklearn/__check_build/__init.py", line 46, in raise_build_error(e) File "sklearn/check_build/__init.py", line 41, in raise_build_error %s""" % (e, local_dir, ''.join(dir_content).strip(), msg)) ImportError: No module named _check_build _______________________________________________________________________ Contents of sklearn/check_build: setup.py
__init
.py _check_build.pyx _check_build.c setup.pyc init.pyc _______________________________________________________________________ It seems that scikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget to build the package before using it: run python setup.py install or make in the source directory.

If you have used an installer, please check that it is suited for your Python version, your operating system and your platform.

I have no idea where sklearn/check_build is located.

My folder in /usr/lib/python2.7/dist-packages is empty, but I can import numpy within python. Like I said, I used the ubuntu software center to install numpy, but not for sklearn which I regret doing now.

Jake Fund
  • 395
  • 2
  • 6
  • 16
  • 1
    First, one should never (very rarely) do `sudo pip` as you may ruin your operating system and Python package installations this way. Instead, one should use `virtualenv` to locally install packages under non-root user: http://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/ – Mikko Ohtamaa Aug 10 '14 at 08:32
  • Can you get the end of the compilation output? What you pasted there are warnings and there is actual error there. – Mikko Ohtamaa Aug 10 '14 at 08:34
  • Also might be one of these errors: http://stackoverflow.com/questions/15274696/importerror-in-importing-from-sklearn-cannot-import-name-check-build – Mikko Ohtamaa Aug 10 '14 at 08:36
  • No, it seems that it just goes on in a loop, but I'll try it again. – Jake Fund Aug 10 '14 at 08:36
  • I think it just spits out a lot of warning, so the output might be long. – Mikko Ohtamaa Aug 10 '14 at 08:36
  • 1
    Here's the output Assembler messages: Fatal error: can't create build/temp.linux-x86_64-2.7/sklearn/utils/fast_dict.o: Permission denied error: Command "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" failed with exit status 1 – Jake Fund Aug 10 '14 at 08:42
  • that would because i didnt use sudo. should I just use virtualenv instead? – Jake Fund Aug 10 '14 at 08:43
  • you cannot install to the system python without using sudo – Padraic Cunningham Aug 10 '14 at 08:44
  • Yes, it is trying to create files under root user. I suggest you might want to take clean start with virtualenv's `--no-site-packages` option. – Mikko Ohtamaa Aug 10 '14 at 08:46
  • .... or just go down with `apt-get` route. – Mikko Ohtamaa Aug 10 '14 at 08:47
  • why did you not use pip to install scikit-learn? – Padraic Cunningham Aug 10 '14 at 08:52
  • I did. It went into the same loop. But it wasn't a loop at all. It does eventually finish, but python still can not import sklearn. – Jake Fund Aug 10 '14 at 08:54
  • what versions of `numpy` and `scipy` have you installed? – Padraic Cunningham Aug 10 '14 at 08:57
  • not sure how to check, but probably the newest ones since I installed them through ubuntu's software center. – Jake Fund Aug 10 '14 at 08:59
  • Oh dear, I ran whereis python. It appears I have many versions of python installed – Jake Fund Aug 10 '14 at 09:01
  • /usr/bin/python3.4m /usr/bin/python2.7-config /usr/bin/python2.7-dbg /usr/bin/python2.7 /usr/bin/python3.4 /usr/bin/python2.7-dbg-config /usr/bin/python /etc/python2.7 /etc/python3.4 /etc/python /usr/lib/python2.7 /usr/lib/python3.4 /usr/bin/X11/python3.4m /usr/bin/X11/python2.7-config /usr/bin/X11/python2.7-dbg /usr/bin/X11/python2.7 /usr/bin/X11/python3.4 /usr/bin/X11/python2.7-dbg-config /usr/bin/X11/python /usr/local/lib/python2.7 /usr/local/lib/python3.4 /usr/include/python2.7_d /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz – Jake Fund Aug 10 '14 at 09:02
  • you should run `which -a python` to find your installs. you only actually have two installs – Padraic Cunningham Aug 10 '14 at 09:06
  • okay python is located at /usr/bin/python.But I got my sklearn to import after I logout and logged back in. But the library files are located in /usr/local/lib/python2.7/dist-packages/sklearn – Jake Fund Aug 10 '14 at 09:15
  • that is because of how you installed it – Padraic Cunningham Aug 10 '14 at 09:24
  • 2
    Okay thanks guys. I see I have newbified my python in ubuntu, but everything runs now. When I get time, I'll try uninstalling everything and reinstalling everything through virtualenv thank you for your help. – Jake Fund Aug 10 '14 at 09:30
  • @user3335911 no worries, I would leave your install as is., if it's not broke don't fix it ;) – Padraic Cunningham Aug 10 '14 at 09:32
  • A suggestion to drain the swamp rather than kill all the mosquitoes - pick a python distribution such as Anaconda or Enthought or whatever you like and just install that. The software center never seems to have the most recent version. – James King Aug 11 '14 at 00:35

3 Answers3

0

I recommend installing sklearn and all dependencies with Anaconda package: https://www.continuum.io/downloads#_unix

It will be installed together with numpy and other packages, full list is available here: http://docs.continuum.io/anaconda/pkg-docs

Asia
  • 21
  • 3
0

If you want your package manager to handle everything, that usually works although you won't necessarily be on the most recent version

Otherwise do something along the lines of

sudo apt-get install build-essential gcc g++ python-dev python3-dev python-scipy python3-scipy

and try to install/compile again. compiling python extension modules relies on having a working compilation environment, plus the extended or development headers for python. I'm not sure if those dependencies are 100% exactly right for Ubuntu b/c I've been using more openSUSE lately, but apt-cache search will turn you up the correct naming if I've made a typo

Nathan Smith
  • 475
  • 4
  • 12
0

One of new ways to handle issues due to environment is to handle it using docker images. This allows any developer to recreate the environment in any server within a single minute. You can pull the image from here.

This can also be performed very easily using the datmo CLI tool. We faced these problems ourselves and decided to build it.

Edit: You could install as follows,

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

Disclaimer: I work at Datmo

Shabaz Patel
  • 281
  • 1
  • 10
  • It's not particularly clear how this answers OP's question. I'm sure a docker image could conceivably solve this problem, but as it stands all you've done is link to a place where some docker images exist. Why would docker fix the problem? How could I set an image up? What actually caused this problem in the first place? – ymbirtt Apr 30 '17 at 08:49
  • @ymbirtt I have also added the segment of code from Dockerfile which let's one install sklearn. Hope that helps! – Shabaz Patel May 03 '17 at 04:49