Package fails to install in pip: no python.h [duplicate] - pip

This question already has answers here:
fatal error: Python.h: No such file or directory
(35 answers)
Closed last year.
when try to install a package from pip (numba, Minerl), i get this error:
Running setup.py install for getch ... error
ERROR: Command errored out with exit status 1:
command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kyiq6848/getch_81d2a001bdc842c789d2feb8e967906a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kyiq6848/getch_81d2a001bdc842c789d2feb8e967906a/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-d0vb8bqu/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/shawn/.local/include/python3.10/getch
cwd: /tmp/pip-install-kyiq6848/getch_81d2a001bdc842c789d2feb8e967906a/
Complete output (12 lines):
running install
running build
running build_ext
building 'getch' extension
creating build
creating build/temp.linux-x86_64-3.10
gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/usr/local/include -I/usr/include -I/usr/include/python3.10 -c getchmodule.c -o build/temp.linux-x86_64-3.10/getchmodule.o
getchmodule.c:1:10: fatal error: Python.h: No such file or directory
1 | #include <Python.h>
| ^~~~~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-kyiq6848/getch_81d2a001bdc842c789d2feb8e967906a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-kyiq6848/getch_81d2a001bdc842c789d2feb8e967906a/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-d0vb8bqu/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/shawn/.local/include/python3.10/getch Check the logs for full command output.
However, Jupyter notebooks successfully installed
(sorry for the noob qn i just started learning python a month ago)

Try pip install --only-binary. Pip is trying to compile from source and failing because the python headers aren't installed. If a precompiled binary exists it would make life easier (quicker install, no need to sort out headers) at the expense of being very slightly less optimised for your setup (=you will almost certainly not notice).
Alternatively, install the python headers. The precise method will vary depending on your linux, but you're looking for a package called something like python3-dev.
The ability to install jupyter is unrelated, particularly if you installed with the system package manager.

Related

Not able to install Pycairo while deploying app using Heroku

I'm trying to deploy a python app using Heroku, but I'm not able to install pycairo, which is added to requirements.txt file. I have used https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku-community/apt.tgz build-package to install required apt packages.
When I tried to install this package in Heroku bash using pip, it returned the same error.
Building wheel for pycairo (setup.py): started
Building wheel for pycairo (setup.py): finished with status 'error'
ERROR: Command errored out with exit status 1:
command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6rkzsy5d/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6rkzsy5d/pycairo/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-0eopb8bo
cwd: /tmp/pip-install-6rkzsy5d/pycairo/
Complete output (35 lines):
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.8
creating build/lib.linux-x86_64-3.8/cairo
copying cairo/__init__.py -> build/lib.linux-x86_64-3.8/cairo
copying cairo/__init__.pyi -> build/lib.linux-x86_64-3.8/cairo
copying cairo/py.typed -> build/lib.linux-x86_64-3.8/cairo
running build_ext
building 'cairo._cairo' extension
creating build/temp.linux-x86_64-3.8
creating build/temp.linux-x86_64-3.8/cairo
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DPYCAIRO_VERSION_MAJOR=1 -DPYCAIRO_VERSION_MINOR=19 -DPYCAIRO_VERSION_MICRO=1 -I/tmp/build_5896cd7c39526a1767b861fb4950464e/.apt/usr/include/cairo -I/tmp/build_5896cd7c39526a1767b861fb4950464e/.apt/usr/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/app/.heroku/python/include/python3.8 -c cairo/device.c -o build/temp.linux-x86_64-3.8/cairo/device.o -Wall -Warray-bounds -Wcast-align -Wconversion -Wextra -Wformat=2 -Wformat-nonliteral -Wformat-security -Wimplicit-function-declaration -Winit-self -Winline -Wmissing-format-attribute -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpacked -Wpointer-arith -Wreturn-type -Wshadow -Wsign-compare -Wstrict-aliasing -Wundef -Wunused-but-set-variable -Wswitch-default -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-command-line-argument -fno-strict-aliasing -fvisibility=hidden -std=c99
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
----------------------------------------
ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-6rkzsy5d/pycairo/setup.py'"'"'; __file__='"'"'/tmp/pip-install-6rkzsy5d/pycairo/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-lbe5cexs/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.8/pycairo Check the logs for full command output.
! Push rejected, failed to compile Python app.
! Push failed
Please don't link the archive file (.tgz) of the buildpack, but its homepage from here.
In the error output you posted, the build_ext function of the Python Setuptools build system fails to build cairo. In particular, the gcc compiler tells you that the ld linker failed. I guess it's because the script in the buildpack didn't link the cairo library.
I think you have 2 options:
Modify the Heroku buildpack and figure out how to install the cairo C library and link it when Pycairo runs the build_ext function.
Create a Dockerimage that includes the conda package manager (I would start from docker-miniconda) and install Pycairo as a conda recipe.
Option 2 should be far easier.
See also my other answer here.

