无法安装MySQL-Python

3

我想在我的代码中尝试使用sqlalchemy,但是为了使用它,我需要先安装mysql-python。我下载了这个包,但当我尝试运行 {python setup.py install} 时,出现了一个我无法理解的错误。

running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-i686-2.7/MySQLdb
running build_ext
building '_mysql' extension
i686-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-i686-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG
_mysql.c:29:20: fatal error: Python.h: No such file or directory
 compilation terminated. error: command 'i686-linux-gnu-gcc' failed with exit status 1

在执行sudo apt-get install python2.7-dev命令后。
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python2.7-dev : Depends: libpython2.7-dev (= 2.7.4-2ubuntu3.2) but it is not     going to be installed
             Depends: libexpat1-dev but it is not installable
E: Unable to correct problems, you have held broken packages.
3个回答

9

如果是针对Python 3.6版本,您需要安装相应的python3-dev,即:

sudo apt-get install python3.6-dev

3

实际上,我已经尝试过了。这是它给出的错误信息。`正在读取软件包列表... 完成 正在构建依赖关系树
正在读取状态信息... 完成 软件包 python-dev 无法获得,但是有另一个软件包引用了它。 这可能意味着该软件包已丢失、已被淘汰或者 仅在另一个来源中可用。 然而,以下软件包可以替代它: pythonE: 软件包 'python-dev' 没有安装候选项。`
- tlbakh
如果我没有做错什么,Synaptic 会说 python2.7-dev 已经损坏了。这很奇怪。 - tlbakh
哇!我得到的错误看起来不太好。我该怎么办?已将其添加到问题中。 - tlbakh
我尝试了,它显示“0 个升级,0 个新安装,0 个要删除和0 个未升级。” - tlbakh
那么尝试使用Synaptic安装依赖项libpython2.7-devlibexpat1-dev,如果可以的话,接着安装python2.7-dev。你必须解决这些依赖关系,否则无法安装python2.7-dev - David de Kleer
显示剩余6条评论

-1

试一下这个:

sudo apt-get install zlib1g-dev

1
这个库是做什么的?为什么它能解决问题? - Luis Milanese

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接