pip Trouble building wheel while installing web3 [duplicate] - linux

I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:
gcc -Wall utilsmodule.c -o Utilc
After executing the command, I get this error message:
> utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.
I have tried all the suggested solutions over the internet but the problem still exists. I have no problem with Python.h. I managed to locate the file on my machine.

Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.
For apt (Ubuntu, Debian...):
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev # for python3.x installs
For yum (CentOS, RHEL...):
sudo yum install python-devel # for python2.x installs
sudo yum install python3-devel # for python3.x installs
For dnf (Fedora...):
sudo dnf install python2-devel # for python2.x installs
sudo dnf install python3-devel # for python3.x installs
For zypper (openSUSE...):
sudo zypper in python-devel # for python2.x installs
sudo zypper in python3-devel # for python3.x installs
For apk (Alpine...):
# This is a departure from the normal Alpine naming
# scheme, which uses py2- and py3- prefixes
sudo apk add python2-dev # for python2.x installs
sudo apk add python3-dev # for python3.x installs
For apt-cyg (Cygwin...):
apt-cyg install python-devel # for python2.x installs
apt-cyg install python3-devel # for python3.x installs
Note: python3-dev does not automatically cover all minor versions of python3, if you are using e.g. python 3.8 you may need to install python3.8-dev.

On Ubuntu, I was running Python 3 and I had to install
sudo apt-get install python3-dev
If you want to use a version of Python that is not linked to python3, install the associated python3.x-dev package. For example:
sudo apt-get install python3.5-dev

For Python 3.7 and Ubuntu in particular, I needed
sudo apt install libpython3.7-dev
.
I think at some point names were changed from pythonm.n-dev to this.
for Python 3.6, 3.8 through 3.10 (and counting…) similarly:
sudo apt install libpython3.6-dev 
sudo apt install libpython3.8-dev 
sudo apt install libpython3.9-dev
sudo apt install libpython3.10-dev

