I am running RHEL5 , and i have python 2.4 installed on it.Please dont ask why the native version? My question is that in my home directory i want to install python2.6 with selected packages only and also most importantly i dont want any of the library os or any other which deals with system calls or mail box preferences(sending mail to be prohibited).Is it possible to install a python version with selected libraries only. So now on the system python 2.4 and selected libraries of 2.6 exists
-
Do you want to do it for security so that users using Python 2.6 MUST not be able to access some modules or are there other reasons? If the goal is security then people may find workarounds very easily and you'll have to come up with something more solid. Otherwise solution would be much simpler – sharjeel Mar 29 '11 at 19:10
-
Yes this is mostly for security purpose.. – Rajeev Mar 30 '11 at 06:34
2 Answers
This may not be quite what you're looking for... but the following steps will accomplish something similar to this (if you have root access). The below steps assume you are on i386 architecture.
1) Install Python 2.6 in parallel on your system (requires root). It is available at the EPEL repository:
$ rpm -i http://download.fedora.redhat.com/pub/epel/5/i386/python26-2.6.5-6.el5.i386.rpm
2) Install setuptools by running (again as root):
$ curl http://peak.telecommunity.com/dist/ez_setup.py | python26
3) Install virtualenv (http://pypi.python.org/pypi/virtualenv):
$ easy_install-2.6 virtualenv
4) From your home directory, create a new python environment:
$ cd ~
$ virtualenv --no-site-packages my-env
5) Activate the environment:
$ source my-env/bin/activate
You can now use easy_install to install whatever packages you want, remove anything you don't want from ~/my-env/lib/python26/site-packages, etc.
To let you know you are working in the virtual environment, your prompt will look like this:
[(my-env)you@host ~]$
One thing you have to be careful about is python scripts that start with #!/usr/bin/python, as they will not use the environment version. To ensure that the environment version is used, execute your script like this:
$ python your-script.py
Or you can specifically specify your environment version in your scripts:
#!/home/your-name/my-env/bin/python

- 78
- 1
- 2
Try ActivePython - it installs to an isolated directory (eg: /opt/ActivePython-2.6
), and you can use PyPM to install third-party packages.

- 81,433
- 63
- 146
- 187
-
@Rajeev - FYI ... `pypm` installs by default into `~/.local` unless you use the `-g` option. – Sridhar Ratnakumar Mar 31 '11 at 17:29