gpt4 book ai didi

python - 在 Centos 上安装 mysql-python

转载 作者:IT老高 更新时间:2023-10-28 21:05:53 26 4
gpt4 key购买 nike

我正在尝试在 centos 5.5 上安装 MySQL-python 库。我跑了

sudo yum install MySQL-python

但是当我尝试时:

import MySQLdb

我收到此错误:

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "MySQLdb/__init__.py", line 22, in ?
raise ImportError("this is MySQLdb version %s, but _mysql is version %r" %
ImportError: this is MySQLdb version (1, 2, 3, 'final', 0), \ # added linebreak
but _mysql is version (1, 2, 1, 'final', 1)

关于如何解决这个问题的任何线索?

最佳答案

第 1 步 - 安装包

# yum install MySQL-python
Loaded plugins: auto-update-debuginfo, langpacks, presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package MySQL-python.i686 0:1.2.3-3.fc15 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
MySQL-python i686 1.2.3-3.fc15 fedora 78 k

Transaction Summary
================================================================================
Install 1 Package(s)

Total download size: 78 k
Installed size: 220 k
Is this ok [y/N]: y
Downloading Packages:
Setting up and reading Presto delta metadata
Processing delta metadata
Package(s) data still to download: 78 k
MySQL-python-1.2.3-3.fc15.i686.rpm | 78 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : MySQL-python-1.2.3-3.fc15.i686 1/1

Installed:
MySQL-python.i686 0:1.2.3-3.fc15

Complete!

第 2 步 - 测试工作

import MySQLdb
db = MySQLdb.connect("localhost","myusername","mypassword","mydb" )
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print "Database version : %s " % data
db.close()

输出:

Database version : 5.5.20 

关于python - 在 Centos 上安装 mysql-python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380931/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com