Where should I put my own python module so that it can be imported

I usually put the stuff i want to have ready to import in the user site directory:

~/.local/lib/pythonX.X/site-packages

To show the right directory for your platform, you can use python -m site --user-site


edit: it will show up in sys.path once you create it:

mkdir -p "`python -m site --user-site`"

So if your a novice like myself and your directories are not very well organized you may want to try this method.

Open your python terminal. Import a module that you know works such as numpy in my case and do the following. Import numpy

numpy.__file__

which results in

'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site- packages/numpy/__init__.py'

The result of numpy.__file__ is the location you should put the python file with your module (excluding the numpy/__init__.py) so for me that would be

/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site- packages

To do this just go to your terminal and type

mv "location of your module" "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site- packages"

Now you should be able to import your module.