Problem installing flask-mysqldb on linux 16.04

1

I was trying to install the flask-mysqldb on my Linux 16.04 device but I found a problem, even with a virtual environment: _mysql.c: 32: 20: error fatal: Python.h: No existe ese archivo o directorio .

(myFlaskAppenv) mike@mike-thinks:~/Programing/Rasa/myflaskapp$ python -m  pip install flask-mysqldb
Collecting flask-mysqldb
  Using cached https://files.pythonhosted.org/packages/62/e3/955c845efe1aacf30c8e2607470544ede36aa1044f6382c809f13e014104/Flask-MySQLdb-0.2.0.tar.gz
Requirement already satisfied: Flask>=0.10 in ./myFlaskAppenv/lib/python3.5/site-packages (from flask-mysqldb) (1.0.2)
Collecting mysqlclient (from flask-mysqldb)
  Using cached https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.tar.gz
Requirement already satisfied: itsdangerous>=0.24 in ./myFlaskAppenv/lib/python3.5/site-packages (from Flask>=0.10->flask-mysqldb) (0.24)
Requirement already satisfied: Jinja2>=2.10 in ./myFlaskAppenv/lib/python3.5/site-packages (from Flask>=0.10->flask-mysqldb) (2.10)
Requirement already satisfied: Werkzeug>=0.14 in ./myFlaskAppenv/lib/python3.5/site-packages (from Flask>=0.10->flask-mysqldb) (0.14.1)
Requirement already satisfied: click>=5.1 in ./myFlaskAppenv/lib/python3.5/site-packages (from Flask>=0.10->flask-mysqldb) (6.7)
Requirement already satisfied: MarkupSafe>=0.23 in ./myFlaskAppenv/lib/python3.5/site-packages (from Jinja2>=2.10->Flask>=0.10->flask-mysqldb) (1.0)
Installing collected packages: mysqlclient, flask-mysqldb
  Running setup.py install for mysqlclient ... error
    Complete output from command /home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-rpj3mj09/mysqlclient/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-r7zvujiv/install-record.txt --single-version-externally-managed --compile --install-headers /home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/include/site/python3.5/mysqlclient:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.5
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.5
    creating build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.5/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.5/MySQLdb
    creating build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.5/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-x86_64-3.5
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/include/mysql -I/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/include -I/usr/include/python3.5m -c _mysql.c -o build/temp.linux-x86_64-3.5/_mysql.o
    _mysql.c:32:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

    ----------------------------------------
Command "/home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-rpj3mj09/mysqlclient/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-r7zvujiv/install-record.txt --single-version-externally-managed --compile --install-headers /home/mike/Programing/Rasa/myflaskapp/myFlaskAppenv/include/site/python3.5/mysqlclient" failed with error code 1 in /tmp/pip-install-rpj3mj09/mysqlclient/

What can I do then to install it?

I have python3:

(myFlaskAppenv) mike@mike-thinks:~/Programing/Rasa/myflaskapp$ python3 -V
Python 3.5.2
    
asked by ThePassenger 02.06.2018 в 14:48
source

1 answer

0

Compiling modules written in C using the Python API / C requires a set of header files and static libraries, being essential the header file Ptyhon.h ( #include "Python.h" ), which includes all the function definitions, types and macros necessary to use the API.

The error in this case is due to the fact that the compiler of C (gnu-gcc) is not able to find Python.h in the compilation process of _mysql.c . The path specified in the Makefile is /usr/include/python3.5m in this case, the path where the header file can not be found.

There are times when this happens because despite having the header files, they are located in a different directory than the one specified in the include of the Makefile , for example /usr/local/include/python3.5m , in these cases we can solve it in a simple way creating a link.

In this particular case, what surely happens is that the python3-dev

answered by 02.06.2018 / 18:21
source