pip install sanic : command 'gcc' terminated by signal 11

So I am trying to install sanic on my mac os yosemite but for some reason everytime I try to install it, it just returns this error.
building 'ujson' extension
creating build
creating build/temp.macosx-10.9-x86_64-3.6
creating build/temp.macosx-10.9-x86_64-3.6/python
creating build/temp.macosx-10.9-x86_64-3.6/lib
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I./python -I./lib -I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c ./python/ujson.c -o build/temp.macosx-10.9-x86_64-3.6/./python/ujson.o -D_GNU_SOURCE
error: command 'gcc' terminated by signal 11
Command "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/f8/vtw38lxs63d18dj7sztkyp9w0000gn/T/pip-install-74t39yin/ujson/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/f8/vtw38lxs63d18dj7sztkyp9w0000gn/T/pip-record-0hl9eodf/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/f8/vtw38lxs63d18dj7sztkyp9w0000gn/T/pip-install-74t39yin/ujson/
It also happens when I try to install vibora (another asynchronous web framework) or eventlet for flask websocket

"cannot find -lssl; cannot find -lcrypto" when installing mysql-python?

I'm struggling to install the mysql-python pip either systemwide or in a venv on Ubuntu 14.04 with MariaDB 10 installed. Also tried with MariaDB 5.5 and getting the same error. I don't have this issue with vanilla mysql-server installed.
I have the following installed via apt-get:
build-essential
python-dev
libmariadbclient-dev (thats the MariaDB replacement for libmysqlclient-dev)
python-mysqldb
Originally I thought this was an issue installing this into a venv but I've subsequently noticed mysql-python won't install systemwide either. Below are the cmds I used to install in a venv.
virtualenv venv
. venv/bin/activate
pip install mysql-python==1.2.5
In file included from _mysql.c:44:0:
/usr/include/mysql/my_config.h:439:0: warning: "HAVE_WCSCOLL" redefined [enabled by default]
#define HAVE_WCSCOLL
^
In file included from /usr/include/python2.7/pyconfig.h:3:0,
from /usr/include/python2.7/Python.h:8,
from _mysql.c:29:
/usr/include/x86_64-linux-gnu/python2.7/pyconfig.h:911:0: note: this is the location of the previous definition
#define HAVE_WCSCOLL 1
^x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmariadbclient_r -lpthread -lz -lm -lssl -lcrypto -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /root/env/bin/python -c "import setuptools, tokenize;__file__='/root/env/build/mysql- python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-EyhO2v-record/install-record.txt --single-version-externally-managed --compile --install-headers /root/env/include/site/python2.7 failed with error code 1 in /root/env/build/mysql-python
Storing debug log for failure in /root/.pip/pip.log
You need to have installed the development libraries of OpenSSL. It can be a libssl-dev, libssl-devel if your distribution provides separated packages for the dev libraries. Or install the complete openssl package if they don't.
(venv)➜ src pip install mysql-python==1.2.5
Downloading/unpacking mysql-python==1.2.5
Downloading MySQL-python-1.2.5.zip (108kB): 108kB downloaded
Running setup.py (path:/home/braiam/src/venv/build/mysql-python/setup.py) egg_info for package mysql-python
Installing collected packages: mysql-python
Running setup.py install for mysql-python
building '_mysql' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing
In file included from _mysql.c:44:0:
/usr/include/mysql/my_config.h:439:0: warning: "HAVE_WCSCOLL" redefined
#define HAVE_WCSCOLL
^
In file included from /usr/include/python2.7/pyconfig.h:3:0,
from /usr/include/python2.7/Python.h:8,
from _mysql.c:29:
/usr/include/x86_64-linux-gnu/python2.7/pyconfig.h:911:0: note: this is the location of the previous definition
#define HAVE_WCSCOLL 1
^
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmariadbclient_r -lpthread -lz -lm -lssl -lcrypto -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
Successfully installed mysql-python
Cleaning up...
But, there were two messages that you have that I didn't, namely:
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
Which if you did ld -lcrypto --verbose or ld -lssl --verbose wouldn't produce this results:
➜ src ld -lcrypto --verbose | grep succeeded
attempt to open //usr/lib/x86_64-linux-gnu/libcrypto.so succeeded
ld: warning: cannot find entry symbol _start; not setting start address
➜ src ld -lssl --verbose | grep succeeded
attempt to open //usr/lib/x86_64-linux-gnu/libssl.so succeeded
ld: warning: cannot find entry symbol _start; not setting start address
So, to fix this just make sure you have installed the libssl-dev package which provides both libraries.
I meet the similar error on MacOS but there is no "/usr/bin/ld: cannot find -lssl" for me.
Solved with the following steps:
Step 1. Make sure you have installed openssl with homebrew.
brew install openssl
Step 2. In a terminal:
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
For Linux you can also try yum install your missing library and add them to LIBRARY_PATH.
For Debian 9.x:
apt install libssl-dev
For CentOS:
sudo yum install openssl-devel

