简体   繁体   中英

import MySQLdb报错ImportError: cannot import name '_mysql' from 'MySQLdb' (D:\python\lib\site-packages\MySQLdb\__init__.py)

win10 python3.7.3 Installed mysqlclient1.4.2

When I import mysqlclient, I get an error message when I run the code. When I installed mysqlclient, I changed 'mysqlclient-1.4.2-cp37-cp37m-win_amd64.whl' to 'mysqlclient-1.4.2-py37-none-any.whl', because only then can I install it in windows. Mysqlclient My English is not good, but I really hope to get help., thank you all.

C:\Users\22938>pip list

astroid           2.2.5
colorama          0.4.1
Django            2.2.1
isort             4.3.17
lazy-object-proxy 1.3.1
mccabe            0.6.1
mysqlclient       1.4.2
pip               19.1
pygame            1.9.6
pylint            2.3.1
PyMySQL           0.9.3
pytz              2019.1
setuptools        40.6.2
six               1.12.0
sqlparse          0.3.0
typed-ast         1.3.1
wrapt             1.11.1

>>> import MySQLdb

Traceback (most recent call last): File "", line 1, in File "D:\\python\\lib\\site-packages\\MySQLdb__init__.py", line 18, in from . import _mysql ImportError: cannot import name '_mysql' from 'MySQLdb' (D:\\python\\lib\\site-packages\\MySQLdb__init__.py)

I tried to install pymysql, I added the following code to the program.

>>> import pymysql
>>> pymysql.install_as_MySQLdb()
>>> import MySQLdb
>>> MySQLdb.__version__
'0.9.3'

Is this correct? Does it support python3?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question importerror: cannot import name 'dump' from 'dump' (~/.local/lib/python3.8/site-packages/dump/__init__.py) ImportError: cannot import name 'Deconvolution3D' from 'keras.layers' (/home/mona/venv/fall/lib/python3.8/site-packages/keras/layers/__init__.py) ImportError: cannot import name 'CypherError' from 'neo4j.v1' (/usr/local/lib/python3.7/site-packages/neo4j/v1/__init__.py) ImportError: cannot import name 'post' from 'request' (C:\Program Files\Python37\lib\site-packages\request\__init__.py) Django2.1.7 ImportError: cannot import name 'util' from 'django.forms' (/Users/lib/python3.7/site-packages/django/forms/__init__.py) Error: from matplotlib import _png ImportError: cannot import name '_png' from 'matplotlib' (C:\\Garden\lib\site-packages\matplotlib\__init__.py) ImportError: cannot import name 'TwitterRestPager' from 'TwitterAPI' (C:\Users\My name \Anaconda3\lib\site-packages\TwitterAPI\__init__.py) ImportError: cannot import name 'set_random_seed' from 'tensorflow' (C:\Users\polon\Anaconda3\lib\site-packages\tensorflow\__init__.py) ImportError: cannot import name 'logsumexp' from 'scipy.misc' (C:\Users\firstname.lastname\Anaconda3\lib\site-packages\scipy\misc\__init__.py) ImportError: cannot import name '_message' from 'google.protobuf.pyext' (c:\programdata\anaconda3\lib\site-packages\google\protobuf\pyext\__init__.py)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM