Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ตั้งค่า PYTHONPATH บน Linux

เหมือน macOS ทุกประการ (Linux/Unish ใช้ Colon : คั่น)

Temporary

export PYTHONPATH=${PYTHONPATH}:${HOME}/my_project/lib
python script.py

Permanent

# ~/.bashrc, ~/.profile, /etc/environment
export PYTHONPATH=${PYTHONPATH}:${HOME}/my_project/lib

System-wide (All Users)

# /etc/environment
PYTHONPATH="/opt/myapp/lib:/usr/local/custom/lib"

ข้อควรระวัง

  • Append ด้วย : ไม่ Replace
  • ไม่ต้องตั้งสำหรับ Standard Library
  • Virtualenv จัดการ Path ให้อัตโนมัติ (ดีกว่า)