如何在 Ubuntu 中安装 Pycosat?

如何在 Ubuntu 中安装 Pycosat?

我跑了pip install pycosat,但是得到了:

Downloading/unpacking pycosat
  Downloading pycosat-0.6.1.tar.gz (59kB): 59kB downloaded
  Running setup.py (path:/tmp/pip_build_masi/pycosat/setup.py) egg_info for package pycosat

Installing collected packages: pycosat
  Running setup.py install for pycosat
    building 'pycosat' extension
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPYCOSAT_VERSION="0.6.1" -I/usr/include/python2.7 -c pycosat.c -o build/temp.linux-x86_64-2.7/pycosat.o
    pycosat.c:9:20: 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
    Complete output from command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_masi/pycosat/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-40CYkM-record/install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying test_pycosat.py -> build/lib.linux-x86_64-2.7
running build_ext
building 'pycosat' extension
creating build/temp.linux-x86_64-2.7
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPYCOSAT_VERSION="0.6.1" -I/usr/include/python2.7 -c pycosat.c -o build/temp.linux-x86_64-2.7/pycosat.o
pycosat.c:9:20: 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
----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_masi/pycosat/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-40CYkM-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_masi/pycosat
Storing debug log for failure in /home/masi/.pip/pip.log

我跑了sudo -H pip install pycosat,但是得到了:

Collecting pycosat
  Using cached pycosat-0.6.1.tar.gz
Building wheels for collected packages: pycosat
  Running setup.py bdist_wheel for pycosat ... error
  Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-0CcATa/pycosat/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpa1EG1Fpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-2.7
  copying test_pycosat.py -> build/lib.linux-x86_64-2.7
  running build_ext
  building 'pycosat' extension
  creating build/temp.linux-x86_64-2.7
  x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPYCOSAT_VERSION="0.6.1" -I/usr/include/python2.7 -c pycosat.c -o build/temp.linux-x86_64-2.7/pycosat.o
  pycosat.c:9:20: 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 pycosat
  Running setup.py clean for pycosat
Failed to build pycosat
Installing collected packages: pycosat
  Running setup.py install for pycosat ... error
    Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-0CcATa/pycosat/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-l6ZMSb-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    copying test_pycosat.py -> build/lib.linux-x86_64-2.7
    running build_ext
    building 'pycosat' extension
    creating build/temp.linux-x86_64-2.7
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DPYCOSAT_VERSION="0.6.1" -I/usr/include/python2.7 -c pycosat.c -o build/temp.linux-x86_64-2.7/pycosat.o
    pycosat.c:9:20: 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 "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-0CcATa/pycosat/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-l6ZMSb-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-0CcATa/pycosat/

评论

我不喜欢使用sudowith pip。但这里可能有必要。我不明白为什么gcc编译时会出现错误。


如何在 Ubuntu 中安装 Pycosat?

答案1

https://stackoverflow.com/a/32030746/486919sudo apt-get install python-dev跑步前先跑步pip install pycosat

答案2

2021 年更新:为了解决这个问题你应该使用以下命令:

sudo apt-get install python3-dev

...除非您使用的是 python2。

相关内容