I use django with python3. When pip install mysql-python gives the error: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-kgys_quh/mysql-python/ . Tried to do from venv , same

    1 answer 1

    You would put the full log with errors, it would be clearer why it does not work for you.

    There are two ways to use mysql in python.

    Option 1. As they say in all articles

    The fact is that all connectors to the bases must be compiled because of their design features. Of course, if you use pip, it does it for you. However, your system must have header files to compile. You did not specify a system, therefore for debian-based systems including. ubuntu:

     sudo apt-get install python-pip python-dev libmysqlclient-dev 

    Next, you need to repeat the installation via pip

     pip install MySQL-python 

    Option 2. More correct

    The fact is that the maintainers are not fools and they have collected everything for you. Accordingly, you need to install the package from the repository that contains the already compiled mysql-python.

    For debian-based, again, the command is:

     sudo apt-get install python-mysqldb 

    If you have python3, then the package is slightly different:

     sudo apt-get install python3-mysqldb 

    After that you will have a global module for connecting to mysql.

    However, this is not all. If you are using virtualenv (or venv in python3), then you need to create a virtual environment so that it includes global packages. This is done by the virtualenv venv --system-site-packages command (or for python3 python3 -m venv --system-site-packages ). After that, it will include both global packages and those installed directly into the environment. It is not necessary to pip such packages via pip , just like to put them in the requirements file.