Python modules

Create an __init__.py file in each directory that will be in the tree of your import. For example, if you have the following directory structure…

/opt/software/com/yourcompany/yourdivision/yourfile.py

…you would issue the following commands:

export PYTHONPATH=$PYTHONPATH:/opt/software
touch /opt/software/com/__init__.py
touch /opt/software/com/yourcompany/__init__.py
touch /opt/software/com/yourcompany/yourdivision/__init__.py

You should be able to run the following successfully…

python -c "import com.yourcompany.yourdivision.yourfile"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.