Is it possible to install another version of Python to Virtualenv?
I have a shared account in a web-hosting that has Python 2.4 installed, but my code is not compatible with 2.4. Is it possible to install Python 2.6 directly to Virtualenv?
Note: I don´t have permission to install it in the shared server.
Here are the options for virtualenv
$ virtualenv
You must provide a DEST_DIR
Usage: virtualenv [OPTIONS] DEST_DIR
Options:
--version show program's version number and exit.
-h, --help show this help message and exit.
-v, --verbose Increase verbosity.
-q, --quiet Decrease verbosity.
-p PYTHON_EXE, --python=PYTHON_EXE
The Python interpreter to use, e.g.,
--python=python2.5 will use the python2.5 interpreter
to create the new environment. The default is the
interpreter that virtualenv was installed with
(/usr/bin/python)
--clear Clear out the non-root install and start from scratch
--no-site-packages Don't give access to the global site-packages dir to
the virtual environment
--unzip-setuptools Unzip Setuptools or Distribute when installing it
--relocatable Make an EXISTING virtualenv environment relocatable.
This fixes up scripts and makes all .pth files
relative
--distribute Use Distribute instead of Setuptools. Set environ
variable VIRTUALENV_USE_DISTRIBUTE to make it the
default
--prompt==PROMPT Provides an alternative prompt prefix for this
environment
1) What you want to do is install python to a directory that you are able to write too.
You can follow the instructions here
.
For Python 2.7.1Python source
mkdir ~/src
mkdir ~/.localpython
cd ~/src
wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tgz
tar -zxvf Python-2.7.1.tgz
cd Python-2.7.1
make clean
./configure --prefix=/home/${USER}/.localpython
make
make install
2) Install virtualenvvirtualenv source
cd ~/src
wget http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.5.2.tar.gz#md5=fbcefbd8520bb64bc24a560c6019a73c
tar -zxvf virtualenv-1.5.2.tar.gz
cd virtualenv-1.5.2/
~/.localpython/bin/python setup.py install
3) Create a virtualenv using your local pythonvirtualenv docs
mkdir /home/${USER}/virtualenvs
cd /home/${USER}/virtualenvs
~/.localpython/bin/virtualenv py2.7 --python=/home/${USER}/.localpython/bin/python2.7
4) Activate the environment
cd ~/virtualenvs/py2.7/bin
source ./activate
5) Check
(py2.7)$ python
Python 2.7.1 (r271:86832, Mar 31 2011, 15:31:37)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(py2.7)$ deactivate
$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Pre-requisites:
sudo easy_install virtualenv
sudo pip install virtualenvwrapper
Installing virtualenv with Python2.6:
-
You could manually download, build and install another version of Python to
/usr/local
or another location. -
If it's another location other than
/usr/local
, add it to your PATH. -
Reload your shell to pick up the updated PATH.
-
From this point on, you should be able to call the following 2 python binaries from your shell
python2.5
andpython2.6
-
Create a new instance of virtualenv with
python2.6
:mkvirtualenv --python=python2.6 yournewenv