问题
i have problem to try pymysql.
- my computer is using windows 10
- use python 3.5
- i have installed pymysql via
pip install pymsqland success, no error. i have checked withpip listand getPyMySQL (0.7.9)
but when i run import PyMySQL get error no module named "PyMySQL" where is the problem?
edited :
but if i try import pymysql, i got error :
Traceback (most recent call last):
File "pymysql1.py", line 1, in <module>
import pymysql
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pymysql\__init__.py", line 29, in <module>
from .err import (
File "C:\Program Files (x86)\Python35-32\lib\site-packages\pymysql\err.py", line 1, in <module>
import struct
File "C:\python\struct.py", line 2, in <module>
pack('hhl', 1, 2, 3)
NameError: name 'pack' is not defined
回答1:
step-1 :Uninstall the existing pymysql by using the command
pip uninstall PyMySQL
step-2 : Install the pymysql by using the command pip3
pip3 install PyMySQL
step-3: import pymysql
This should work. I am using python3.4 in windows 8 when I tried to import pymysql using the command import PyMySQL it didn't work, but after performing the above steps then I tried import pymysql then it worked perfectly.
回答2:
The name of the import doesn't need to be the same as the project. Use:
import pymysql
See: https://github.com/PyMySQL/PyMySQL/blob/master/example.py
Also, you can't use any python if I understand correctly. The requirements posted https://github.com/PyMySQL/PyMySQL#installation:
Requirements Python -- one of the following:
CPython >= 2.6 or >= 3.3PyPy >= 4.0
IronPython 2.7
MySQL Server -- one of the following:
MySQL> >= 4.1 (tested with only 5.5~)
MariaDB >= 5.1
回答3:
If even sudo apt-get install python3-pymysql or pip3 install pymysql does not work for you then go to PyMySQL page.https://github.com/PyMySQL/PyMySQL, download the zip file,extract it, cd to that location and type python setup.py install. This worked like a charm for me.
来源:https://stackoverflow.com/questions/40280762/error-no-module-named-pymysql-windows-10