Two things you have to do.
Install development package for Python, in case of Debian/Ubuntu/Mint it's done with command:
sudo apt-get install python-dev
Second thing is that include files are not by default in the include path, nor is Python library linked with executable by default. You need to add these flags (replace Python's version accordingly):
-I/usr/include/python2.7 -lpython2.7
In other words your compile command ought to be:
gcc -Wall -I/usr/include/python2.7 -lpython2.7 utilsmodule.c -o Utilc

on Fedora run this for Python 2:
sudo dnf install python2-devel
and for Python 3:
sudo dnf install python3-devel

If you are using tox to run tests on multiple versions of Python, you may need to install the Python dev libraries for each version of Python you are testing on.
sudo apt-get install python2.6-dev
sudo apt-get install python2.7-dev
etc.

Make sure that the Python dev files come with your OS.
You should not hard code the library and include paths. Instead, use pkg-config, which will output the correct options for your specific system:
$ pkg-config --cflags --libs python2
-I/usr/include/python2.7 -lpython2.7
You may add it to your gcc line:
gcc -Wall utilsmodule.c -o Utilc $(pkg-config --cflags --libs python2)

For me, changing it to this worked:
#include <python2.7/Python.h>
I found the file /usr/include/python2.7/Python.h, and since /usr/include is already in the include path, then python2.7/Python.h should be sufficient.
You could also add the include path from command line instead - gcc -I/usr/lib/python2.7 (thanks #erm3nda).

Solution for Cygwin
You need to install the package python2-devel or python3-devel, depending on the Python version you're using.
You can quickly install it using the 32-bit or 64-bit setup.exe (depending on your installation) from Cygwin.com.
Example (modify setup.exe's filename and Python's major version if you need):
$ setup.exe -q --packages=python3-devel
You can also check my other answer for a few more options to install Cygwin's packages from the command-line.

In AWS API (centOS) its
yum install python27-devel

AWS EC2 install running python34:
sudo yum install python34-devel

If you use a virtualenv with a 3.6 python (edge right now), be sure to install the matching python 3.6 dev sudo apt-get install python3.6-dev, otherwise executing sudo python3-dev will install the python dev 3.3.3-1, which won't solve the issue.

In my case, what fixed it in Ubuntu was to install the packages libpython-all-dev (or libpython3-all-dev if you use Python 3).

It's not the same situation, but it also works for me and now I can use SWIG with Python3.5:
I was trying to compile:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
With Python 2.7 works fine, not with my version 3.5:
existe_wrap.c:147:21: fatal error: Python.h: No existe el archivo o el
directorio compilation terminated.
After run in my Ubuntu 16.04 installation:
sudo apt-get install python3-dev # for python3.x installs
Now I can compile without problems Python3.5:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/

I managed to solve this issue and generate the .so file in one command
gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7 utilsmodule.c

I also encountered this error when I was installing coolprop in ubuntu.
For ubuntu 16.04 with python 3.6
sudo apt-get install python3.6-dev
If ever this doesn't work try installing/updating gcc lib.
sudo apt-get install gcc

try apt-file. It is difficult to remember the package name where the missing file resides. It is generic and useful for any package files.
For example:
root#ubuntu234:~/auto# apt-file search --regexp '/Python.h$'
pypy-dev: /usr/lib/pypy/include/Python.h
python2.7-dbg: /usr/include/python2.7_d/Python.h
python2.7-dev: /usr/include/python2.7/Python.h
python3.2-dbg: /usr/include/python3.2dmu/Python.h
python3.2-dev: /usr/include/python3.2mu/Python.h
root#ubuntu234:~/auto#
Now you can make an expert guess as to which one to choose from.

This problem can also arrive when you have different Python versions installed and you use a pip that's not the system's one. In that case, the non-system pip won't find the right version of Python headers.
It happened to me when trying to pip install a package for a Python bundled with an application. As it was not system's python, apt install pythonXX-dev didn't work.
In this case, the solution is to find the right python header:
find / -iname 'Python.h'
In the output, you will see system python headers, and hopefully the one you are looking for, for example:
/usr/include/python3.7m/Python.h
/usr/include/python3.6m/Python.h
/home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.8.5-h7579374_1/include/python3.8/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.7.0-h6e4f718_3/include/python3.7m/Python.h
/home/ubuntu/miniconda3/include/python3.8/Python.h
/home/ubuntu/miniconda3/envs/sim/include/python3.7m/Python.h
/home/ubuntu/src/blender-deps/Python-3.7.7/Include/Python.h
/opt/lib/python-3.7.7/include/python3.7m/Python.h
Then, you can set a compiler flag that will get used by gcc when called by pip.
Mine was /home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h, so I did:
export CPPFLAGS=-I/home/ubuntu/src/blender-deps/Python-3.7.7/Include
pip install <package>

For CentOS 7:
sudo yum install python36u-devel
I followed the instructions here for installing python3.6 on several VMs: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7
and was then able to build mod_wsgi and get it working with a python3.6 virtualenv

For the OpenSuse comrades out there:
sudo zypper install python3-devel

Here is yet another solution, because none of these solutions worked for me. For reference, I was trying to pip install something on an Amazon Linux AMI base Docker image for Python 3.6.
Non-docker solution:
# Install python3-devel like everyone says
yum -y install python36-devel.x86_64
# Find the install directory of `Python.h`
rpm -ql python36-devel.x86_64 | grep -i "Python.h"
# Forcefully add it to your include path
C_INCLUDE_PATH='/usr/include/python3.6m'
export C_INCLUDE_PATH
Docker solution:
# Install python3-devel like everyone says
RUN yum -y install python36-devel.x86_64
# Find the install directory of `Python.h`, for me it was /usr/include/python3.6m
RUN rpm -ql python36-devel.x86_64 | grep -i "Python.h" && fake_command_so_docker_fails_and_shows_us_the_output
# Since the previous command contains a purposeful error, remove it before the next run
# Forcefully add it to your include path
ARG C_INCLUDE_PATH='/usr/include/python3.6m'
NOTE: If you're getting the error when compiling C++, use CPLUS_INCLUDE_PATH.
Alternatively, you may prefer to use another Docker image. For example, I was trying to install asyncpg~=0.24.0 on python:3.9.4-slim, which generated the same error as you saw. However, when I updated the image to python:3, it worked fine.

If you're using Python 3.6 on Amazon Linux (based on RHEL, but the RHEL answers given here didn't work):
sudo yum install python36-devel

You must install the Python development files on your operating system if the Python provided with your operating system does not come with them. The many answers on this question show the myriad ways this can be achieved on different systems.
When you have done so, the problem is telling the compiler where they're located and how to compile against them. Python comes with a program called python-config. For compilation, you need the --includes output and for linking a program against the Python library (embedding Python into your program) the --ldflags output. Example:
gcc -c mypythonprogram.c $(python3-config --includes)
gcc -o program mypythonprogram.o $(python3-config --ldflags)
The python-config program can be named after the Python versions - on Debian, Ubuntu for example these can be named python3-config or python3.6-config.

Sure python-dev or libpython-all-dev are the first thing to (apt )install, but if that doesn't help as was my case, I advice you to install the foreign Function Interface packages by sudo apt-get install libffi-dev and sudo pip install cffi.
This should help out especially if you see the error as/from c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory.

try locate your Python.h:
gemfield#ThinkPad-X1C:~$ locate Python.h
/home/gemfield/anaconda3/include/python3.7m/Python.h
/home/gemfield/anaconda3/pkgs/python-3.7.6-h0371630_2/include/python3.7m/Python.h
/usr/include/python3.8/Python.h
if not found, then install python-dev or python3-dev; else include the correct header path for compiler:
g++ -I/usr/include/python3.8 ...

I am on Ubuntu. I have installed all packages as was recommended in some answers.
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev # for python3.x installs
I still had this problem, the line:
#include "Python.h"
And some others, I can edit them manually, it is a bad practice.
I know the secret now, it comes from the cython source code. I have the file. It compiles without errors. That is the file.
Change PYTHON to python version you have, python/python3. Change FILE to your c-filename. The name of the makefile file should be Makefile. Run the the file with the command:
make all
Makefile for creating our standalone Cython program
FILE := file.c
PYTHON := python3
PYVERSION := $(shell $(PYTHON) -c "import sys;
print(sys.version[:3])")
PYPREFIX := $(shell $(PYTHON) -c "import sys; print(sys.prefix)")
INCDIR := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_python_inc())")
PLATINCDIR := $(shell $(PYTHON) -c "from distutils import
sysconfig; print(sysconfig.get_python_inc(plat_specific=True))")
LIBDIR1 := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBDIR'))")
LIBDIR2 := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBPL'))")
PYLIB := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBRARY')[3:-2])")
CC := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('CC'))")
LINKCC := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LINKCC'))")
LINKFORSHARED := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LINKFORSHARED'))")
LIBS := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LIBS'))")
SYSLIBS := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('SYSLIBS'))")
.PHONY: paths all clean test
paths:
#echo "PYTHON=$(PYTHON)"
#echo "PYVERSION=$(PYVERSION)"
#echo "PYPREFIX=$(PYPREFIX)"
#echo "INCDIR=$(INCDIR)"
#echo "PLATINCDIR=$(PLATINCDIR)"
#echo "LIBDIR1=$(LIBDIR1)"
#echo "LIBDIR2=$(LIBDIR2)"
#echo "PYLIB=$(PYLIB)"
#echo "CC=$(CC)"
#echo "LINKCC=$(LINKCC)"
#echo "LINKFORSHARED=$(LINKFORSHARED)"
#echo "LIBS=$(LIBS)"
#echo "SYSLIBS=$(SYSLIBS)"
$(FILE:.c=): $(FILE:.c=.o)
$(LINKCC) -o $# $^ -L$(LIBDIR1) -L$(LIBDIR2) -l$(PYLIB)
$(LIBS) $(SYSLIBS) $(LINKFORSHARED)
$(FILE:.c=.o): $(FILE)
$(CC) -c $^ -I$(INCDIR) -I$(PLATINCDIR)
all: $(FILE:.c=)

This error occurred when I attempted to install ctds on CentOS 7 with Python3.6. I did all the tricks mentioned here including yum install python34-devel. The problem was Python.h was found in /usr/include/python3.4m but not in /usr/include/python3.6m. I tried to use --global-option to point to include dir (pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds). This resulted in a lpython3.6m not found when linking ctds.
Finally what worked was fixing the development environment for Python3.6 needs to correct with the include and libs.
yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/python36u-libs-3.6.3-1.ius.centos7.x86_64.rpm
Python.h needs to be in your include path for gcc. Whichever version of python is used, for example if it's 3.6, then it should be in /usr/include/python3.6m/Python.h typically.

Sometimes even after installing python-dev the error persists,
Check for the error if it is 'gcc' missing.
First download as stated in https://stackoverflow.com/a/21530768/8687063, then install gcc
For apt (Ubuntu, Debian...):
sudo apt-get install gcc
For yum (CentOS, RHEL...):
sudo yum install gcc
For dnf (Fedora...):
sudo dnf install gcc
For zypper (openSUSE...):
sudo zypper in gcc
For apk (Alpine...):
sudo apk gcc

It often appear when you trying to remove python3.5 and install python3.6.
So when using python3 (which python3 -V => python3.6) to install some packages required python3.5 header will appear this error.
Resolve by install python3.6-dev module.

This means that Python.h isn't in your compiler's default include paths. Have you installed it system-wide or locally? What's your OS?
You could use the -I<path> flag to specify an additional directory where your compiler should look for headers. You will probably have to follow up with -L<path> so that gcc can find the library you'll be linking with using -l<name>.

Related

pip install fasttext gives fatal error on Linux [duplicate]

