When utilizing sys.path.append to add a directory to the PYTHONPATH, the modification is only temporary and disappears upon exiting the Python session. To ensure a directory remains on the PYTHONPATH permanently, consider implementing the following solutions:
If you're running bash on macOS or a GNU/Linux distribution, you can permanently add the directory by incorporating the following code into your ~/.bashrc file:
export PYTHONPATH="${PYTHONPATH}:/my/other/path"
This line ensures the PYTHONPATH environment variable includes the specified directory even after closing the Python session. Remember to reload the ~/.bashrc file for the changes to take effect.
The above is the detailed content of How Can I Permanently Add a Directory to PYTHONPATH?. For more information, please follow other related articles on the PHP Chinese website!