简体   繁体   English

在Linux上使用新版本的python安装mysqldb

[英]Installing mysqldb with a new version of python on linux

I have mysqldb installed and it works for python2.4. 我已经安装了mysqldb,它适用于python2.4。 But I've recently installed python2.6 and when I run it I can't import mysqldb. 但是我最近安装了python2.6,当我运行它时,我无法导入mysqldb。 I get the following: 我得到以下内容:

import MySQLdb
ImportError: No module named MySQLdb

I've looked over how to install mysqldb (it's been a few years since I installed it), but can't find anything on how to reinstall or make it work with a new version of python. 我已经研究了如何安装mysqldb(已经安装了几年了),但是找不到有关如何重新安装或使其与新版本的python一起使用的信息。 Any thoughts? 有什么想法吗?

I made some progress by adding a path to my .bashrc file (the first one, whic is where my MySQLdb installation is for python2.4): 我通过向.bashrc文件添加路径取得了一些进展(第一个,这是我的MySQLdb安装用于python2.4的位置):

export PYTHONPATH=/usr/lib64/python2.4/site-packages:/usr/lib/python2.4:/usr/lib/python2.4/site-packages:$PYTHONPATH

so now when I run python2.6 and try import MySQLdb I get 所以现在当我运行python2.6并尝试导入MySQLdb时,我得到了

import MySQLdb 导入MySQLdb

Traceback (most recent call last): 追溯(最近一次通话):

File "", line 1, in 文件“”,第1行,位于

File "/usr/lib64/python2.4/site-packages/MySQLdb/ init .py", line 27, in import _mysql 导入_mysql中的文件“ /usr/lib64/python2.4/site-packages/MySQLdb/ init .py”,第27行

ImportError: /usr/lib64/python2.4/site-packages/_mysql.so: undefined symbol: Py_InitModule4 ImportError:/usr/lib64/python2.4/site-packages/_mysql.so:未定义符号:Py_InitModule4

I don't know what to do about this. 我不知道该怎么办。 Maybe install MySQLdb again with python2.6? 也许再次用python2.6安装MySQLdb? (I've actually tried this and it's hard to install MySQLdb with or without setuptools. I did it once more than a year ago but forgot what I did. My server behind a firewall, so setuptools doesn't work out of the box.) Any ideas? (实际上,我已经尝试过了,无论是否安装setuptools,都很难安装MySQLdb。我一年多以前就这样做了,但忘记了我所做的。我的服务器位于防火墙后面,因此setuptools无法开箱即用。 ) 有任何想法吗?

Which python version is on your path? 您使用的是哪个python版本? You can determine this by typing 您可以通过输入来确定

which python

It should return the location with py26 if it's referencing version 2.6 如果引用的是2.6版,则应返回py26的位置

Then, try 然后,尝试

sudo apt-get install python-mysqldb

This should install the correct version for 2.6 这应该为2.6安装正确的版本

You can also download python-mysqldb directly here 您也可以在这里直接下载python-mysqldb

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM