1

I've used venv to create a virtual environment for Python 3.5.2. I have installed the mysql.connector. The connector works fine as long as I am not in an activated venv environment.

from mysql.connector import MySQLConnection, Error
from python_mysql_dbconfig import read_db_config

With these statements I get the following:

Traceback (most recent call last):
  File "fetchone.py", line 1, in <module>
    from mysql.connector import MySQLConnection, Error
ImportError: No module named 'mysql.connector'

I have searched for a solution but most are dated several years ago. Like I said, the mysql.connector is located and works fine outside of the venv environment

2
  • Is venv short for virtual environment?
    – John K. N.
    Aug 24, 2017 at 12:05
  • Yes...that's the python module name
    – Vietyank
    Aug 26, 2017 at 2:16

2 Answers 2

2

You might want to check out the following article:

Can not get mysql-connector-python to install in virtualenv (Stackoverflow)

The accepted answer states the following:

Several things. There is an inconsistency in package naming so you may want to do:

pip search mysql-connector

to find out what it is called on your platform. I got two results mysql-connector-python and mysql-connector-repackaged.

so try this first:

pip install mysql-connector-python  

this may additionally give an error like this:

Some externally hosted files were ignored (use 
  --allow-external mysql-connector-python to allow).  

so finally this should do the job:

pip install mysql-connector-python --allow-external mysql-connector-python
1
  • DEPRECATION: --allow-external has been deprecated and will be removed in the future. Due to changes in the repository protocol, it no longer has any effect. May 27, 2018 at 12:37
0

The following command solved the issue for me.

pip install mysql-connector-python-rf

This post expands a little on the differences between mysql-connector-python and the -rf suffixed variant.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.