PYTHONPATH Environment Variable
PYTHONPATH एक Environment Variable है जिसे आप Additional Directories Add करने के लिए Set कर सकते हैं जहां Python Modules और Packages के लिए Look करेगा। अधिकांश Installations के लिए, आपको ये Variables Set करने की आवश्यकता नहीं है क्योंकि Python को Run करने के लिए इनकी आवश्यकता नहीं होती। Python जानता है कि इसकी Standard Library कहां Find करनी है।
PYTHONPATH Set करने का एकमात्र कारण Custom Python Libraries की Directories को Maintain करना है जिन्हें आप Global Default Location (यानी site-packages Directory) में Install नहीं करना चाहते।
Python कैसे Modules Find करता है:
import sys
print('\n'.join(sys.path))
sys.path में शामिल होता है:
- Script की Directory (या Current Directory)
PYTHONPATHDirectories- Standard Library Paths
site-packagesDirectories.pthFiles में Listed Paths
जब PYTHONPATH उपयोगी होता है:
- Development के दौरान Local Packages Test करना
- Shared Network Drives से Modules Access करना
- Non-standard Locations में Installed Packages
जब PYTHONPATH से बचें:
- Production Deployments में
- जब Virtual Environments काम कर सकते हों
- Standard Library को Override करने के लिए
Better Understanding के लिए Python Environment Variables Docs पढ़ें: Python Command Line Docs