无法在 ubuntu 18.04 上安装 python3-dev 和 python3 的 pyyaml 包

无法在 ubuntu 18.04 上安装 python3-dev 和 python3 的 pyyaml 包

每次运行该命令时sudo apt-get install python3-dev都会出现以下错误:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 python3-dev : Depends: libpython3-dev (= 3.6.5-3ubuntu1) but it is not going to be installed
               Depends: python3.6-dev (>= 3.6.5-2~) but it is not going to be installed

我曾尝试过这个问题并尝试降级我的 Python 版本,但也没有效果。

我最初的目标是安装PyYaml包。pip3 install pyyaml返回以下错误:

Collecting pyyaml
  Using cached https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz
Building wheels for collected packages: pyyaml
  Running setup.py bdist_wheel for pyyaml ... error
  Complete output from command /home/mike/.virtualenvs/django-learning/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-9bovsmi4/pyyaml/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-7960lzxr --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/error.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/resolver.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/loader.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/composer.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/scanner.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/dumper.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/reader.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/__init__.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/nodes.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/tokens.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/constructor.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/representer.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/parser.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/cyaml.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/emitter.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/serializer.py -> build/lib.linux-x86_64-3.6/yaml
  copying lib3/yaml/events.py -> build/lib.linux-x86_64-3.6/yaml
  running build_ext
  creating build/temp.linux-x86_64-3.6
  checking if libyaml is compilable
  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/usr/include/python3.6m -I/home/mike/.virtualenvs/django-learning/include/python3.6m -c build/temp.linux-x86_64-3.6/check_libyaml.c -o build/temp.linux-x86_64-3.6/check_libyaml.o
  checking if libyaml is linkable
  x86_64-linux-gnu-gcc -pthread build/temp.linux-x86_64-3.6/check_libyaml.o -lyaml -o build/temp.linux-x86_64-3.6/check_libyaml
  building '_yaml' extension
  creating build/temp.linux-x86_64-3.6/ext
  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/usr/include/python3.6m -I/home/mike/.virtualenvs/django-learning/include/python3.6m -c ext/_yaml.c -o build/temp.linux-x86_64-3.6/ext/_yaml.o
  ext/_yaml.c:4:10: fatal error: Python.h: No such file or directory
   #include "Python.h"
            ^~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

  ----------------------------------------
  Failed building wheel for pyyaml
  Running setup.py clean for pyyaml
Failed to build pyyaml
Installing collected packages: pyyaml
  Running setup.py install for pyyaml ... error
    Complete output from command /home/mike/.virtualenvs/django-learning/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-9bovsmi4/pyyaml/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-37umjkqx/install-record.txt --single-version-externally-managed --compile --install-headers /home/mike/.virtualenvs/django-learning/include/site/python3.6/pyyaml:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/error.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/resolver.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/loader.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/composer.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/scanner.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/dumper.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/reader.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/__init__.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/nodes.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/tokens.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/constructor.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/representer.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/parser.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/cyaml.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/emitter.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/serializer.py -> build/lib.linux-x86_64-3.6/yaml
    copying lib3/yaml/events.py -> build/lib.linux-x86_64-3.6/yaml
    running build_ext
    creating build/temp.linux-x86_64-3.6
    checking if libyaml is compilable
    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/usr/include/python3.6m -I/home/mike/.virtualenvs/django-learning/include/python3.6m -c build/temp.linux-x86_64-3.6/check_libyaml.c -o build/temp.linux-x86_64-3.6/check_libyaml.o
    checking if libyaml is linkable
    x86_64-linux-gnu-gcc -pthread build/temp.linux-x86_64-3.6/check_libyaml.o -lyaml -o build/temp.linux-x86_64-3.6/check_libyaml
    building '_yaml' extension
    creating build/temp.linux-x86_64-3.6/ext
    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/usr/include/python3.6m -I/home/mike/.virtualenvs/django-learning/include/python3.6m -c ext/_yaml.c -o build/temp.linux-x86_64-3.6/ext/_yaml.o
    ext/_yaml.c:4:10: fatal error: Python.h: No such file or directory
     #include "Python.h"
              ^~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/mike/.virtualenvs/django-learning/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-9bovsmi4/pyyaml/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-37umjkqx/install-record.txt --single-version-externally-managed --compile --install-headers /home/mike/.virtualenvs/django-learning/include/site/python3.6/pyyaml" failed with error code 1 in /tmp/pip-install-9bovsmi4/pyyaml/

有多个来源告诉我要安装以解决这样的python3-dev错误error: command 'x86_64-linux-gnu-gcc' failed with exit status 1digital-ocean 教程和这个stackoverflow 问题

如何在 Ubuntu 18.04 中安装 PyYaml 包?

相关内容