導出程序所使用的的依賴包,並生成requirements文件
import os, sys # 找到當前目錄 project_root = os.path.dirname(os.path.realpath(__file__)) print(project_root) # 找到解釋器,虛擬環境目錄 python_root = sys.exec_prefix print(python_root) # 拼接生成requirements命令 command = python_root + '\Scripts\pip freeze > ' + project_root + '\\requirements.txt' print(command) # 執行命令。 os.system(command)