Friday, 16 January 2015

Over-riding installed versions of a python module

I needed to use a local version of a python module AvrilFastaUtils.py that I had edited, rather than the one that is installed system-wide on our compute cluster. To do this, I had to force the python script to use the local version rather than the one installed on the computer cluster.

Here's how to do it within a python script that uses the AvrilFastaUtils.py module:

# prepend the path to the local version of AvrilFastaUtils.py to the PYTHONPATH
sys.path = ["/nfs/users/nfs_a/alc/Documents/git/helminth_scripts_python/lib"] + sys.path
# double-check that you've typed it correctly:
assert os.path.isdir(sys.path[0]) 
# now import the local version of the module:

import AvrilFastaUtils 

Thanks to Noel O'Boyle for helping with this!

1 comment:

krespim said...

I have started using virtualenvs and it was revelation for problems like these. Also, I no longer need the sysadmin's magical sudo powers to install python packages. My post on this is

I have started using virtualenvs and it was revelation for problems like these. Also, I no longer need the sysadmin magical sudo powers to install python packages. My post on it is
here.