0

I'm trying to get to a MySql database through python, starting with a centos ec2 instance with python upgraded to 2.7 from 2.6. It's not working because my gcc compiler cannot find a the python header file. which python returns /usr/bin/python, and which gcc returns /usr/bin/gcc.

The following is what I've tried.

Thanks to a comment by @romuloigor, the discussion in chat/comments at this question and this question for the missing file Python.h, my method is the following:

sudo yum install mysql mysql-devel mysql-libs 
sudo yum install python-devel
sudo yum install MySQL-python 
sudo pip install mysql-python

I think if you've upgraded your python (say, from 2.6 to 2.7) this won't yet work. You need to put the path of the Python.h header file searchable by gcc (see this question and this other one) by doing the following after python-devel is installed but before pip installing mysql-python:

find / -name Python.h 2>/dev/null # find path

Mine was at /usr/include/python2.6/Python.h:

C_INCLUDE_PATH=/usr/include/python2.6
sudo su
export C_INCLUDE_PATH
exit
echo $C_INCLUDE_PATH # should look right

Note, you can't use the gcc -I option because we can't access the c source file gcc is compiling because it's a pip install, and all the files are temporary.

Now, this still doesn't work. How would you tell gcc to find the header file?

PS. I think this question should be on stackoverflow because the FAQ states "Software development tools" and SO suggested the tags; please feel free to correct if you think differently!

Community
  • 1
  • 1
ehacinom
  • 8,070
  • 7
  • 43
  • 65

1 Answers1

0

AHA!

It was because I'd installed python2.7 alongside the system python2.6 (following this great page). I had to be careful that I referenced the right python (see this) and from this I discovered my problem: python27-devel instead of python-devel was needed. Ah, ignorance.

Here's the final thing I ran.

sudo yum install mysql mysql-devel mysql-libs 
sudo yum install python27-devel
sudo yum install MySQL-python 
sudo pip install mysql-python
Community
  • 1
  • 1
ehacinom
  • 8,070
  • 7
  • 43
  • 65