[求助]pip安装spglib失败

各位坛友你们好,最近本人需要学用软件 pymatgen ,官方推荐通过 pip 安装,我换了 openSUSE42.1 和 13.2 都没有安装成功。自己看 pip 的安装日志发现问题出在 pip 安装 spglib 失败,但是不知道如何解决。这是最近一次用 13.2 内置的 pip3 安装 pymatgen(截取 spglib 失败那一段),以及 pip3 单独安装 spglib 失败的日志,都是到 sgplib 根目录缺少一个“_spglib.c”文件这里停止,但是我不知道如何解决,希望大家能帮忙解决。

P.S.1: Ubuntu 试了几个版本都能安装成功,可是太卡了不想用。
P.S.2: 提前需要装的东西比较少,pip3 是自带的,然后用装的有 python3-numpy, python3-scipy, gcc 别的木有了。欢迎大家帮我测试安装,13.2 和 42.1 的出错也是一样的。

pip3 安装 pymatgen 3.3.4 失败的日志(节选 spglib 安装的那一段)

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/cell.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/spglib_f.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/refinement.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/niggli.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/symmetry.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/site_symmetry.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/pointgroup.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/spglib.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/src/primitive.c

gcc: /tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/_spglib.c

/tmp/pip_build_specter119/pymatgen/dependencies/spglib-1.7.4/_spglib.c:1:20: fatal error: Python.h: 没有那个文件或目录

 #include <Python.h>

**pip3 安装 spglib 1.9.0.5 失败的日志 **

------------------------------------------------------------
/usr/bin/pip3 run on Fri Feb 19 00:58:19 2016
Downloading/unpacking spglib
  Getting page https://pypi.python.org/simple/spglib/
  URLs to search for versions for spglib:
  * https://pypi.python.org/simple/spglib/
  Analyzing links from page https://pypi.python.org/simple/spglib/
    Found link https://pypi.python.org/packages/source/s/spglib/spglib-1.6.0.1.tar.gz#md5=bb06dfd84cd0b9aa73a37bbdb1cfbf01 (from https://pypi.python.org/simple/spglib/), version: 1.6.0.1
    Found link https://pypi.python.org/packages/source/s/spglib/spglib-1.6.0.2.tar.gz#md5=4ab2cdddaea67c2bee8f8b274120ff95 (from https://pypi.python.org/simple/spglib/), version: 1.6.0.2
    Found link https://pypi.python.org/packages/source/s/spglib/spglib-1.6.0.3.tar.gz#md5=8ae328fbd0ed381355c756bffca5653a (from https://pypi.python.org/simple/spglib/), version: 1.6.0.3
    Found link https://pypi.python.org/packages/source/s/spglib/spglib-1.6.0.tar.gz#md5=f85fe8f28e3f627c67cd18b1008b8a38 (from https://pypi.python.org/simple/spglib/), version: 1.6.0
    Found link https://pypi.python.org/packages/source/s/spglib/spglib-1.9.0.5.tar.gz#md5=3afebb6111509a00a54eeb64eec5acf5 (from https://pypi.python.org/simple/spglib/), version: 1.9.0.5
  Using version 1.9.0.5 (newest of versions: 1.9.0.5, 1.6.0.3, 1.6.0.2, 1.6.0.1, 1.6.0)
  Downloading from URL https://pypi.python.org/packages/source/s/spglib/spglib-1.9.0.5.tar.gz#md5=3afebb6111509a00a54eeb64eec5acf5 (from https://pypi.python.org/simple/spglib/)
  Running setup.py (path:/tmp/pip_build_specter119/spglib/setup.py) egg_info for package spglib
    running egg_info
    creating pip-egg-info/spglib.egg-info
    writing top-level names to pip-egg-info/spglib.egg-info/top_level.txt
    writing pip-egg-info/spglib.egg-info/PKG-INFO
    writing dependency_links to pip-egg-info/spglib.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/spglib.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found
    
    reading manifest file 'pip-egg-info/spglib.egg-info/SOURCES.txt'
    writing manifest file 'pip-egg-info/spglib.egg-info/SOURCES.txt'
  Source in /tmp/pip_build_specter119/spglib has version 1.9.0.5, which satisfies requirement spglib
