data science

Building a Local Library – Python

This may not be the ideal way of doing, but it’s how I’m doing it for now.

To build a local library with all the modules you write you should move the modules to the python, a process which is explained here.

The main problem, however, is that if you want to edit them, then you will have to access the hidden directories (in Mac). Which really sucks if you are as lazy as me.

The other way to do it is to change the list of directories that Python goes through looking for modules.

Here you can add a local directory of your choice – in my case it will be /Users/jose/Documents/gh_repo.

The process of modifying Python’s search path is explained in greater detail here.

The easiest thing to do is to go open Python in the terminal and run the sys module.

>>> import sys

Then we can get the list of paths being search like this

>>> sys.path

Which for me returns a really long list, but should at least look like this

['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2',
 '/usr/local/lib/python2.3/lib-tk', '/usr/local/lib/python2.3/lib-dynload',

All we need to do is append the directory to that list, like so

>>> sys.path.append('/Users/jose/Documents/gh_repo')

So now our path list should look a bit like this

>>> sys.path
['', '/usr/local/lib/python2.3', '/usr/local/lib/python2.3/plat-linux2',
 '/usr/local/lib/python2.3/lib-tk', '/usr/local/lib/python2.3/lib-dynload',

…that’s it.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s