Error when installing Cython for use with Buildozer

I've run into an error while installing Kivy, which told me to install Cython, so I did.
Except I run into an error, I've tried installing with pip,easy_install, manually but it results in the same. I also tried installing a older version of Cython but no luck.
Error message:
Command /usr/bin/python -c "import setuptools, tokenize;file='/private/tmp/pip_build_root/Cython/setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-nXMqSR-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /private/tmp/pip_build_root/Cython
Storing debug log for failure in /Users/jorn/Library/Logs/pip.log
When I install manually I get this error:
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c Cython/Plex/Scanners.c -o build/temp.macosx-10.8-intel-2.7/Cython/Plex/Scanners.o
unable to execute clang: No such file or directory
error: command 'clang' failed with exit status 1
I have read and tried all solutions I could find but none work..
I'm running on Mac osx 10.8.5
Ok, thanks to what #RaynP just said about it being a osx/clang issue I found the solution:
credits to this blog: http://kaspermunck.github.io/2014/03/fixing-clang-error/
The error is related to Xcode 5.1.
You will have to download the cython-master from GitHub. Installing with pip will not work and results in another error.
in terminal go to the cython-master file and enter: sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future python setup.py install
This is a workaround the error.
Now I have installed Cython and can finally compile my app with Kivy/Buildozer:D

PIL installation error on Mac OS Maverics inside virtual env

I am trying to install PIL inside virtual as below
pip intall PIL
And i got the below error
Downloading/unpacking PIL
Running setup.py egg_info for package PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
Installing collected packages: PIL
Running setup.py install for PIL
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
--- using frameworks at /System/Library/Frameworks
building '_imagingft' extension
cc -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -pipe -Wno-error=unused-command-line-argument-hard-error-in-future -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/usr/local/include/freetype2 -IlibImaging -I/opt/local/include -I/Users/user/.virtualenvs/proj/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imagingft.c -o build/temp.macosx-10.9-intel-2.7/_imagingft.o
_imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found
#include <freetype/fterrors.h>
^
1 error generated.
error: command 'cc' failed with exit status 1
Complete output from command /Users/user/.virtualenvs/proj/bin/python -c "import setuptools;__file__='/Users/user/.virtualenvs/proj/build/PIL/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/pip-R5JSVs-record/install-record.txt --single-version-externally-managed --install-headers /Users/user/.virtualenvs/proj/include/site/python2.7:
WARNING: '' not a valid package name; please use only.-separated package names in setup.py
running install
running build
running build_py
running build_ext
--- using frameworks at /System/Library/Frameworks
building '_imagingft' extension
cc -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -pipe -Wno-error=unused-command-line-argument-hard-error-in-future -I/System/Library/Frameworks/Tcl.framework/Headers -I/System/Library/Frameworks/Tk.framework/Headers -I/usr/local/include/freetype2 -IlibImaging -I/opt/local/include -I/Users/user/.virtualenvs/proj/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imagingft.c -o build/temp.macosx-10.9-intel-2.7/_imagingft.o
_imagingft.c:73:10: fatal error: 'freetype/fterrors.h' file not found
#include <freetype/fterrors.h>
^
1 error generated.
error: command 'cc' failed with exit status 1
----------------------------------------
Command /Users/user/.virtualenvs/proj/bin/python -c "import setuptools;__file__='/Users/user/.virtualenvs/proj/build/PIL/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/x1/1bwt313j0qvgdh5pfzpbpvcw0000gn/T/pip-R5JSVs-record/install-record.txt --single-version-externally-managed --install-headers /Users/user/.virtualenvs/proj/include/site/python2.7 failed with error code 1 in /Users/user/.virtualenvs/proj/build/PIL
So how to fix it and can some one let me know why it is throwing me an error on my new macbook air ?
I suggest you try Pillow, the fork of PIL. I've not tried in a virtual machine but on Mac OS X you can do this:
brew install libtiff libjpeg webp little-cms2
pip install Pillow
Full details here: http://pillow.readthedocs.org/en/latest/installation.html#mac-os-x-installation

Resources