首页 > 解决方案 > 无法在 Ubuntu 20.04 中使用 python 3.9 安装 gwpy 包

问题描述

我正在尝试在 Ubuntu 20.04 和 Python 3.9 中安装gwpy包

虽然使用以下命令成功安装了 python 3.8,但无法使其适用于 Python 3.9

pip3 install gwpy

上面的命令成功安装gwpy在目录中/.local/lib/python3.8/site-packages,并且在 Python 3.8 上运行良好

但是当我选择 Python 3.9 时,gwpy模块没有被识别并得到“ImportError:没有名为 gwpy 的模块”

已尝试以下命令用于 Python 3.9

python3.9 -m pip install

并且,

pip3.9 install gwpy

但得到同样的错误(下)

(我已经卸载并重新安装了 ligo-segments )

Building wheels for collected packages: ligo-segments
  Building wheel for ligo-segments (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/setup.py'"'"'; __file__='"'"'/tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-m3l2cb3f
       cwd: /tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/
  Complete output (20 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.9
  creating build/lib.linux-x86_64-3.9/ligo
  copying ligo/__init__.py -> build/lib.linux-x86_64-3.9/ligo
  creating build/lib.linux-x86_64-3.9/ligo/segments
  copying ligo/segments/utils.py -> build/lib.linux-x86_64-3.9/ligo/segments
  copying ligo/segments/__init__.py -> build/lib.linux-x86_64-3.9/ligo/segments
  running build_ext
  building 'ligo.segments.__segments' extension
  creating build/temp.linux-x86_64-3.9
  creating build/temp.linux-x86_64-3.9/src
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Isrc -I/usr/include/python3.9 -c src/infinity.c -o build/temp.linux-x86_64-3.9/src/infinity.o
  src/infinity.c:29:10: fatal error: Python.h: No such file or directory
     29 | #include <Python.h>
        |          ^~~~~~~~~~
  compilation terminated.
  error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for ligo-segments
  Running setup.py clean for ligo-segments
Failed to build ligo-segments
Installing collected packages: ligo-segments, pyerfa, gwdatafind, tqdm, ligotimegps, h5py, gwosc, dqsegdb2, astropy, gwpy
    Running setup.py install for ligo-segments ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/setup.py'"'"'; __file__='"'"'/tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-7g5qg2rc/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/paul/.local/include/python3.9/ligo-segments
         cwd: /tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/
    Complete output (20 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.9
    creating build/lib.linux-x86_64-3.9/ligo
    copying ligo/__init__.py -> build/lib.linux-x86_64-3.9/ligo
    creating build/lib.linux-x86_64-3.9/ligo/segments
    copying ligo/segments/utils.py -> build/lib.linux-x86_64-3.9/ligo/segments
    copying ligo/segments/__init__.py -> build/lib.linux-x86_64-3.9/ligo/segments
    running build_ext
    building 'ligo.segments.__segments' extension
    creating build/temp.linux-x86_64-3.9
    creating build/temp.linux-x86_64-3.9/src
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Isrc -I/usr/include/python3.9 -c src/infinity.c -o build/temp.linux-x86_64-3.9/src/infinity.o
    src/infinity.c:29:10: fatal error: Python.h: No such file or directory
       29 | #include <Python.h>
          |          ^~~~~~~~~~
    compilation terminated.
    error: command '/usr/bin/x86_64-linux-gnu-gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/setup.py'"'"'; __file__='"'"'/tmp/pip-install-l_etxqfg/ligo-segments_093d6d7361fe403dba837e6e5793581f/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-7g5qg2rc/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/paul/.local/include/python3.9/ligo-segments Check the logs for full command output.

我已经完全删除了 Python 3.9,并在我的系统中重新安装了它。

标签: pythonpython-3.xpip

解决方案


从问题底部的@Sujay 非常有用的评论中找到了解决方案。

这个 SO 帖子

刚刚安装在下面

sudo apt-get install python3.9-dev

推荐阅读