user2991413
user2991413

Reputation: 551

Multiple Python leads to installation of boto at wrong location

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

Upvotes: 0

Views: 819

Answers (1)

Nab Ilovich
Nab Ilovich

Reputation: 360

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

Upvotes: 3

Related Questions