我正在尝试通过Python访问MySql数据库,从centos ec2实例开始,Python从2.6升级到2.7。它不起作用,因为我的 gcc 编译器找不到 python 头文件。 which python
返回 /usr/bin/python
,which gcc
返回 /usr/bin/gcc
。
以下是我尝试过的。
感谢a comment by @romuloigor,聊天/评论中的讨论 this question和 this question对于丢失的文件Python.h
,我的方法如下:
sudo yum install mysql mysql-devel mysql-libs
sudo yum install python-devel
sudo yum install MySQL-python
sudo pip install mysql-python
我认为如果你已经升级了你的Python(比如,从2.6到2.7),这还无法工作。您需要通过在 python- 之后执行以下操作,将
已安装,但在 pip 安装 Python.h
头文件的路径放置为可通过 gcc
搜索的路径(请参阅 this question 和 this other one ) develmysql-python
之前:
find / -name Python.h 2>/dev/null # find path
我的位于/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
请注意,您不能使用gcc -I
选项,因为我们无法访问gcc正在编译的c源文件,因为它是pip安装,并且所有文件都是临时的。
现在,这仍然不起作用。你会如何告诉 gcc 找到头文件?
PS。我认为这个问题应该放在 stackoverflow 上,因为常见问题解答指出“软件开发工具”并且建议使用标签;如果您有不同的想法,欢迎指正!最佳答案
啊哈!
这是因为我在系统 python2.6 旁边安装了 python2.7 (在 this great page 之后)。我必须小心,我引用了正确的 python ( see this ) 和 from this我发现了我的问题:需要 python27-devel
而不是 python-devel
。啊,无知。
这是我运行的最后一件事。
sudo yum install mysql mysql-devel mysql-libs
sudo yum install python27-devel
sudo yum install MySQL-python
sudo pip install mysql-python
关于python - 如何使用升级的 python 在 ec2 centos 机器上获取 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26044935/