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

ติดตั้ง Python Module ด้วย pip (Complete Guide)

pip คือ Package Manager มาตรฐาน ติดตั้ง Dependency อัตโนมัติ

1. เตรียม pip

# Python 2.7.9+ / 3.4+ มาพร้อม pip
# อัปเกรด:
# Linux/macOS
pip install -U pip setuptools
# Windows
python -m pip install -U pip setuptools

2. ติดตั้ง pip หากไม่มี

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

3. ติดตั้งแพ็กเกจ

$ pip install 'SomeProject'          # ล่าสุด
$ pip install 'SomeProject==1.4'     # เวอร์ชันคงที่
$ pip install 'SomeProject>=1,<2'    # ช่วงเวอร์ชัน
$ pip install -r requirements.txt    # จากไฟล์

4. Linux System Package Manager

ดู: Installing using Linux tools

Best Practice: ใช้ Virtual Environment ทุกโปรเจกต์ + Commit requirements.txt / Pipfile.lock