Pythonパッケージのビルドは成功しましたが、パッケージが誤ってビルドされました。

Pythonパッケージのビルドは成功しましたが、パッケージが誤ってビルドされました。

実行すると、python3 setup.py build次のように終了します。

x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/sklearn/linear_model/sag_fast.o -Lbuild/temp.linux-x86_64-3.4 -o build/lib.linux-x86_64-3.4/sklearn/linear_model/sag_fast.cpython-34m.so
running install_lib
creating /usr/local/lib/python3.4/dist-packages/sklearn
error: could not create '/usr/local/lib/python3.4/dist-packages/sklearn': Permission denied

/usr/local/lib/もちろん使用しないので書くことはできませんsudo。このステップでは、sudoの使用に注意する必要があります。

これが最後ですsudo python3 setup.py install

running install_egg_info
Writing /usr/local/lib/python3.4/dist-packages/scikit_learn-0.18.dev0.egg-info
running install_clib

私に見て良いです。ただし、試してみると、import sklearn次のエラーが発生します。

$ python3
Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
Traceback (most recent call last):
File "/home/dotancohen/code/scikit-learn/sklearn/__check_build/__init__.py", line 44, in <module>
    from ._check_build import check_build
ImportError: No module named 'sklearn.__check_build._check_build'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dotancohen/code/scikit-learn/sklearn/__init__.py", line 56, in <module>
    from . import __check_build
File "/home/dotancohen/code/scikit-learn/sklearn/__check_build/__init__.py", line 46, in <module>
    raise_build_error(e)
File "/home/dotancohen/code/scikit-learn/sklearn/__check_build/__init__.py", line 41, in raise_build_error
    %s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: No module named 'sklearn.__check_build._check_build'
___________________________________________________________________________
Contents of /home/dotancohen/code/scikit-learn/sklearn/__check_build:
_check_build.c            setup.pyc                 __pycache__
_check_build.pyx          __init__.py               setup.py
___________________________________________________________________________
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.
>>>

python3 setup.py buildで走らなければなりませんかsudoこれは Kubuntu Linux 15.10 にあります。

$ uname -a
Linux loathe 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/issue
Ubuntu 15.10 \n \l

Ubuntuパッケージのバージョンはpython-scikits-learnPython 2でのみ動作するため、Python 3が必要です。

ベストアンサー1

私が見つけたこの投稿使用する線形代数パッケージ(ATLAS)バージョンを設定する方法は次のとおりです。

$ sudo update-alternatives --set libblas.so.3 /usr/lib/atlas-base/atlas/libblas.so.3
$ sudo update-alternatives --set liblapack.so.3 /usr/lib/atlas-base/atlas/liblapack.so.3

その後、実際には権限の問題がなくなったことに驚きましたが、ビルド時に次のエラーが発生しました。

sklearn/__check_build/_check_build.c:4:20: fatal error: Python.h: No such file or directory

それで、結果を見て、次のパッケージが役に立つaptitude search python | grep devと判断しました。

$ sudo aptitude install python3-numpy-dev python3.5-dev libpython3.4-dev

これによりパッケージが正しく構築され、scikit-learnが正しくインポートされます。

$ python3
Python 3.4.3+ (default, Oct 14 2015, 16:03:50) 
[GCC 5.2.1 20151010] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sklearn
>>>

これら3つのパッケージのどれが重要なパッケージかはわかりませんが、libpython3.4-dev問題は解決しました。

おすすめ記事