I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:
gcc -Wall utilsmodule.c -o Utilc
After executing the command, I get this error message:
> utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.
I have tried all the suggested solutions over the internet but the problem still exists. I have no problem with Python.h. I managed to locate the file on my machine.
Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.
For apt (Ubuntu, Debian...):
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev # for python3.x installs
For yum (CentOS, RHEL...):
sudo yum install python-devel # for python2.x installs
sudo yum install python3-devel # for python3.x installs
For dnf (Fedora...):
sudo dnf install python2-devel # for python2.x installs
sudo dnf install python3-devel # for python3.x installs
For zypper (openSUSE...):
sudo zypper in python-devel # for python2.x installs
sudo zypper in python3-devel # for python3.x installs
For apk (Alpine...):
# This is a departure from the normal Alpine naming
# scheme, which uses py2- and py3- prefixes
sudo apk add python2-dev # for python2.x installs
sudo apk add python3-dev # for python3.x installs
For apt-cyg (Cygwin...):
apt-cyg install python-devel # for python2.x installs
apt-cyg install python3-devel # for python3.x installs
Note: python3-dev does not automatically cover all minor versions of python3, if you are using e.g. python 3.8 you may need to install python3.8-dev.
On Ubuntu, I was running Python 3 and I had to install
sudo apt-get install python3-dev
If you want to use a version of Python that is not linked to python3, install the associated python3.x-dev package. For example:
sudo apt-get install python3.5-dev
For Python 3.7 and Ubuntu in particular, I needed
sudo apt install libpython3.7-dev
.
I think at some point names were changed from pythonm.n-dev to this.
for Python 3.6, 3.8 through 3.10 (and counting…) similarly:
sudo apt install libpython3.6-dev 
sudo apt install libpython3.8-dev 
sudo apt install libpython3.9-dev
sudo apt install libpython3.10-dev
Two things you have to do.
Install development package for Python, in case of Debian/Ubuntu/Mint it's done with command:
sudo apt-get install python-dev
Second thing is that include files are not by default in the include path, nor is Python library linked with executable by default. You need to add these flags (replace Python's version accordingly):
-I/usr/include/python2.7 -lpython2.7
In other words your compile command ought to be:
gcc -Wall -I/usr/include/python2.7 -lpython2.7 utilsmodule.c -o Utilc
on Fedora run this for Python 2:
sudo dnf install python2-devel
and for Python 3:
sudo dnf install python3-devel
If you are using tox to run tests on multiple versions of Python, you may need to install the Python dev libraries for each version of Python you are testing on.
sudo apt-get install python2.6-dev
sudo apt-get install python2.7-dev
etc.
Make sure that the Python dev files come with your OS.
You should not hard code the library and include paths. Instead, use pkg-config, which will output the correct options for your specific system:
$ pkg-config --cflags --libs python2
-I/usr/include/python2.7 -lpython2.7
You may add it to your gcc line:
gcc -Wall utilsmodule.c -o Utilc $(pkg-config --cflags --libs python2)
For me, changing it to this worked:
#include <python2.7/Python.h>
I found the file /usr/include/python2.7/Python.h, and since /usr/include is already in the include path, then python2.7/Python.h should be sufficient.
You could also add the include path from command line instead - gcc -I/usr/lib/python2.7 (thanks #erm3nda).
Solution for Cygwin
You need to install the package python2-devel or python3-devel, depending on the Python version you're using.
You can quickly install it using the 32-bit or 64-bit setup.exe (depending on your installation) from Cygwin.com.
Example (modify setup.exe's filename and Python's major version if you need):
$ setup.exe -q --packages=python3-devel
You can also check my other answer for a few more options to install Cygwin's packages from the command-line.
In AWS API (centOS) its
yum install python27-devel
AWS EC2 install running python34:
sudo yum install python34-devel
If you use a virtualenv with a 3.6 python (edge right now), be sure to install the matching python 3.6 dev sudo apt-get install python3.6-dev, otherwise executing sudo python3-dev will install the python dev 3.3.3-1, which won't solve the issue.
In my case, what fixed it in Ubuntu was to install the packages libpython-all-dev (or libpython3-all-dev if you use Python 3).
It's not the same situation, but it also works for me and now I can use SWIG with Python3.5:
I was trying to compile:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
With Python 2.7 works fine, not with my version 3.5:
existe_wrap.c:147:21: fatal error: Python.h: No existe el archivo o el
directorio compilation terminated.
After run in my Ubuntu 16.04 installation:
sudo apt-get install python3-dev # for python3.x installs
Now I can compile without problems Python3.5:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
I managed to solve this issue and generate the .so file in one command
gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7 utilsmodule.c
I also encountered this error when I was installing coolprop in ubuntu.
For ubuntu 16.04 with python 3.6
sudo apt-get install python3.6-dev
If ever this doesn't work try installing/updating gcc lib.
sudo apt-get install gcc
try apt-file. It is difficult to remember the package name where the missing file resides. It is generic and useful for any package files.
For example:
root#ubuntu234:~/auto# apt-file search --regexp '/Python.h$'
pypy-dev: /usr/lib/pypy/include/Python.h
python2.7-dbg: /usr/include/python2.7_d/Python.h
python2.7-dev: /usr/include/python2.7/Python.h
python3.2-dbg: /usr/include/python3.2dmu/Python.h
python3.2-dev: /usr/include/python3.2mu/Python.h
root#ubuntu234:~/auto#
Now you can make an expert guess as to which one to choose from.
This problem can also arrive when you have different Python versions installed and you use a pip that's not the system's one. In that case, the non-system pip won't find the right version of Python headers.
It happened to me when trying to pip install a package for a Python bundled with an application. As it was not system's python, apt install pythonXX-dev didn't work.
In this case, the solution is to find the right python header:
find / -iname 'Python.h'
In the output, you will see system python headers, and hopefully the one you are looking for, for example:
/usr/include/python3.7m/Python.h
/usr/include/python3.6m/Python.h
/home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.8.5-h7579374_1/include/python3.8/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.7.0-h6e4f718_3/include/python3.7m/Python.h
/home/ubuntu/miniconda3/include/python3.8/Python.h
/home/ubuntu/miniconda3/envs/sim/include/python3.7m/Python.h
/home/ubuntu/src/blender-deps/Python-3.7.7/Include/Python.h
/opt/lib/python-3.7.7/include/python3.7m/Python.h
Then, you can set a compiler flag that will get used by gcc when called by pip.
Mine was /home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h, so I did:
export CPPFLAGS=-I/home/ubuntu/src/blender-deps/Python-3.7.7/Include
pip install <package>
For CentOS 7:
sudo yum install python36u-devel
I followed the instructions here for installing python3.6 on several VMs: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7
and was then able to build mod_wsgi and get it working with a python3.6 virtualenv
For the OpenSuse comrades out there:
sudo zypper install python3-devel
Here is yet another solution, because none of these solutions worked for me. For reference, I was trying to pip install something on an Amazon Linux AMI base Docker image for Python 3.6.
Non-docker solution:
# Install python3-devel like everyone says
yum -y install python36-devel.x86_64
# Find the install directory of `Python.h`
rpm -ql python36-devel.x86_64 | grep -i "Python.h"
# Forcefully add it to your include path
C_INCLUDE_PATH='/usr/include/python3.6m'
export C_INCLUDE_PATH
Docker solution:
# Install python3-devel like everyone says
RUN yum -y install python36-devel.x86_64
# Find the install directory of `Python.h`, for me it was /usr/include/python3.6m
RUN rpm -ql python36-devel.x86_64 | grep -i "Python.h" && fake_command_so_docker_fails_and_shows_us_the_output
# Since the previous command contains a purposeful error, remove it before the next run
# Forcefully add it to your include path
ARG C_INCLUDE_PATH='/usr/include/python3.6m'
NOTE: If you're getting the error when compiling C++, use CPLUS_INCLUDE_PATH.
Alternatively, you may prefer to use another Docker image. For example, I was trying to install asyncpg~=0.24.0 on python:3.9.4-slim, which generated the same error as you saw. However, when I updated the image to python:3, it worked fine.
If you're using Python 3.6 on Amazon Linux (based on RHEL, but the RHEL answers given here didn't work):
sudo yum install python36-devel
You must install the Python development files on your operating system if the Python provided with your operating system does not come with them. The many answers on this question show the myriad ways this can be achieved on different systems.
When you have done so, the problem is telling the compiler where they're located and how to compile against them. Python comes with a program called python-config. For compilation, you need the --includes output and for linking a program against the Python library (embedding Python into your program) the --ldflags output. Example:
gcc -c mypythonprogram.c $(python3-config --includes)
gcc -o program mypythonprogram.o $(python3-config --ldflags)
The python-config program can be named after the Python versions - on Debian, Ubuntu for example these can be named python3-config or python3.6-config.
Sure python-dev or libpython-all-dev are the first thing to (apt )install, but if that doesn't help as was my case, I advice you to install the foreign Function Interface packages by sudo apt-get install libffi-dev and sudo pip install cffi.
This should help out especially if you see the error as/from c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory.
try locate your Python.h:
gemfield#ThinkPad-X1C:~$ locate Python.h
/home/gemfield/anaconda3/include/python3.7m/Python.h
/home/gemfield/anaconda3/pkgs/python-3.7.6-h0371630_2/include/python3.7m/Python.h
/usr/include/python3.8/Python.h
if not found, then install python-dev or python3-dev; else include the correct header path for compiler:
g++ -I/usr/include/python3.8 ...
I am on Ubuntu. I have installed all packages as was recommended in some answers.
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev # for python3.x installs
I still had this problem, the line:
#include "Python.h"
And some others, I can edit them manually, it is a bad practice.
I know the secret now, it comes from the cython source code. I have the file. It compiles without errors. That is the file.
Change PYTHON to python version you have, python/python3. Change FILE to your c-filename. The name of the makefile file should be Makefile. Run the the file with the command:
make all
Makefile for creating our standalone Cython program
FILE := file.c
PYTHON := python3
PYVERSION := $(shell $(PYTHON) -c "import sys;
print(sys.version[:3])")
PYPREFIX := $(shell $(PYTHON) -c "import sys; print(sys.prefix)")
INCDIR := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_python_inc())")
PLATINCDIR := $(shell $(PYTHON) -c "from distutils import
sysconfig; print(sysconfig.get_python_inc(plat_specific=True))")
LIBDIR1 := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBDIR'))")
LIBDIR2 := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBPL'))")
PYLIB := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBRARY')[3:-2])")
CC := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('CC'))")
LINKCC := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LINKCC'))")
LINKFORSHARED := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LINKFORSHARED'))")
LIBS := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LIBS'))")
SYSLIBS := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('SYSLIBS'))")
.PHONY: paths all clean test
paths:
#echo "PYTHON=$(PYTHON)"
#echo "PYVERSION=$(PYVERSION)"
#echo "PYPREFIX=$(PYPREFIX)"
#echo "INCDIR=$(INCDIR)"
#echo "PLATINCDIR=$(PLATINCDIR)"
#echo "LIBDIR1=$(LIBDIR1)"
#echo "LIBDIR2=$(LIBDIR2)"
#echo "PYLIB=$(PYLIB)"
#echo "CC=$(CC)"
#echo "LINKCC=$(LINKCC)"
#echo "LINKFORSHARED=$(LINKFORSHARED)"
#echo "LIBS=$(LIBS)"
#echo "SYSLIBS=$(SYSLIBS)"
$(FILE:.c=): $(FILE:.c=.o)
$(LINKCC) -o $# $^ -L$(LIBDIR1) -L$(LIBDIR2) -l$(PYLIB)
$(LIBS) $(SYSLIBS) $(LINKFORSHARED)
$(FILE:.c=.o): $(FILE)
$(CC) -c $^ -I$(INCDIR) -I$(PLATINCDIR)
all: $(FILE:.c=)
This error occurred when I attempted to install ctds on CentOS 7 with Python3.6. I did all the tricks mentioned here including yum install python34-devel. The problem was Python.h was found in /usr/include/python3.4m but not in /usr/include/python3.6m. I tried to use --global-option to point to include dir (pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds). This resulted in a lpython3.6m not found when linking ctds.
Finally what worked was fixing the development environment for Python3.6 needs to correct with the include and libs.
yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/python36u-libs-3.6.3-1.ius.centos7.x86_64.rpm
Python.h needs to be in your include path for gcc. Whichever version of python is used, for example if it's 3.6, then it should be in /usr/include/python3.6m/Python.h typically.
Sometimes even after installing python-dev the error persists,
Check for the error if it is 'gcc' missing.
First download as stated in https://stackoverflow.com/a/21530768/8687063, then install gcc
For apt (Ubuntu, Debian...):
sudo apt-get install gcc
For yum (CentOS, RHEL...):
sudo yum install gcc
For dnf (Fedora...):
sudo dnf install gcc
For zypper (openSUSE...):
sudo zypper in gcc
For apk (Alpine...):
sudo apk gcc
It often appear when you trying to remove python3.5 and install python3.6.
So when using python3 (which python3 -V => python3.6) to install some packages required python3.5 header will appear this error.
Resolve by install python3.6-dev module.
This means that Python.h isn't in your compiler's default include paths. Have you installed it system-wide or locally? What's your OS?
You could use the -I<path> flag to specify an additional directory where your compiler should look for headers. You will probably have to follow up with -L<path> so that gcc can find the library you'll be linking with using -l<name>.

