Can not get mysql-connector-python to install in virtualenv
Question:
I’m using Amazon Linux AMI release 2013.09. I’ve install virtualenv and after activation then I run pip install mysql-connector-python, but when I run my app I get an error: ImportError: No module named mysql.connector
. Has anyone else had trouble doing this? I can install it outside of virtualenv and my script runs without issues. Thanks in advance for any help!
Answers:
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
Solution I found:
sudo pip install mysql-connector-python-rf
If you see this error: option --single-version-externally-managed not recognized
, try this:
sudo pip install --egg mysql-connector-python-rf
try my answer here. Though i meant it for Python3, u can just modify the command python3->python to make it work for python2
I’ve battled with this and tried upgrading pip and setuptools but actually it seems all you need to do is:
sudo pip install virtualenv --upgrade
Once you’ve upgraded virtualenv, create a new virtual environment, activate it and try installing with:
pip install https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz
(you might need to update the url, but that’s the current one)
I have managed to overcome this problem by entering mysql-connector-python
package URL, taken from MySQL page, directly to the requirements file, instead of dependency name.
My requirements file looks like this:
bson==0.4.2
https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.tar.gz
pymongo==3.2.1
After creating virtualenv and switching into it I am executing
$ pip install -r ./requirements
And pip is doing the rest of the work, i.e., downloading, extracting and installing.
pip install mysql-connector
This worked for me!
I’d like to add that
sudo easy_install mysql-connector
worked for me after pip kept crashing no matter what I did.
I was facing the similar issue. My env details –
Python 2.7.11
pip 9.0.1
CentOS release 5.11 (Final)
Error on python interpreter –
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
>>>
Use pip to search the available module –
$ pip search mysql-connector | grep --color mysql-connector-python
mysql-connector-python-rf (2.2.2) - MySQL driver written in Python
mysql-connector-python (2.0.4) - MySQL driver written in Python
Install the mysql-connector-python-rf –
$ pip install mysql-connector-python-rf
Verify
$ python
Python 2.7.11 (default, Apr 26 2016, 13:18:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>
Command
pip install mysql-connector-python-rf
worked for me in my pyenv python version 2.7.12 and pip version 9.0.1.
Also something that can go wrong: Don’t name your own module mysql
import mysql.connector
will fail because the import gives the module in the project precedence over site packages and yours likely doesnt have a connector.py
file.
I just had the same problem and none of the solutions below worked. Some was already installed and the last one returned me an error:
pip install mysql-connector
pip install mysql-connector-python
pip install mysql-connector-python-rf
It looks like all I had to do was run the code in a different IDLE version, moving from 3.6 to 3.7.
Before doing that, I also used the windows repair installation tool in two different python versions I have installed.
Sometimes the simplest solutions work. Good luck
It works for me!
pip install mysql-connector-python-rf
If you get the error, install the latest version of setuptools
and wheel
:
pip install -U setuptools
pip install -U wheel
Make sure that you’ve installed the mysql connector from within the venv.
In VSCode, what worked for me is I selected the venv interpreter as the python interpreter.
You can download official connector from here –
Choose Platform independent
version.
Unzip and cd to the folder.
run sudo -H python3 setup.py install
from your environment.
Done
I’m using Amazon Linux AMI release 2013.09. I’ve install virtualenv and after activation then I run pip install mysql-connector-python, but when I run my app I get an error: ImportError: No module named mysql.connector
. Has anyone else had trouble doing this? I can install it outside of virtualenv and my script runs without issues. Thanks in advance for any help!
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
Solution I found:
sudo pip install mysql-connector-python-rf
If you see this error: option --single-version-externally-managed not recognized
, try this:
sudo pip install --egg mysql-connector-python-rf
try my answer here. Though i meant it for Python3, u can just modify the command python3->python to make it work for python2
I’ve battled with this and tried upgrading pip and setuptools but actually it seems all you need to do is:
sudo pip install virtualenv --upgrade
Once you’ve upgraded virtualenv, create a new virtual environment, activate it and try installing with:
pip install https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.1.3.tar.gz
(you might need to update the url, but that’s the current one)
I have managed to overcome this problem by entering mysql-connector-python
package URL, taken from MySQL page, directly to the requirements file, instead of dependency name.
My requirements file looks like this:
bson==0.4.2
https://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.4.tar.gz
pymongo==3.2.1
After creating virtualenv and switching into it I am executing
$ pip install -r ./requirements
And pip is doing the rest of the work, i.e., downloading, extracting and installing.
pip install mysql-connector
This worked for me!
I’d like to add that
sudo easy_install mysql-connector
worked for me after pip kept crashing no matter what I did.
I was facing the similar issue. My env details –
Python 2.7.11
pip 9.0.1
CentOS release 5.11 (Final)
Error on python interpreter –
>>> import mysql.connector
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mysql.connector
>>>
Use pip to search the available module –
$ pip search mysql-connector | grep --color mysql-connector-python
mysql-connector-python-rf (2.2.2) - MySQL driver written in Python
mysql-connector-python (2.0.4) - MySQL driver written in Python
Install the mysql-connector-python-rf –
$ pip install mysql-connector-python-rf
Verify
$ python
Python 2.7.11 (default, Apr 26 2016, 13:18:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>
Command
pip install mysql-connector-python-rf
worked for me in my pyenv python version 2.7.12 and pip version 9.0.1.
Also something that can go wrong: Don’t name your own module mysql
import mysql.connector
will fail because the import gives the module in the project precedence over site packages and yours likely doesnt have a connector.py
file.
I just had the same problem and none of the solutions below worked. Some was already installed and the last one returned me an error:
pip install mysql-connector
pip install mysql-connector-python
pip install mysql-connector-python-rf
It looks like all I had to do was run the code in a different IDLE version, moving from 3.6 to 3.7.
Before doing that, I also used the windows repair installation tool in two different python versions I have installed.
Sometimes the simplest solutions work. Good luck
It works for me!
pip install mysql-connector-python-rf
If you get the error, install the latest version of setuptools
and wheel
:
pip install -U setuptools
pip install -U wheel
Make sure that you’ve installed the mysql connector from within the venv.
In VSCode, what worked for me is I selected the venv interpreter as the python interpreter.
You can download official connector from here –
Choose Platform independent
version.
Unzip and cd to the folder.
run sudo -H python3 setup.py install
from your environment.
Done