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

วิธีติดตั้งโมดูล Python บน Mac ที่เข้ากันได้ดีที่สุด

บน macOS มีหลายทางเลือก แนะนำตามลำดับ:

1. ใช้ pip (มาตรฐาน ข้าม Platform ได้)

# ตรวจสอบ pip
pip install -U pip setuptools
# หรือติดตั้ง pip ใหม่
curl https://bootstrap.pypa.io/get-pip.py | python

2. Homebrew (สำหรับ System-level Tools)

$ brew install python  # ติดตั้ง Python 3 + pip
$ pip install package_name

3. easy_install (เก่า ไม่แนะนำ)

$ easy_install django  # ยังทำงานได้ แต่ deprecated

คำสั่ง pip พื้นฐาน

$ pip install 'SomeProject'          # ล่าสุด
$ pip install 'SomeProject==1.4'     # เวอร์ชันคงที่
$ pip install 'SomeProject>=1,<2'    # ช่วงเวอร์ชัน
Best Practice: ใช้ pyenv จัดการ Python Version หลายรุ่น + pipx สำหรับ CLI Tools + venv ต่อโปรเจกต์