PyCharm提示ModuleNotFoundError: No module named 'pymysql'

Beginner python, encountered when connecting mysql prompt pymysql module imports in question, although I window system to address the idea is the same

code show as below:

pymysql Import 
# open the database parameters were as follows: hostname / IP, user name, password, database name
db = pymysql.connect ( "localhost", "root", "888 999", "pythonsql")
# using the cursor () method create a cursor object the cursor
the cursor = db.cursor ()
# use the execute () method executes SQL queries
cursor.execute ( "the SELECT Version ()")
# use fetchone () method to obtain a single data, and print
data = cursor.fetchone ( )
Print ( "Datebase Version:% S" Data%)
# close the connection
db.Close ()

First, you need to install PyMySQL

Run in cmd: pip install PyMySQL

After successful installation restart Pycharm, let Pycharm reload the configuration file, if you still can not connect to the database, you command manually add the path to pip

View pip command path method, and then perform a pip install PyMySQL, the system will prompt you already been installed, and the path is displayed, find the actual path, copy down:

 

 

Right-click on File -> settings, perform the following sequence

Enter the command path pip found in their own

Re-run, the perfect solution.

 

 

Guess you like

Origin www.cnblogs.com/ly-520/p/11015685.html