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

โมดูล Python เก็บอยู่ที่ไหน? (sys.path)

โมดูลมาตรฐานและ Third-party เก็บใน Lib/site-packages ของ Python Installation

ดู Search Path ด้วย sys.path

>>> import sys
>>> print(sys.path)
['', 'C:\\Python39', 'C:\\Python39\\Lib\\site-packages', ...]
  • '' = Current Directory
  • ตามด้วย Standard Library Paths
  • สุดท้ายคือ site-packages (Third-party)

ดู Location ของโมดูลเฉพาะ

>>> import scrapy
>>> print(scrapy.__file__)
C:\Python39\Lib\site-packages\scrapy\__init__.py

Verbose Mode: ดูทุกอย่างที่ Import

$ python -v hello.py
# importing zipimport hook
# import site
# import os
# import scrapy
# ...
หมายเหตุ: Built-in Modules (C Extension) ไม่มี __file__ หรือเป็น .so/.pyd