V
V
vlarkanov2018-08-30 12:44:33
linux
vlarkanov, 2018-08-30 12:44:33

PyCharm: how to load mysql.connector module?

Hello! You need to connect to a MySQL database.
In PyCharm, when I try to execute import mysql.connector, I get:


File "/home/user/PycharmProjects/dartshire/venv/main.py", line 6, in
import mysql
ImportError: No module named 'mysql'

Moreover, if you run Python in the console on behalf of the same user and execute import mysql.connector - there are no errors:

$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>

What could be the problem and how to win?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Alekseev, 2018-08-30
@Zatmil

Since main.py is run inside venv (I guess), mysql might not be there. You need to install it inside venv:

>>> source venv/bin/activate 
>>> pip install mysql

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question