Archivo de la etiqueta: django

Error al ejecutar al instalar mysql-python con pip – sh: mysql_config: command not found

Instalar mysql-python con pip

Un error común al instalar mysql-python para usar mysql con django puede ser este:

pip install MySQL-python
Downloading/unpacking MySQL-python
  Real name of requirement MySQL-python is MySQL-python
  Downloading MySQL-python-1.2.4.zip (113Kb): 113Kb downloaded
  Running setup.py egg_info for package MySQL-python
    Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
    Extracting in /tmp/tmpT2lFmq
    Now working in /tmp/tmpT2lFmq/distribute-0.6.28
    Building a Distribute egg in /home/build/MySQL-python
    /home/build/MySQL-python/distribute-0.6.28-py2.7.egg
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "", line 14, in 
      File "/home/build/MySQL-python/setup.py", line 18, in 
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz

Extracting in /tmp/tmpT2lFmq

Now working in /tmp/tmpT2lFmq/distribute-0.6.28

Building a Distribute egg in /home/build/MySQL-python

/home/build/MySQL-python/distribute-0.6.28-py2.7.egg

sh: mysql_config: command not found

Traceback (most recent call last):

  File "", line 14, in 

  File "/home/build/MySQL-python/setup.py", line 18, in 

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 25, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))


EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /root/.pip/pip.log

La razón es falta de dependencias, tenemos que instalar el mysql-server y lo más importante para solucionar el error es instalar el paquete libmysqlclient-dev

Lo instalamos con apt:

apt-get install libmysqlclient-dev

También para evitar otros errores con pip necesitamos instalar el paquete de desarrollo de python:

apt-get install python-dev

Luego de eso ya podemos instalar mysql-python:

pip install MySQL-python
Downloading/unpacking MySQL-python
  Running setup.py egg_info for package 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,'final',1) -D__version__=1.2.4 -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: warning: "HAVE_WCSCOLL" redefined [enabled by default]
    /usr/include/python2.7/pyconfig.h:890:0: note: this is the location of the previous definition
    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...