I need to add a directory to my sys.path/PYTHONPATH which contains my custom Python modules. There are a couple of other questions on here on the same topic with answers that have resolved the issue for other users.
I have manually appended to the sys.path object the new file path, and that has successfully added the module directory, but only for the current Python shell, and after a reboot the module path is lost.
Another common answer has been to alter the PYTHONPATH environment variable with a call like:
PYTHONPATH="$PYTHONPATH:/path/to/modules"
I am having no luck with this approach and I cannot even identify the PYTHONPATH variable or understand where it lives. The call sudo echo $PYTHONPATH
does not return anything and PYTHONPATH does not show up when I call env
. There is no reference to PYTHONPATH in the .bashrc or .profile files in my ~ directory.
I am new to Linux and getting the hang of using the terminal. Any help to point me in the right direction to getting the path to my modules permanently added will be greatly appreciated!
UPDATE:
I have tried adding the line PYTHONPATH=/path/to/modules
to my .bashrc file in my user directory, but this does not resolve the issues and furthermore the PYTHONPATH variable is still not showing up in terminal when I call env
.
UPDATE 2: Adding the following lines to .bashrc has succeded in getting PYTHONPATH to show up in terminal as an environment variable:
PYTHONPATH=path/to/modules
export PYTHONPATH
and now in Python sys.path shows the new path/to/modules and the modules are loading as expected.
However, while this works to solve my specific problem, I'm still not sure quite how all the pieces are working, such as why the new PYTHONPATH variable is not showing the remaining default paths that show up in sys.path.