Installing collected packages: spglib
  Running setup.py install for spglib
    Running command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_specter119/spglib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ent8liq5-record/install-record.txt --single-version-externally-managed --compile
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.4
    creating build/lib.linux-x86_64-3.4/spglib
    copying spglib/spglib.py -> build/lib.linux-x86_64-3.4/spglib
    copying spglib/__init__.py -> build/lib.linux-x86_64-3.4/spglib
    running build_ext
    building 'spglib._spglib' extension
    C compiler: gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC
    
    creating build/temp.linux-x86_64-3.4
    creating build/temp.linux-x86_64-3.4/src
    compile options: '-Isrc -I/usr/lib64/python3.4/site-packages/numpy/core/include -I/usr/include/python3.4m -c'
    gcc: src/kgrid.c
    gcc: src/primitive.c
    gcc: src/mathfunc.c
    gcc: src/sitesym_database.c
    gcc: src/site_symmetry.c
    gcc: src/symmetry.c
    gcc: src/lattice.c
    gcc: src/spglib.c
    gcc: src/spin.c
    gcc: src/cell.c
    gcc: src/kpoint.c
    src/kpoint.c: In function ‘get_ir_reciprocal_mesh’:
    src/kpoint.c:497:0: warning: ignoring #pragma omp parallel -Wunknown-pragmas]
     #pragma omp parallel for private(j, grid_point_rot, address_double, address_double_rot)
     ^
    src/kpoint.c:522:0: warning: ignoring #pragma omp parallel -Wunknown-pragmas]
     #pragma omp parallel for reduction(+:num_ir)
     ^
    gcc: src/spg_database.c
    gcc: _spglib.c
    _spglib.c:35:20: fatal error: Python.h: 没有那个文件或目录
     #include <Python.h>
                        ^
    compilation terminated.
    error: Command "gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -Isrc -I/usr/lib64/python3.4/site-packages/numpy/core/include -I/usr/include/python3.4m -c _spglib.c -o build/temp.linux-x86_64-3.4/_spglib.o" failed with exit status 1
    _spglib.c:35:20: fatal error: Python.h: 没有那个文件或目录
     #include <Python.h>
                        ^
    compilation terminated.
    Complete output from command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_specter119/spglib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ent8liq5-record/install-record.txt --single-version-externally-managed --compile:
    running install

running build

running build_py

creating build

creating build/lib.linux-x86_64-3.4

creating build/lib.linux-x86_64-3.4/spglib

copying spglib/spglib.py -> build/lib.linux-x86_64-3.4/spglib

copying spglib/__init__.py -> build/lib.linux-x86_64-3.4/spglib

running build_ext

building 'spglib._spglib' extension

C compiler: gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC



creating build/temp.linux-x86_64-3.4

creating build/temp.linux-x86_64-3.4/src

compile options: '-Isrc -I/usr/lib64/python3.4/site-packages/numpy/core/include -I/usr/include/python3.4m -c'

gcc: src/kgrid.c

gcc: src/primitive.c

gcc: src/mathfunc.c

gcc: src/sitesym_database.c

gcc: src/site_symmetry.c

gcc: src/symmetry.c

gcc: src/lattice.c

gcc: src/spglib.c

gcc: src/spin.c

gcc: src/cell.c

gcc: src/kpoint.c

src/kpoint.c: In function ‘get_ir_reciprocal_mesh’:

src/kpoint.c:497:0: warning: ignoring #pragma omp parallel -Wunknown-pragmas]

 #pragma omp parallel for private(j, grid_point_rot, address_double, address_double_rot)

 ^

src/kpoint.c:522:0: warning: ignoring #pragma omp parallel -Wunknown-pragmas]

 #pragma omp parallel for reduction(+:num_ir)

 ^

gcc: src/spg_database.c

gcc: _spglib.c

_spglib.c:35:20: fatal error: Python.h: 没有那个文件或目录

 #include <Python.h>

                    ^

compilation terminated.

error: Command "gcc -pthread -Wno-unused-result -Werror=declaration-after-statement -DNDEBUG -fmessage-length=0 -grecord-gcc-switches -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -g -DOPENSSL_LOAD_CONF -fPIC -Isrc -I/usr/lib64/python3.4/site-packages/numpy/core/include -I/usr/include/python3.4m -c _spglib.c -o build/temp.linux-x86_64-3.4/_spglib.o" failed with exit status 1

_spglib.c:35:20: fatal error: Python.h: 没有那个文件或目录

 #include <Python.h>

                    ^

compilation terminated.

----------------------------------------
Cleaning up...
  Removing temporary dir /tmp/pip_build_specter119...
Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_specter119/spglib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ent8liq5-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_specter119/spglib
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python3.4/site-packages/pip/commands/install.py", line 283, in run
    requirement_set.install(install_options, global_options, root=options.root_path)
  File "/usr/lib/python3.4/site-packages/pip/req.py", line 1435, in install
    requirement.install(install_options, global_options, *args, **kwargs)
  File "/usr/lib/python3.4/site-packages/pip/req.py", line 706, in install
    cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
  File "/usr/lib/python3.4/site-packages/pip/util.py", line 697, in call_subprocess
    % (command_desc, proc.returncode, cwd))
pip.exceptions.InstallationError: Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_specter119/spglib/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-ent8liq5-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_specter119/spglib

看起来像是缺了开发包?

试试 zypper in python3-devel (包名不知道是不是这个)

感谢,但是装上试了试,出错的地方没变…

@specter119

思路是对的,出错的地方没变是因为 include <Python.h> 默认了 Python.h 在 /usr/include。

但是 openSUSE 有两个 Python 版本(2.7 & 3.4),所以它的 Python 3 的头文件是在 /usr/include/python3.4m/Python.h。你得想办法给 spglib 打个补丁。不知道 pip 能不能安装本地 tar.gz 文件了,如果可以的话,你可以去 pypi 下载回来,改好再装。

另外其实给 openSUSE 打包个 python3-spglib 也不是很难的,自己维护,一劳永逸。

谢谢,我自己学学,搞起~

看到您回复是今天早晨了,昨天晚上换了发行版了,fedora scitific,能装上。不明白为啥都是pip3,然后别的发行版也都有python 2.7和3,别的发行版没这个事,等我弄懂python再回来~谢谢苏姐。

通过我的 LG-H818 上的 Tapatalk发言