簡體   English   中英

即使安裝了 MySQL-python 也沒有名為 MySQLdb 的模塊?

[英]No module named MySQLdb even if MySQL-python installed?

我有一個 CentOS 機器。

(venv)[root@localhost]# 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)[root@localhost]# 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)

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

pip install mysql-python

做:

LC_ALL=C pip install mysql-python

如果遇到error: Python.h: No such file or directory ,則需要安裝額外的庫:

yum install python-devel

有時我們需要從外部添加/安裝 git repo,這還沒有發布,但你可以從下面的命令添加

pip install git+https://github.com/PyMySQL/mysqlclient-python.git

pip install mysql-python

yum install python-devel

你可以使用 MySQL-python

對於centos

yum 安裝 MySQL-python

Python 2.7.13 (default, Sep 26 2018, 18:42:22) 
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.

    >> import MySQLdb
    >> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM