'running pip install from python 2.7.5

I have a CentOS server (5.6) which has Python 2.4.3 on it. I have another local installation of Python (2.7.5) installed in /opt and soft-links created as follows /usr/local/bin/python2.7 and /usr/local/python2.7. I want to install python-requests using pip. While installing using the command pip install requests, I get the following error:

root ~/ff_test_ff # pip install requests
Unpacking ./requests
  Running setup.py egg_info for package from file:///root/ff_test_ff/requests
    Traceback (most recent call last):
      File "<string>", line 14, in ?
      File "/tmp/pip-MM685m-build/setup.py", line 6, in ?
        import requests
      File "requests/__init__.py", line 58
        from . import utils
             ^
    SyntaxError: invalid syntax
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 14, in ?

  File "/tmp/pip-MM685m-build/setup.py", line 6, in ?

    import requests

  File "requests/__init__.py", line 58

    from . import utils

         ^

SyntaxError: invalid syntax

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /root/.pip/pip.log

I'm assuming it's still trying to use Python 2.4. I checked here which says 2.4 isn't supported. So how do I run the pip install command but use python2.7 instead?



Solution 1:[1]

you need to set the PYTHONPATH / PYTHONHOME like here

you can also try to install virtualenv

Solution 2:[2]

You probably should (re)install a new version of pip explicitly for the new Python version. On pip installation instructions page it says that

pip works with CPython versions 2.6, 2.7, 3.1, 3.2, 3.3 and also pypy.

While installing, be sure to use the newer version of Python instead of the old one.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 miikkas