2

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'
0

3 Answers 3

3

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

7
  • I already had easy-install and pip ... so i ran the install for virtualenv and virtualenvwrapper. I don't know much about them but the mkvirtualenv command didnt work. I will try to research more... Jun 6, 2014 at 19:44
  • alright .. i ws able to activate the environment, and afterward installed setuptools, but the python3.3 still bombs out with "ImportError: No module named 'MySQLdb'" - is MySQLdb part of setuptools? if so, how can i validate that it's actually within the environment i have created? Jun 6, 2014 at 20:14
  • After you create the environment, you can install theodules specifically by typing 'workon yourenv', and then try 'pip install mysqldb'. Pip will become your modules manager. Oh and you can find out which modules are currently installed for this venv using the command 'pip freeze'
    – Shu Hikari
    Jun 6, 2014 at 20:33
  • "workon pythin3.3" says "-bash: workon: command not found". I will "actiavte" my python3.3 environment and see if I can pip install the modules and see if they work as expected. Jun 7, 2014 at 6:05
  • I activate my environment which i can tell by the propmt "(python3.3)root@server [folder]". Under my environment I see with pip freeze that it has "pandas=0.14.0", "MySQLdb=1.2.5" .. but when I enter python and try "import MySQLdb" or "import pandas" they both result in something like "ImportError: No module named 'MySQLdb'" Jun 7, 2014 at 6:55
2

I'm not sure about earlier versions but with CentOS 6.5 you can install the CentOS Software Collections Library repo. This gives you access to newer versions of some tools and python 3.3 is one of them.

You can find general information on the SCL here.

You can install the SCL repo with

yum install centos-release-SCL

Then you can install python 3.3 with

yum install python33

The documentation for SCL's is here.

3
  • Will this supercede my current python 2.6? or will it run concurrently, and will it have full access to the mods that the current 2.6 does? Jun 6, 2014 at 16:08
  • No, yes, I don't know. Why don't you suck it and see, it's bound to be better than rolling your own.
    – user9517
    Jun 6, 2014 at 16:30
  • This installed the SCL - but the modules still were't available to python 3.3. I amworking to implement the virtualend below. Jun 7, 2014 at 6:58
2

SOLUTION:

To solve this issue I created a fresh virtualenv with a specified python (python 3.3), and used the correct installer (easy_install-3.3 which is apparently specific to that python version) to add the modules. As verified by the correction version of pip (pip3.3) it appears to be working now

root@server [~] easy_install pip
root@server [~] pip install virtualenv virtualenvwrapper 
root@server [~] virtualenv --python=/usr/local/bin/python3.3 py3
root@server [~] . /root/py3/bin/activate
(py3)root@server [~] easy_install-3.3 numpy
(py3)root@server [~] easy_install-3.3 scipy
(py3)root@server [~] easy_install-3.3 pandas
(py3)root@server [~] easy_install-3.3 scikit-learn
(py3)root@server [~] easy_install-3.3 PyMySQL

(py3)root@server [~]# pip3.3 freeze
PyMySQL==0.6.2
numpy==1.8.1
pandas==0.14.0
pexpect==3.2
pyinotify==0.9.4
python-dateutil==2.2
pytz==2014.4
scikit-learn==0.15.0b1
scipy==0.14.0
scpy==1.1.4
six==1.6.1

My script now runs as hoped within my virtual environment.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .