今天用deepin安装python包的时候,报了这个问题。
报错
下面这么长一传报错,其实核心的就只有一点: Python.h文件找不到。我们要做的就是解决这个问题
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
   | (venv) mothra@mothra-PC:~/code/baidu-upd/encrypt2bdy$ pip3 install ruamel.yaml Collecting ruamel.yaml   Using cached https://files.pythonhosted.org/packages/d9/0e/2a05efa11ea33513fbdf4a2e2576fe94fd8fa5ad226dbb9c660886390974/ruamel.yaml-0.17.32-py3-none-any.whl Collecting ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.12" (from ruamel.yaml)   Using cached https://files.pythonhosted.org/packages/d5/31/a3e6411947eb7a4f1c669f887e9e47d61a68f9d117f10c3c620296694a0b/ruamel.yaml.clib-0.2.7.tar.gz Building wheels for collected packages: ruamel.yaml.clib   Running setup.py bdist_wheel for ruamel.yaml.clib ... error   Complete output from command /home/mothra/code/baidu-upd/encrypt2bdy/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-55f2q2xf/ruamel.yaml.clib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-m1ay2dbt --python-tag cp37:   sys.argv ['-c', 'bdist_wheel', '-d', '/tmp/pip-wheel-m1ay2dbt', '--python-tag', 'cp37']   test compiling /tmp/tmp_ruamel_qu43oc5r/test_ruamel_yaml.c -> test_ruamel_yaml OK   running bdist_wheel   running build   running build_py   Generating grammar tables from /usr/lib/python3.7/lib2to3/Grammar.txt   Generating grammar tables from /usr/lib/python3.7/lib2to3/PatternGrammar.txt   creating build   creating build/lib.linux-x86_64-3.7   creating build/lib.linux-x86_64-3.7/ruamel   copying .ruamel/__init__.py -> build/lib.linux-x86_64-3.7/ruamel   creating build/lib.linux-x86_64-3.7/ruamel/yaml   copying .ruamel/yaml/__init__.py -> build/lib.linux-x86_64-3.7/ruamel/yaml   creating build/lib.linux-x86_64-3.7/ruamel/yaml/clib   copying ./__init__.py -> build/lib.linux-x86_64-3.7/ruamel/yaml/clib   copying ./setup.py -> build/lib.linux-x86_64-3.7/ruamel/yaml/clib   copying ./LICENSE -> build/lib.linux-x86_64-3.7/ruamel/yaml/clib   running build_ext   building '_ruamel_yaml' extension   creating build/temp.linux-x86_64-3.7   x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/mothra/code/baidu-upd/encrypt2bdy/venv/include -I/usr/include/python3.7m -c _ruamel_yaml.c -o build/temp.linux-x86_64-3.7/_ruamel_yaml.o   _ruamel_yaml.c:6:10: fatal error: Python.h: 没有那个文件或目录    #include "Python.h"             ^~~~~~~~~~   compilation terminated.   error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
    Failed building wheel for ruamel.yaml.clib   Running setup.py clean for ruamel.yaml.clib Failed to build ruamel.yaml.clib Installing collected packages: ruamel.yaml.clib, ruamel.yaml   Running setup.py install for ruamel.yaml.clib ... error     Complete output from command /home/mothra/code/baidu-upd/encrypt2bdy/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-55f2q2xf/ruamel.yaml.clib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-lh0gyakn/install-record.txt --single-version-externally-managed --compile --install-headers /home/mothra/code/baidu-upd/encrypt2bdy/venv/include/site/python3.7/ruamel.yaml.clib:     sys.argv ['-c', 'install', '--record', '/tmp/pip-record-lh0gyakn/install-record.txt', '--single-version-externally-managed', '--compile', '--install-headers', '/home/mothra/code/baidu-upd/encrypt2bdy/venv/include/site/python3.7/ruamel.yaml.clib']     test compiling /tmp/tmp_ruamel_myagpa5e/test_ruamel_yaml.c -> test_ruamel_yaml OK     running install     running build     running build_py     Generating grammar tables from /usr/lib/python3.7/lib2to3/Grammar.txt     Generating grammar tables from /usr/lib/python3.7/lib2to3/PatternGrammar.txt     creating build     creating build/lib.linux-x86_64-3.7     creating build/lib.linux-x86_64-3.7/ruamel     copying .ruamel/__init__.py -> build/lib.linux-x86_64-3.7/ruamel     creating build/lib.linux-x86_64-3.7/ruamel/yaml     copying .ruamel/yaml/__init__.py -> build/lib.linux-x86_64-3.7/ruamel/yaml     creating build/lib.linux-x86_64-3.7/ruamel/yaml/clib     copying ./__init__.py -> build/lib.linux-x86_64-3.7/ruamel/yaml/clib     copying ./setup.py -> build/lib.linux-x86_64-3.7/ruamel/yaml/clib     copying ./LICENSE -> build/lib.linux-x86_64-3.7/ruamel/yaml/clib     running build_ext     building '_ruamel_yaml' extension     creating build/temp.linux-x86_64-3.7     x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/mothra/code/baidu-upd/encrypt2bdy/venv/include -I/usr/include/python3.7m -c _ruamel_yaml.c -o build/temp.linux-x86_64-3.7/_ruamel_yaml.o     _ruamel_yaml.c:6:10: fatal error: Python.h: 没有那个文件或目录      #include "Python.h"               ^~~~~~~~~~     compilation terminated.     error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
 
      ----------------------------------------
  Command "/home/mothra/code/baidu-upd/encrypt2bdy/venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-55f2q2xf/ruamel.yaml.clib/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-lh0gyakn/install-record.txt --single-version-externally-managed --compile --install-headers /home/mothra/code/baidu-upd/encrypt2bdy/venv/include/site/python3.7/ruamel.yaml.clib" failed with error code 1 in /tmp/pip-install-55f2q2xf/ruamel.yaml.clib/
   | 
 
解决
百度到的解决办法是安装python-dev
https://blog.csdn.net/CloudsRush/article/details/110580061
1
   | sudo apt-get install python-dev
   | 
 
先安装了这个,没有用,于是又安装了对应python版本的dev包
1
   | sudo apt-get install python3.7-dev
   | 
 
搞定!这下pip安装的时候没有报错了!
1 2 3 4 5 6 7 8 9 10 11
   | (venv) mothra@mothra-PC:~/code/baidu-upd/encrypt2bdy$ pip3 install ruamel.yaml Collecting ruamel.yaml   Using cached https://files.pythonhosted.org/packages/d9/0e/2a05efa11ea33513fbdf4a2e2576fe94fd8fa5ad226dbb9c660886390974/ruamel.yaml-0.17.32-py3-none-any.whl Collecting ruamel.yaml.clib>=0.2.7; platform_python_implementation == "CPython" and python_version < "3.12" (from ruamel.yaml)   Using cached https://files.pythonhosted.org/packages/d5/31/a3e6411947eb7a4f1c669f887e9e47d61a68f9d117f10c3c620296694a0b/ruamel.yaml.clib-0.2.7.tar.gz Building wheels for collected packages: ruamel.yaml.clib   Running setup.py bdist_wheel for ruamel.yaml.clib ... done   Stored in directory: /home/mothra/.cache/pip/wheels/2d/db/d8/e6ded7debed48ad2f416fc153122b7698eb136be4c254beffd Successfully built ruamel.yaml.clib Installing collected packages: ruamel.yaml.clib, ruamel.yaml Successfully installed ruamel.yaml-0.17.32 ruamel.yaml.clib-0.2.7
   |