Home > Backend Development > Python Tutorial > How Can I Permanently Add a Directory to PYTHONPATH?

How Can I Permanently Add a Directory to PYTHONPATH?

Mary-Kate Olsen
Release: 2024-12-13 09:03:14
Original
895 people have browsed it

How Can I Permanently Add a Directory to PYTHONPATH?

Ensuring a Directory Remains on PYTHONPATH

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:

Option for Bash Users (Mac/Linux)

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"
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template