S and its system came with Python 2.7, it is possible to keep it with Python 2.7.10. and your system came with Python 2.6, there is no way to change the Python system standard to 2.7: you will destroy your system - most Linux distributions have several key administration programs that rely heavily on Python in the system.
The correct way to proceed is: use the system manager to download the prerequisites to compile Python (for example, in Debian, Ubuntu and derivatives: "apt-get build-Dep python-2.7", in Folder: yum-builddep python2). -Download the source code (the .tar.gz file) of Python.org, and Compile a local version, for the user - set the prefix to be within your own home (./configure --prefix=/home/user/usr) or a system prefix, separate of /usr
- /opt
is a good call. The advantage of using a prefix within your /home is that you do not need super-user permissions at any time (sudo
) to install the new version of Python.
From there, install the virtualenv package in the system’s Python, and for each project you work on, create a virtualenv, using the Python that Voce compiled - for that use the argument -p
of virtualenv.
Each time you work on the project, activate virtualenv. The sequence, after compiling the new Python, is this:
apt-get install python-virtualenv
virtualenv -p /home/usuario/usr/bin/python-2.7 meuprojeto
cd meuprojeto
source bin/activate
and from there put the . py of your new project inside the - folder and install other modules at will with the command pip
:
the installed modules will be restricted to virtualenv. A second project that uses different versions of the same modules can be created in another folder, and one project will not interfere with the other.
(The step source bin/activate
should run on every shell you run Python programs from this project - there are auxiliary virtualenv packages that allow a simpler command to activate the virtualenvs, but the difference is almost cosmetic only)
This recipe works in the same way for newer versions of Python - and you can even have separate virtualenvs with Python 3.4 and Python 3.5 beta.
I think what’s happening is that the
pip
which is being used is loading the wrong Python, possibly/usr/bin/python
which should be a symlink to the old version. Usels -l /usr/bin/python
to see if this is really what it is. If that’s all you need to do is redo the symlink for your new Python.– sergiopereira