2014-05-20 155 views
3

我有一個CentOS盒子。即使安裝了MySQL-python,沒有名爲MySQLdb的模塊?

(venv)[[email protected]]# yum install MySQL-python 
Loaded plugins: fastestmirror, refresh-packagekit, security 
Loading mirror speeds from cached hostfile 
* base: mirrors.maine.edu 
* epel: ftp.osuosl.org 
* extras: mirror.us.leaseweb.net 
* remi: rpms.famillecollet.com 
* updates: mirrors.centarra.com 
Setting up Install Process 
Package MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 already installed and latest version 
Nothing to do 

...

(venv)[[email protected]]# python 
Python 2.7.6 (default, May 20 2014, 20:23:08) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import MySQLdb 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named MySQLdb 
>>> 

我該怎麼辦?

,當我嘗試pip install mysql-python我得到這個:

Traceback (most recent call last): 
    File "/home/user1/project/venv/bin/pip", line 11, in <module> 
    sys.exit(main()) 
    File "/home/user1/project/venv/lib/python2.7/site-packages/pip/__init__.py", line 185, in main 
    return command.main(cmd_args) 
    File "/home/user1/project/venv/lib/python2.7/site-packages/pip/basecommand.py", line 161, in main 
    text = '\n'.join(complete_log) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 65: ordinal not in range(128) 
+0

也許檢查鏈接的http:/ /stackoverflow.com/questions/4380931/installing-mysql-python-on-centos – Freelancer

+0

@Freelancer但這不是我面臨的問題。 – ComputerFellow

+0

可能與你的venv有關。您是否在系統上創建了venv並加載了需求文件? 當你凍結虛擬環境時,需求列表說明了什麼(pip freeze> requirements.txt) – bcollins

回答

6

您需要強制pip使用默認本地化設置。相反的:

pip install mysql-python 

做:

LC_ALL=C pip install mysql-python 

如果碰上一個error: Python.h: No such file or directory,那麼你就需要安裝額外的庫:

yum install python-devel 
+1

這工作!除了上面的步驟外,我還必須'yum安裝mysql-devel'。 – ComputerFellow

相關問題