I currently do this:
How can I make it so that the PYTHONPATH can include everything subdirectory?
PYTHONPATH = /home/$USER/....and-all-subdirectories
That's not how PYTHONPATH works; PYTHONPATH treats its search path differently from shell PATH. Let's say I do this:
This will work, in Python (
However, subdirectories are treated as packages when
To get at something in that subdirectory, this would work:
To roll a solution where every subdirectory in your PYTHONPATH is added, you need to explicitly add every folder to PYTHONPATH or
That's not how environment PATH variables work - you give it the top-level directory and it's up to the application to recurse the directory tree if it needs to.
It's possible to add subdirectories of a directory to your PYTHONPATH variable using the shell, of course. I currently use something similar to the following in my .bashrc:
This would include all subdirectories of your user folder to a depth of 2 in the tree. The find command locates the directories ('-type d'), and the following sed and tr commands format the output in the usual way of PATH variables.
Leaving off '-maxdepth 2' would include all subdirectories of your home folder, which is probably quite a lot to search. Perhaps this should only be done in your $HOME/repository/python-stuff directory.