在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Python  網(wǎng)絡(luò)安全/ python 在venv中報錯 ModuleNotFoundError: No

python 在venv中報錯 ModuleNotFoundError: No module named 'MySQLdb'

環(huán)境

Win7,Python 3.6.5,

情況

腳本中有import MySQLdb 直接執(zhí)行可以執(zhí)行,但是在創(chuàng)建的venv 中執(zhí)行,執(zhí)行失敗提示ModuleNotFoundError: No module named 'MySQLdb'。運行pip install MySQLdb 報錯提示:


(prod) D:\mysite\crawler>python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Inte
l)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

(prod) D:\mysite\crawler>python parse_content.py
Traceback (most recent call last):
  File "parse_content.py", line 3, in <module>
    from model import article as article_model, \
  File "D:\mysite\crawler\model\__init__.py", line 3, in <module>
    import MySQLdb
ModuleNotFoundError: No module named 'MySQLdb'


(prod) D:\mysite\crawler>pip install MySQLdb
Collecting MySQLdb
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
 after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.or
g', port=443): Read timed out. (read timeout=15)",)': /simple/mysqldb/
  Could not find a version that satisfies the requirement MySQLdb (from versions
: )
No matching distribution found for MySQLdb



(prod) D:\mysite\crawler>pip search mysqldb
mysqldb-rich (2.4)     - rich mysqldb
Flask-MySQLdb (0.2.0)  - MySQLdb extension for Flask
lurker (0.1)           - a tiny wrapper for mysqldb
mysqldbhelper (1.0.2)  - A simple wrapper over mysqldb
umysqldb (1.0.3)       - MySQLdb compatible wrapper for ultramysql
tomdb (0.5.1)          - A simple wrapper around MySQLdb and pymysql.
mandb (0.1.4)          - Mandb is a lightweight wrapper around MySQLdb and
                         sqlite3.
sqlShort (0.3)         - A tiny wrapper for the Python modules MySQLdb and
                         Sqlite
sqlwitch (0.2)         - sqlwitch offers idiomatic SQL generation on top of
                         MySQLdb.
simplemysql (1.25)     - An ultra simple wrapper for Python MySQLdb with very
                         basic functionality
torndb (0.3)           - A lightweight wrapper around MySQLdb.  Originally
                         part of the Tornado framework.
mysql_helper (1.0.0)   - Um módulo para auxiliar opera??es com o MySQL e
                         MySQLdb

(prod) D:\mysite\crawler>

為何退出這個venv,執(zhí)行pip install MySQLdb 卻又可以了

回答
編輯回答
誮惜顏

如果你報的錯是這個

 Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None))
 after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.or
g', port=443): Read timed out. (read timeout=15)",)': /simple/mysqldb/
  Could not find a version that satisfies the requirement MySQLdb (from versions
: )

你可以嘗試加大超時時間

pip --default-timeout=100 install MySQLdb

個人建議換源(清華),速度也會加快

pip install --index https://mirrors.ustc.edu.cn/pypi/web/simple/ virtualenv 
2018年8月23日 01:46
編輯回答
哚蕾咪

包名稱錯了。

在可以導入 MySQLdb 的環(huán)境中,通過 MySQLdb.__file__ 屬性可查出包名。

一般使用 pip install mysqlclient 安裝該模塊,而 windows 系統(tǒng)一般下載二進制安裝文件,省去編譯過程。

請參考 https://github.com/PyMySQL/my...

2018年3月18日 10:07