Install mysql-python return error in CentOs

前端 未结 6 812
我寻月下人不归
我寻月下人不归 2021-02-05 16:06

I want to run a django project on CentOs. I tried to install mysql-python by easy_install and pip but I got error with both of them. I Googled the problem and found some suggest

相关标签:
6条回答
  • 2021-02-05 16:35

    Just to mention for the others that might end up here too,

    After installing python-devel, I had the very same error but with mysql_config.h missing I solved this error in installing mysql-devel

    $ yum install mysql-devel.x86_64 
    

    Hope this helps

    0 讨论(0)
  • 2021-02-05 16:37

    I think you need to install the python development libraries first:

    yum install python-devel
    
    0 讨论(0)
  • 2021-02-05 16:38

    I had the same error, but for different reasons (pypy + virtualenv).

    Here is the error I got:

    Installing collected packages: mysql-python
      Found existing installation: MySQL-python 1.2.4
        Uninstalling MySQL-python:
          Successfully uninstalled MySQL-python
      Running setup.py install for mysql-python
        building '_mysql' extension
        cc -O2 -fPIC -Wimplicit -Dversion_info=(1,2,4,'final',1) -D__version__=1.2.4 -I/usr/include/mysql -I/mnt/hgfs/Work/devel-centos/include -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -DUNIV_LINUX -DUNIV_LINUX
    
    _mysql.c:29:20: error: Python.h: No such file or directory
    

    Please note that the include_dir is -I/mnt/hgfs/Work/devel-centos/include (that's $VIRTUAL_ENV/include), and there is nothing at that location.

    My setup:

    • CentOS 6.4
    • pypy 2.0.2 installed (that's python 2.7.3)
    • virtualenv 1.10.1 installed and created my environment with

      virtualenv -p /usr/bin/pypy devel-centos

    • python 2.6 is installed

      yum install python-devel did not solve the problem for me; it created /usr/lib64/python2.6/ which isn't used during the pip install mysql-python step.

    2 ways to solve the problem:

    1. symlink the correct python header files to your virtualenv:

      yum install pypy-devel  # which creates /usr/lib64/pypy-2.0.2/
      ln -s /usr/lib64/pypy-2.0.2/include $VIRTUAL_ENV/include
      
    2. or change the setup.cfg file for mysql-python

      pip install --no-install mysql-python
      

      then edit $VIRTUAL_ENV/build/mysql-python/setup.cfg

      [build_ext]
      include_dirs = /usr/lib64/pypy-2.0.2/include
      

      and proceed with the installation.

      pip install --no-download mysql-python
      
    0 讨论(0)
  • 2021-02-05 16:39

    I found a similiar solution:

    yum -y install python-devel mysql-devel
    
    0 讨论(0)
  • 2021-02-05 16:49

    Another way around this is yum install python27-MySQL-python.x86_64.

    0 讨论(0)
  • 2021-02-05 16:51

    Same issue; Python.h not found, Found that python-virtualenv was not installed;

    yum -y install python-virtualenv
    
    0 讨论(0)
提交回复
热议问题