I want to install G++ on my Linux Mint but not able to do so

I want to install g++ for using GROMACS on Linux mint. I typed the following command:
sudo apt-get install g++
It successfully installs the g++ but when I change the directory to Downloads to configure and make cmake and fftw, it (Downloads) is empty.
I have tried removing sudo apt-get remove g++ and re-installing g++ but it shows the same result. I don't know where it is downloading g++.
The command apt-get install g++ doesn't download any executables into your current directory or in the ~/Downloads/ directory.
Usually, it is installed in /usr/bin.
You can check for g++ with the command g++ --version.
Also, you can see where it is installed with whereis g++.
The build-essential package is a reference for all the packages needed
to compile a Debian package. It generally includes the GCC/g++
compilers and libraries and some other utilities
https://superuser.com/a/151558
For this purpose install them with command sudo apt install build-essential
and it will install all the things

Unable to install Twisted [duplicate]

I am trying to build a shared library using a C extension file but first I have to generate the output file using the command below:
gcc -Wall utilsmodule.c -o Utilc
After executing the command, I get this error message:
> utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.
I have tried all the suggested solutions over the internet but the problem still exists. I have no problem with Python.h. I managed to locate the file on my machine.
Looks like you haven't properly installed the header files and static libraries for python dev. Use your package manager to install them system-wide.
For apt (Ubuntu, Debian...):
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev # for python3.x installs
For yum (CentOS, RHEL...):
sudo yum install python-devel # for python2.x installs
sudo yum install python3-devel # for python3.x installs
For dnf (Fedora...):
sudo dnf install python2-devel # for python2.x installs
sudo dnf install python3-devel # for python3.x installs
For zypper (openSUSE...):
sudo zypper in python-devel # for python2.x installs
sudo zypper in python3-devel # for python3.x installs
For apk (Alpine...):
# This is a departure from the normal Alpine naming
# scheme, which uses py2- and py3- prefixes
sudo apk add python2-dev # for python2.x installs
sudo apk add python3-dev # for python3.x installs
For apt-cyg (Cygwin...):
apt-cyg install python-devel # for python2.x installs
apt-cyg install python3-devel # for python3.x installs
Note: python3-dev does not automatically cover all minor versions of python3, if you are using e.g. python 3.8 you may need to install python3.8-dev.
On Ubuntu, I was running Python 3 and I had to install
sudo apt-get install python3-dev
If you want to use a version of Python that is not linked to python3, install the associated python3.x-dev package. For example:
sudo apt-get install python3.5-dev
For Python 3.7 and Ubuntu in particular, I needed
sudo apt install libpython3.7-dev
.
I think at some point names were changed from pythonm.n-dev to this.
for Python 3.6, 3.8 through 3.10 (and counting…) similarly:
sudo apt install libpython3.6-dev 
sudo apt install libpython3.8-dev 
sudo apt install libpython3.9-dev
sudo apt install libpython3.10-dev
Two things you have to do.
Install development package for Python, in case of Debian/Ubuntu/Mint it's done with command:
sudo apt-get install python-dev
Second thing is that include files are not by default in the include path, nor is Python library linked with executable by default. You need to add these flags (replace Python's version accordingly):
-I/usr/include/python2.7 -lpython2.7
In other words your compile command ought to be:
gcc -Wall -I/usr/include/python2.7 -lpython2.7 utilsmodule.c -o Utilc
on Fedora run this for Python 2:
sudo dnf install python2-devel
and for Python 3:
sudo dnf install python3-devel
If you are using tox to run tests on multiple versions of Python, you may need to install the Python dev libraries for each version of Python you are testing on.
sudo apt-get install python2.6-dev
sudo apt-get install python2.7-dev
etc.
Make sure that the Python dev files come with your OS.
You should not hard code the library and include paths. Instead, use pkg-config, which will output the correct options for your specific system:
$ pkg-config --cflags --libs python2
-I/usr/include/python2.7 -lpython2.7
You may add it to your gcc line:
gcc -Wall utilsmodule.c -o Utilc $(pkg-config --cflags --libs python2)
For me, changing it to this worked:
#include <python2.7/Python.h>
I found the file /usr/include/python2.7/Python.h, and since /usr/include is already in the include path, then python2.7/Python.h should be sufficient.
You could also add the include path from command line instead - gcc -I/usr/lib/python2.7 (thanks #erm3nda).
Solution for Cygwin
You need to install the package python2-devel or python3-devel, depending on the Python version you're using.
You can quickly install it using the 32-bit or 64-bit setup.exe (depending on your installation) from Cygwin.com.
Example (modify setup.exe's filename and Python's major version if you need):
$ setup.exe -q --packages=python3-devel
You can also check my other answer for a few more options to install Cygwin's packages from the command-line.
In AWS API (centOS) its
yum install python27-devel
AWS EC2 install running python34:
sudo yum install python34-devel
If you use a virtualenv with a 3.6 python (edge right now), be sure to install the matching python 3.6 dev sudo apt-get install python3.6-dev, otherwise executing sudo python3-dev will install the python dev 3.3.3-1, which won't solve the issue.
In my case, what fixed it in Ubuntu was to install the packages libpython-all-dev (or libpython3-all-dev if you use Python 3).
It's not the same situation, but it also works for me and now I can use SWIG with Python3.5:
I was trying to compile:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
With Python 2.7 works fine, not with my version 3.5:
existe_wrap.c:147:21: fatal error: Python.h: No existe el archivo o el
directorio compilation terminated.
After run in my Ubuntu 16.04 installation:
sudo apt-get install python3-dev # for python3.x installs
Now I can compile without problems Python3.5:
gcc -fPIC -c existe.c existe_wrap.c -I /usr/include/python3.5m/
I managed to solve this issue and generate the .so file in one command
gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7 utilsmodule.c
I also encountered this error when I was installing coolprop in ubuntu.
For ubuntu 16.04 with python 3.6
sudo apt-get install python3.6-dev
If ever this doesn't work try installing/updating gcc lib.
sudo apt-get install gcc
try apt-file. It is difficult to remember the package name where the missing file resides. It is generic and useful for any package files.
For example:
root#ubuntu234:~/auto# apt-file search --regexp '/Python.h$'
pypy-dev: /usr/lib/pypy/include/Python.h
python2.7-dbg: /usr/include/python2.7_d/Python.h
python2.7-dev: /usr/include/python2.7/Python.h
python3.2-dbg: /usr/include/python3.2dmu/Python.h
python3.2-dev: /usr/include/python3.2mu/Python.h
root#ubuntu234:~/auto#
Now you can make an expert guess as to which one to choose from.
This problem can also arrive when you have different Python versions installed and you use a pip that's not the system's one. In that case, the non-system pip won't find the right version of Python headers.
It happened to me when trying to pip install a package for a Python bundled with an application. As it was not system's python, apt install pythonXX-dev didn't work.
In this case, the solution is to find the right python header:
find / -iname 'Python.h'
In the output, you will see system python headers, and hopefully the one you are looking for, for example:
/usr/include/python3.7m/Python.h
/usr/include/python3.6m/Python.h
/home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.8.5-h7579374_1/include/python3.8/Python.h
/home/ubuntu/miniconda3/pkgs/python-3.7.0-h6e4f718_3/include/python3.7m/Python.h
/home/ubuntu/miniconda3/include/python3.8/Python.h
/home/ubuntu/miniconda3/envs/sim/include/python3.7m/Python.h
/home/ubuntu/src/blender-deps/Python-3.7.7/Include/Python.h
/opt/lib/python-3.7.7/include/python3.7m/Python.h
Then, you can set a compiler flag that will get used by gcc when called by pip.
Mine was /home/ubuntu/workspace/blender-git/lib/linux_centos7_x86_64/python/include/python3.7m/Python.h, so I did:
export CPPFLAGS=-I/home/ubuntu/src/blender-deps/Python-3.7.7/Include
pip install <package>
For CentOS 7:
sudo yum install python36u-devel
I followed the instructions here for installing python3.6 on several VMs: https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-centos-7
and was then able to build mod_wsgi and get it working with a python3.6 virtualenv
For the OpenSuse comrades out there:
sudo zypper install python3-devel
Here is yet another solution, because none of these solutions worked for me. For reference, I was trying to pip install something on an Amazon Linux AMI base Docker image for Python 3.6.
Non-docker solution:
# Install python3-devel like everyone says
yum -y install python36-devel.x86_64
# Find the install directory of `Python.h`
rpm -ql python36-devel.x86_64 | grep -i "Python.h"
# Forcefully add it to your include path
C_INCLUDE_PATH='/usr/include/python3.6m'
export C_INCLUDE_PATH
Docker solution:
# Install python3-devel like everyone says
RUN yum -y install python36-devel.x86_64
# Find the install directory of `Python.h`, for me it was /usr/include/python3.6m
RUN rpm -ql python36-devel.x86_64 | grep -i "Python.h" && fake_command_so_docker_fails_and_shows_us_the_output
# Since the previous command contains a purposeful error, remove it before the next run
# Forcefully add it to your include path
ARG C_INCLUDE_PATH='/usr/include/python3.6m'
NOTE: If you're getting the error when compiling C++, use CPLUS_INCLUDE_PATH.
Alternatively, you may prefer to use another Docker image. For example, I was trying to install asyncpg~=0.24.0 on python:3.9.4-slim, which generated the same error as you saw. However, when I updated the image to python:3, it worked fine.
If you're using Python 3.6 on Amazon Linux (based on RHEL, but the RHEL answers given here didn't work):
sudo yum install python36-devel
You must install the Python development files on your operating system if the Python provided with your operating system does not come with them. The many answers on this question show the myriad ways this can be achieved on different systems.
When you have done so, the problem is telling the compiler where they're located and how to compile against them. Python comes with a program called python-config. For compilation, you need the --includes output and for linking a program against the Python library (embedding Python into your program) the --ldflags output. Example:
gcc -c mypythonprogram.c $(python3-config --includes)
gcc -o program mypythonprogram.o $(python3-config --ldflags)
The python-config program can be named after the Python versions - on Debian, Ubuntu for example these can be named python3-config or python3.6-config.
Sure python-dev or libpython-all-dev are the first thing to (apt )install, but if that doesn't help as was my case, I advice you to install the foreign Function Interface packages by sudo apt-get install libffi-dev and sudo pip install cffi.
This should help out especially if you see the error as/from c/_cffi_backend.c:2:20: fatal error: Python.h: No such file or directory.
try locate your Python.h:
gemfield#ThinkPad-X1C:~$ locate Python.h
/home/gemfield/anaconda3/include/python3.7m/Python.h
/home/gemfield/anaconda3/pkgs/python-3.7.6-h0371630_2/include/python3.7m/Python.h
/usr/include/python3.8/Python.h
if not found, then install python-dev or python3-dev; else include the correct header path for compiler:
g++ -I/usr/include/python3.8 ...
I am on Ubuntu. I have installed all packages as was recommended in some answers.
sudo apt-get install python-dev # for python2.x installs
sudo apt-get install python3-dev # for python3.x installs
I still had this problem, the line:
#include "Python.h"
And some others, I can edit them manually, it is a bad practice.
I know the secret now, it comes from the cython source code. I have the file. It compiles without errors. That is the file.
Change PYTHON to python version you have, python/python3. Change FILE to your c-filename. The name of the makefile file should be Makefile. Run the the file with the command:
make all
Makefile for creating our standalone Cython program
FILE := file.c
PYTHON := python3
PYVERSION := $(shell $(PYTHON) -c "import sys;
print(sys.version[:3])")
PYPREFIX := $(shell $(PYTHON) -c "import sys; print(sys.prefix)")
INCDIR := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_python_inc())")
PLATINCDIR := $(shell $(PYTHON) -c "from distutils import
sysconfig; print(sysconfig.get_python_inc(plat_specific=True))")
LIBDIR1 := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBDIR'))")
LIBDIR2 := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBPL'))")
PYLIB := $(shell $(PYTHON) -c "from distutils import sysconfig;
print(sysconfig.get_config_var('LIBRARY')[3:-2])")
CC := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('CC'))")
LINKCC := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LINKCC'))")
LINKFORSHARED := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LINKFORSHARED'))")
LIBS := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('LIBS'))")
SYSLIBS := $(shell $(PYTHON) -c "import distutils.sysconfig;
print(distutils.sysconfig.get_config_var('SYSLIBS'))")
.PHONY: paths all clean test
paths:
#echo "PYTHON=$(PYTHON)"
#echo "PYVERSION=$(PYVERSION)"
#echo "PYPREFIX=$(PYPREFIX)"
#echo "INCDIR=$(INCDIR)"
#echo "PLATINCDIR=$(PLATINCDIR)"
#echo "LIBDIR1=$(LIBDIR1)"
#echo "LIBDIR2=$(LIBDIR2)"
#echo "PYLIB=$(PYLIB)"
#echo "CC=$(CC)"
#echo "LINKCC=$(LINKCC)"
#echo "LINKFORSHARED=$(LINKFORSHARED)"
#echo "LIBS=$(LIBS)"
#echo "SYSLIBS=$(SYSLIBS)"
$(FILE:.c=): $(FILE:.c=.o)
$(LINKCC) -o $# $^ -L$(LIBDIR1) -L$(LIBDIR2) -l$(PYLIB)
$(LIBS) $(SYSLIBS) $(LINKFORSHARED)
$(FILE:.c=.o): $(FILE)
$(CC) -c $^ -I$(INCDIR) -I$(PLATINCDIR)
all: $(FILE:.c=)
This error occurred when I attempted to install ctds on CentOS 7 with Python3.6. I did all the tricks mentioned here including yum install python34-devel. The problem was Python.h was found in /usr/include/python3.4m but not in /usr/include/python3.6m. I tried to use --global-option to point to include dir (pip3.6 install --global-option=build_ext --global-option="--include-dirs=/usr/include/python3.4m" ctds). This resulted in a lpython3.6m not found when linking ctds.
Finally what worked was fixing the development environment for Python3.6 needs to correct with the include and libs.
yum -y install https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/python36u-libs-3.6.3-1.ius.centos7.x86_64.rpm
Python.h needs to be in your include path for gcc. Whichever version of python is used, for example if it's 3.6, then it should be in /usr/include/python3.6m/Python.h typically.
Sometimes even after installing python-dev the error persists,
Check for the error if it is 'gcc' missing.
First download as stated in https://stackoverflow.com/a/21530768/8687063, then install gcc
For apt (Ubuntu, Debian...):
sudo apt-get install gcc
For yum (CentOS, RHEL...):
sudo yum install gcc
For dnf (Fedora...):
sudo dnf install gcc
For zypper (openSUSE...):
sudo zypper in gcc
For apk (Alpine...):
sudo apk gcc
It often appear when you trying to remove python3.5 and install python3.6.
So when using python3 (which python3 -V => python3.6) to install some packages required python3.5 header will appear this error.
Resolve by install python3.6-dev module.
This means that Python.h isn't in your compiler's default include paths. Have you installed it system-wide or locally? What's your OS?
You could use the -I<path> flag to specify an additional directory where your compiler should look for headers. You will probably have to follow up with -L<path> so that gcc can find the library you'll be linking with using -l<name>.

flask-mysqldb support for Python 3.6? [duplicate]

I am trying to get a Python script to run on the linux server I'm connected to via ssh. The script uses mysqldb. I have all the other components I need, but when I try to install mySQLdb via setuptools like so:,
python setup.py install
I get the following error report related to the mysql_config command.
sh: mysql_config: command not found
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Has anyone else encountered this error and if so how did you resolve it/what can I do to successfully install mysqldb?
mySQLdb is a python interface for mysql, but it is not mysql itself. And apparently mySQLdb needs the command 'mysql_config', so you need to install that first.
Can you confirm that you did or did not install mysql itself, by running "mysql" from the shell? That should give you a response other than "mysql: command not found".
Which linux distribution are you using? Mysql is pre-packaged for most linux distributions. For example, for debian / ubuntu, installing mysql is as easy as
sudo apt-get install mysql-server
mysql-config is in a different package, which can be installed from (again, assuming debian / ubuntu):
sudo apt-get install libmysqlclient-dev
if you are using mariadb, the drop in replacement for mysql, then run
sudo apt-get install libmariadbclient-dev
Reference:
https://github.com/JudgeGirl/Judge-sender/issues/4#issuecomment-186542797
I was installing python-mysql on Ubuntu 12.04 using
pip install mysql-python
First I had the same problem:
Not Found "mysql_config"
This worked for me
$ sudo apt-get install libmysqlclient-dev
Then I had this problem:
...
_mysql.c:29:20: error fatal: Python.h: No existe el archivo o el directorio
compilación terminada.
error: command 'gcc' failed with exit status 1
Then I tried with
apt-get install python-dev
(If you're using python3, install python3-dev instead.)
And then I was happy :)
pip install mysql-python
Installing collected packages: mysql-python
Running setup.py install for mysql-python
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -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
In file included from _mysql.c:44:0:
/usr/include/mysql/my_config.h:422:0: aviso: se redefinió "HAVE_WCSCOLL" [activado por defecto]
/usr/include/python2.7/pyconfig.h:890:0: nota: esta es la ubicación de la definición previa
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r -lpthread -lz -lm -lrt -ldl -o build/lib.linux-x86_64-2.7/_mysql.so
Successfully installed mysql-python
Cleaning up...
(Specific to Mac OS X)
I have tried a lot of things, but these set of commands finally worked for me.
Install mysql
brew install mysql
brew unlink mysql
brew install mysql-connector-c
Add the mysql bin folder to PATH
export PATH=/usr/local/Cellar/mysql/8.0.11/bin:$PATH
mkdir /usr/local/Cellar/lib/
Create a symlink
sudo ln -s /usr/local/Cellar/mysql/8.0.11/lib/libmysqlclient.21.dylib /usr/local/Cellar/lib/libmysqlclient.21.dylib
brew reinstall openssl (source)
Finally, install mysql-client
LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysqlclient
Update:
In case this doesn't work, #vinyll suggests to run brew link mysql before step 8.
On Red Hat I had to do
sudo yum install mysql-devel gcc gcc-devel python-devel
sudo easy_install mysql-python
Then it worked.
On python 3.5.2 + any future version
sudo apt-get install libmysqlclient-dev python-dev
The below worked for me on Ubuntu 12.04 LTS:
apt-get install libmysqlclient-dev python-dev
All though it worked, i still went ahead to do the below:
export PATH=$PATH:/usr/local/mysql/bin/
I got the same error while trying to install mysql-python.
This is how I fixed it.
sudo PATH=/usr/local/mysql/bin/:$PATH pip install mysql-python
The problem was that the installer could not find the mysql_config in the default path. Now it can ..and it worked..
15 warnings generated.
clang -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.8-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm -lmygcc -o build/lib.macosx-10.8-intel-2.7/_mysql.so -arch x86_64
Successfully installed mysql-python
Cleaning up...
Hope this helps.
Thanks.
I fixed this problem with the following steps:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo python setup.py install
The commands (mysql too) mPATH might be missing.
export PATH=$PATH:/usr/local/mysql/bin/
Step1:-Install Python3 & Python3-dev Both
sudo apt-get install python3 python3-dev
Step2:- Install Python & Mysql Connector
sudo apt-get install libmysqlclient-dev
step3:- Install python mysql client
sudo apt-get install mysqlclient
This will Solve your Problem
The package libmysqlclient-dev is deprecated, so use the below command to fix it.
Package libmysqlclient-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
sudo apt-get install default-libmysqlclient-dev
I think the most convenient way to solve this problem in 2020 is using another python package. We don't need install any other binary software.
Try this
pip install mysql-connector-python
and then
import mysql.connector
mydb = mysql.connector.connect(
host="",
user="",
passwd="",
database=""
)
cursor = mydb.cursor( buffered=True)
cursor.execute('show tables;')
cursor.execute('insert into test values (null, "a",10)')
mydb.commit()
mydb.disconnect()
If you're on macOS and already installed mysql#5.7 via brew install:
brew install mysql-connector-c
brew unlink mysql#5.7
brew link --overwrite --dry-run mysql#5.7 first, to see what symlinks are getting overwritten
brew link --overwrite --force mysql#5.7 to actually overwrite mysql-related symlinks with mysql#5.7
pip install mysqlclient
I fixed it by installing libmysqlclient:
sudo apt-get install libmysqlclient16-dev
In centos 7 this works for me :
yum install mariadb-devel
pip install mysqlclient
The MySQL-python package is using the mysql_config command to learn about the mysql configuration on your host. Your host does not have the mysql_config command.
The MySQL development libraries package (MySQL-devel-xxx) from dev.mysql.com provides this command and the libraries needed by the MySQL-python package. The MySQL-devel packages are found in the download - community server area. The MySQL development library package names start with MySQL-devel and vary based MySQL version and linux platform (e.g. MySQL-devel-5.5.24-1.linux2.6.x86_64.rpm.)
Note that you do not need to install mysql server.
For Alpine Linux:
$ apk add mariadb-dev mariadb-client mariadb-libs
MariaDB is a drop-in replacement for MySQL and became the new standard as of Alpine 3.2. See https://bugs.alpinelinux.org/issues/4264
On my Fedora 23 machine I had to run the following:
sudo dnf install mysql-devel
In CentOS 7 , the following things should be done:
#step1:install mysql
https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
#step2:
sudo yum install mysql-devel
or
sudo yum install mysql-community-devel
I think, following lines can be executed on terminal
sudo ln -s /usr/local/zend/mysql/bin/mysql_config /usr/sbin/
This mysql_config directory is for zend server on MacOSx. You can do it for linux like following lines
sudo ln -s /usr/local/mysql/bin/mysql_config /usr/sbin/
This is default linux mysql directory.
I had this issues and solved if by adding a symlink to mysql_config.
I had installed mysql with homebrew and saw this in the output.
Error: The `brew link` step did not complete successfully
Depending on how you got mysql it will be in different places. In my case /usr/local/Cellar/mysql
Once you know where it is you should be able to ma a symbolic link to where python is looking for it. /usr/local/mysql
This worked for me.
ln -s /usr/local/Cellar/mysql/<< VERSION >>/bin/mysql_config /usr/local/mysql/bin/mysql_config
I had the same problem. I solved it by following this tutorial to install Python with python3-dev on Ubuntu 16.04:
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y python3-pip
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev
And now you can set up your virtual environment:
sudo apt-get install -y python3-venv
pyvenv my_env
source my_env/bin/activate
also, i fetch the same problem
I fixed this problem with the following steps:
First I run this command
sudo apt-get install libmysqlclient-dev
then I install
pip install mysqlclient==2.1.0
this is worked for me
You need to install the python-dev package:
sudo apt-get install python-dev
sudo apt-get install python-mysqldb
Python 2.5? Sounds like you are using a very old version of Ubuntu Server (Hardy 8.04?) - please confirm which Linux version the server uses.
python-mysql search on ubuntu package database
Some additional info:
From the README of mysql-python -
Red Hat Linux
.............
MySQL-python is pre-packaged in Red Hat Linux 7.x and newer. This
includes Fedora Core and Red Hat Enterprise Linux. You can also
build your own RPM packages as described above.
Debian GNU/Linux
................
Packaged as python-mysqldb_::
# apt-get install python-mysqldb
Or use Synaptic.
.. _python-mysqldb: http://packages.debian.org/python-mysqldb
Ubuntu
......
Same as with Debian.
Footnote: If you really are using a server distribution older than Ubuntu 10.04 then you are out of official support, and should upgrade sooner rather than later.
This method is only for those who know that Mysql is installed but still mysql_config can't be find. This happens if python install can't find mysql_config in your system path, which mostly happens if you have done the installation via .dmg Mac Package or installed at some custom path. The easiest and documented way by MySqlDB is to change the site.cfg. Find the mysql_config which is probably in /usr/local/mysql/bin/ and change the variable namely mysql_config just like below and run the installation again. Don't forget to un-comment it by removing "#"
Change below line
"#mysql_config = /usr/local/bin/mysql_config"
to
"mysql_config = /usr/local/mysql/bin/mysql_config"
depending upon the path in your system.
By the way I used python install after changing the site.cfg
sudo /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python setup.py install
So far, all solutions (Linux) require sudo or root rights to install .
Here is a solution if you do not have root rights and without sudo. (no sudo apt install ...):
Download the .deb file of the libmysqlclient-dev, e.g. from this mirror
Navigate to the downloaded file and run dpkg -x libmysqlclient-dev_<version tag>.deb . This will extract a folder called usr.
Symlink ./usr/bin/mysql_config to somewhere that is found on your $PATH:
ln -s `pwd` /usr/bin/mysql_config FOLDER_IN_YOUR_PATH
It should now be able to find mysql_config
Tested on Ubuntu 18.04.
For macOS Mojave , additional configuration was required, for compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
I encountered the same problem, just added the path where *mysql_config* resided to the environment variable PATH and it worked for me.
sudo apt-get build-dep python-mysqldb will install all the dependencies to build the package from PIP/easy_install

How to install `build-essential` in `Cygwin`?

How to install build-essential in Cygwin?
I've tried using: apt-cyg install build-essential
But does not work.
Installing build-essential
Package build-essential not found or ambiguous name, exiting
I'm also having problems like:
(gedit: 13864): Gtk-WARNING **: can not open display:
So I can not install crunch.
See It:
$ make all
Building binary...
/usr/bin/gcc -pthread -Wall -pedantic -std=c99 undefined crunch.c -lm -o crunch
gcc: error: undefined: No such file or directory
Makefile:48: recipe for target 'crunch' failed
make: *** [crunch] Error 1
What's the problem here, and how can I fix it?
There isn't a build-essential package in Cygwin.
Build-essential is a collection of packages. So you'll have to select the packages manually, which I believe are the following:
make
automake
gcc
gcc-c++
Assuming you're doing development, you'll want to select those packages from the Devel branch. This is done when you first install Cygwin and the installer asks you to select the packages, after choosing the download site from the list.
As for the Gtk-WARNING **: can not open display: error, this is because your system is not running Cygwin's X11 display server, which provides a surface for graphical applications to render to. Check out http://x.cygwin.com/.
If you want to run gedit in Windows, you should get the binary for windows here. That's built for Windows and doesn't need Cygwin.
EDIT: Running sudo apt-get install build-essential on Elementary OS Freya mentions the following dependencies will be installed as well, so you'll probably want that for a 'closer-to-Linux' build environment as well.
The following extra packages will be installed:
g++
g++-4.8
libstdc++-4.8-dev
Suggested packages:
g++-multilib
g++-4.8-multilib
gcc-4.8-doc
libstdc++6-4.8-dbg
libstdc++-4.8-doc
The following NEW packages will be installed:
build-essential
g++
g++-4.8
libstdc++-4.8-dev
The list of files installed can be found here
and the contents of the file list (current as of 4/24/2014) can be found in this PasteBin I made.
build-essential is an abstract package, short for its dependencies:
dpkg-dev
binutils
bzip2
libdpkg-perl
make
patch
perl
tar
xz-utils
g++
gcc
libc6-dev
make
So in Cygwin, it is the same to install their substitutes:
apt-cyg install make gcc-core gcc-g++ patch bzip2 perl tar xz
make and gcc-g++ (g++), which depends on gcc-core (gcc), are the most important.
If you really want to compile various projects in Cygwin, packages below may be also helpful. Be careful, libboost-devel is very large.
apt-cyg install git automake cmake python3-devel libboost-devel

Resources