Operations > Computing > FAQ
Python Module Installs
$ cd $ mkdir python-stuff $ cd python-stuff $ virtualenv . ... $ ./bin/pip install pandas ... $ ./bin/pip install PyOpenGL ...
the last of which may take some time to compile. Consult the pip docs for more information on searching for and installing packages.
This custom install tree can then be used as follows:
$ echo 'print "Hello World"' > foo $ cat foo print "Hello World" $ ./bin/python foo Hello World
Or by editing the "shebang" line to reference the appropriate virtualenv path so that the script foo can be run directly:
$ pwd /homes/urlogin/python-stuff
Manually edit the file foo with your favorite editor to include the /homes/urlogin/python-stuff/bin/python line, as shown by the cat command:
$ cat foo #!/homes/urlogin/python-stuff/bin/python print "Hello World" $ chmod +x foo $ ./foo Hello World
The virtualenv python should be the same version as the system one:
$ which python /usr/bin/python $ python --version Python 2.6.6 $ ./bin/python --version Python 2.6.6
Environment variables such as PATH could be updated, and the env(1) command used to automatically select some virtualenv environment, but that will not be covered here.
Install Custom Python Version
If you need a specific version of python (e.g. 2.7 or 3.something), that custom version can be installed under your home directory as well; one way would be to manually build Python:
$ wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2 $ tar xjf Python-2.7.5.tar.bz2 $ cd Python-2.7.5 $ unset CFLAGS $ ./configure --prefix=$HOME/usr/python-2.7.5 && make && make install
The CFLAGS environment variable likely does not need to be unset, but if you've enabled warnings and the like in CFLAGS like I had, the compile could core dump, good fun, good fun. Anyways! Scripts may then use the /homes/urlogin/usr/python-2.7.5/bin/python path to reference that custom python install, or virtualenv be used as above only this time using the custom python install:
$ cd $ mkdir more-python-stuff $ cd more-python-stuff $ virtualenv --python=$HOME/usr/python-2.7.5/bin/python2.7 . ... $ ./bin/python --version Python 2.7.5
And then the same pip install and other instructions, above, should apply, only this time using the custom Python install under your home directory.
Manual Path Method
An alternative that may be less complicated than
virtualenv though requires the creation of the filesystem paths and so forth is the manual path method:
Using the$ mkdir -p ~/pyfoo/lib/python2.6/site-packages $ export PYTHONPATH=~/pyfoo/lib/python2.6/site-packages $ easy_install --prefix=~/pyfoo PyOpenGL
setenvcommand must be used instead of
In either shell, the} mkdir -p ~/pyfoo/lib/python2.6/site-packages } setenv PYTHONPATH /home/$USER/pyfoo/lib/python2.6/site-packages } easy_install --prefix=~/pyfoo PyOpenGL
PYTHONPATHenvironment variable setting will likely need to be made permanent by editing a suitable shell configuration file, such as
.cshrc, as a new shell will not otherwise set the custom value by default. Use the
echocommand to test whether the environment variable has been set:
} echo $PYTHONPATH /home/nemo/pyfoo/lib/python2.6/site-packages
Some Extant Modules
There may be python modules pre-installed under the following directory. However, these may not be maintained; more up-to-date versions more readily could be installed via the
virtualenv method outlined above.
$ export PYTHONPATH=/home/lab.apps/pyfoo/lib/python2.6/site-packages
Cleanup Test Directories
Beware! Getting the rm command wrong might cause unexpected file deletion.
$ cd $ rm -rf python-stuff more-python-stuff