0

I am on Centos7. I have multiple Python versions (Totally newbie in python). One at my root inside folder name Python-2.6.6 which i installed following these steps :

wget https://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz
 tar -zxvf Python-2.6.6.tgz
 cd Python-2.6.6
 sudo yum install gcc gcc-c++
 make 
 make install

However there is also a Python folder at /usr/lib/python2.7/site-packages Which i have no idea how got created . Now i installed boto using

sudo yum -y install python-pip
sudo pip install boto

installation ended with comments Installing collected packages: boto Successfully installed boto-2.47.0

Now when i do python --version , I do get Python 2.6.6 which is expected

which python : /usr/local/bin/python

but when i do import boto i get import boto Traceback (most recent call last): File "", line 1, in ImportError: No module named boto

WHY YOU NO IMPORT?Please help

user2991413
  • 521
  • 2
  • 9
  • 26
  • I think your Centos already had Python, which you now conflicted with your other installation. Additionally, python-pip RPM package installs packages into the *system* python. In addition, [Python 2.6 was *EOL*ed a long time ago already](https://mail.python.org/pipermail/python-dev/2013-September/128287.html), full of holes and so on, and Python 2.7 follows it - if you're compiling your own Python, why not go for the fresh **3**.6?! – Antti Haapala -- Слава Україні Jun 25 '17 at 16:58
  • Are you suggesting to uninstall Python 2.6 ? Can't I somehow use any of the existing python installation? – user2991413 Jun 25 '17 at 17:01
  • You **did** install your Python 2.6.6 from source there. Furthermore, it wasn't the source even for 2.6.9 which was the latest released Python 2.6 version, but broken [2.6.6](https://www.python.org/download/releases/2.6.6/) without any Centos-specific patches. – Antti Haapala -- Слава Україні Jun 25 '17 at 17:03
  • After the `make install` you possibly overwrote your system Python... it depends on the settings you used to actually install it. The Python-2.6.6 directory was used to build it, but `make install` threw the files into `/usr/local/bin` and `/usr/local/lib/` etc... The best course of action would be to remove these files, as they will probably clash with your system's Python. – Antti Haapala -- Слава Україні Jun 25 '17 at 17:07
  • Sorry for my ignorance , but which files should i remove . Is it advisable to remove python . Here people are suggesting against it. https://stackoverflow.com/questions/10724471/how-to-uninstall-python2-6 – user2991413 Jun 25 '17 at 17:11
  • I don't have Centos 7. I cannot see the system, but you've already messed up the system by installing another python into the system path, so I'd say you'd want to remove *the* python version that you just installed with `make install`. Perhaps Nab there would know Centos better. – Antti Haapala -- Слава Україні Jun 25 '17 at 17:12
  • Notice that the *other* question details about removing the *preinstalled* Python 2.6. In your case, Centos comes preinstalled with Python *2.7*. – Antti Haapala -- Слава Україні Jun 25 '17 at 17:13
  • @AnttiHaapala Hi, need little help. i did rm /usr/local/bin/python* , after that , which python gives /usr/bin/python(which is the preinstalled python dir). but when i type python, i am getting /usr/local/bin/python: No such file or directory . Any idea why this is happening? how can i fix it ? – user2991413 Jun 25 '17 at 19:28
  • @AnttiHaapala Created a symlink between ln -s /usr/bin/python /usr/local/bin/python , it worked :) – user2991413 Jun 25 '17 at 19:31

1 Answers1

3

CentOs 7 is delivered with python 2.7 by default.

You installed boto with pip wich is "bind" to python 2.7, that's why you can't import boto using python 2.6. pip is bind to python2.7, cause it's the default version in CentOs 7.

You should use virtualenv. It allows you to create a python environnement with a specific python version and install the modules needed.

Example:

virtualenv -p /usr/bin/python2.7 /home/user/my_project
cd ./my_project
source bin/active

Now you're in a python virtualenv. The first command points to python2.7, but you can make it point to any python version installed (compiled, from repos etc.). Once you sourced the active file you can install modules using pip

Edit

To run a script using your virtualenv (without sourcing ./bin/active):

/home/user/my_project/bin/python /path/my_script.py

If you use this command :

source bin/activate

Then you can use pip to add a lib to the virtualenv.

Edit 2

So, you're on Centos 7, wich is provided with python 2.7. You want to use python 2.6 with a specific script.

  1. Install python 2.6 (let's say in /usr/bin/python2.6)
  2. Create a virtuanlenv with python 2.6 :

    virtualenv -p /usr/bin/python2.6 my_venv

  3. Enter the virtualenv

    cd my_env source bin/activate

  4. Check the python version (should return python 2.6.x)

    python

  5. Install a module with pip :

    pip install boto

boto will be installed with python 2.6, so you will be able to use your script.

If for some reason pip is not installed :

yum install python-pip
Nab Ilovich
  • 360
  • 5
  • 14