This is exactly why you should use virtualenv.
mysql connector installed in python 2.6, but not on 2.7
-
08-10-2022 - |
Question
RedHat is my OS. By default it runs python2.6
. However, I needed to install python2.7
. I installed it following this post. Now, when I run:
$ python -V
Python 2.7.5
however
$ sudo python -V
Python 2.6.6
So, I incurr problems when installing libraries.
I tried to install mysql-connector
by:
pip install mysql-connector-python
- following the installation guide for source distribution
- following the installation guide for binary distribution
However, mysql-connector module is not installed on the python 2.7 version. If I run:
$ python
>>> import mysql.connector
ImportError: No module named mysql.connector
How can I install mysql module also on python version 2.7?
EDIT
Additional information:
$ which pip
/usr/bin/pip
$ sudo which pip
/usr/bin/pip
$ which easy_install
/opt/rh/python27/root/usr/bin/easy_install
$ sudo which easy_install
/usr/bin/easy_install
/usr/bin/ $ ls -al pip
-rwxr-xr-x. 1 root root 281 Feb 7 11:07 pip
/opt/rh/python27/root/usr/bin $ ls -al easy_install
-rwxr-xr-x. 1 root root 344 Aug 16 11:40 easy_install
Solution
OTHER TIPS
Please check where pip and easy_installed are installed? my guess that which pip
would show pip is in the python 2.6 folder. you need to to reinstall pip and easy_install to the python 2.7 folder. you can do it with :
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | python
and then check which easy_install
points to the right direction (you might need to alias/symlink easy_install to the new install. to override the system easy_install) then you can just easy_install pip
Edit (after OP input):
- try to easy_install pip (since the basic easy_install is python 2.7)
Update:
Since for some reason python2.7 easy install is installed as root instead of your user you can change ownership of the easy_instlal (or maybe you'll need the entire python2.7 lib. try to change as little as possible) - you can do it with the chown command:
chown username:usergroup(usually your username also) path/to/change/ownership
You should install pip in python2.7.5 environment. After that pip install will work as expected