I have a CentOS server (rel6) that had python installed (2.6), but I needed a few features in 3.3+. I installed 3.3 into a seperate folder and made a symbolic link to execute it:
- I installed setup tools:
yum install python-setuptools - I installed a needed module"pandas"
easy_install pandas - I executed my pyton script, which encountered an error that required i use a newer version
- I downloaded and installed Python 3.3.5 to it's own folder so as to not override my default python
- wget http://www.python.org/ftp/python/3.3.5/Python-3.3.5.tar.xz
- tar xJf ./Python-3.3.5.tar.xz
- cd ./Python-3.3.5
- ./configure –prefix=/opt/python
- make
- make install
- Made s symbolic link to allow me to execute this new python:
- ln -s /opt/python3.3/bin/python3.3 ~/bin/py
The problem is that when I execute the python script with my new py alias, it does not have all the addons needed (explicitly MySQLdb) which the default install does.
How do i go about installing the MySQLdb module, or any for that matter, to be reachable or useable for the new Python 3.3.5 installation? Or is there a way to make the current modules in 2.6 available to 3.3.5 as well?
Update:
My virtual environment has the following installed
root@server [/]# source ./root/python3.3/bin/activate
(python3.3)root@server [/]#
(python3.3)root@server [/]# pip freeze
MySQL-python==1.2.5
numpy==1.8.1
pandas==0.14.0
python-dateutil==2.2
pytz==2014.4
six==1.6.1
But when I execute the import, it still fails
(python3.3)root@server [/]# python3.3 -c "import MySQLdb"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'MySQLdb'
Best Answer
For multiple python versions, use virtualenv and pip to manage modules.
So you can create a virtual environment with a specific python versions and modules.
So when creating a new environment with a specific python version
If any dependencies python would have, just do this:
Extract the files from the archive and get into its path:
And then install using:
You can do this last step to install modules on this python version you have, just downloading it and running python3.3.5 setup install, but I recommend you to use virtualenv cause its easy mode of managing different python versions and its modules.
To properly install virtualenv without much trouble, follow these steps