CentOS (rel6) with default python 2.6, but seperate 3.3.5 installation

centosMySQLpython

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:

  1. I installed setup tools:
    yum install python-setuptools
  2. I installed a needed module"pandas"
    easy_install pandas
  3. I executed my pyton script, which encountered an error that required i use a newer version
  4. I downloaded and installed Python 3.3.5 to it's own folder so as to not override my default python
  5. 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.

easy_install pip
pip install virtualenv virtualenvwrapper 

So when creating a new environment with a specific python version

mkvirtualenv nameit -p python3.3

If any dependencies python would have, just do this:

wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz

Extract the files from the archive and get into its path:

tar -xvf setuptools-1.4.2.tar.gz
cd setuptools-1.4.2

And then install using:

python3.3 setup.py install

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

Related Topic