สำหรับนักพัฒนาโปรแกรมหรือระบบต่างๆ ด้วยภาษา python อาจจะมีปัญหาในติดตั้ง library หรือ package ที่เราติดตั้งเพิ่มเติมตอนนำขึ้น server demo หรือ server ที่ใช้จริง มี Packages ตัวอาจจะช่วยในปัญหานี้ได้ คือ pipreqs ขั้นตอนมีดังนี้
ทำการติดตั้ง package pipreqs ลงในเครื่องก่อนโดยใช้คำสั่งนี้
pip install pipreqs
ผลจากการติดตั้ง
จะมีรูปแบบการใช้งานของ command ดังนี้
Usage:
pipreqs [options] <path>
Options:
--use-local Use ONLY local package info instead of querying PyPI
--pypi-server <url> Use custom PyPi server
--proxy <url> Use Proxy, parameter will be passed to requests library. You can also just set the
environments parameter in your terminal:
$ export HTTP_PROXY="http://10.10.1.10:3128"
$ export HTTPS_PROXY="https://10.10.1.10:1080"
--debug Print debug information
--ignore <dirs>... Ignore extra directories, each separated by a comma
--encoding <charset> Use encoding parameter for file open
--savepath <file> Save the list of requirements in the given file
--print Output the list of requirements in the standard output
--force Overwrite existing requirements.txt
--diff <file> Compare modules in requirements.txt to project imports.
--clean <file> Clean up requirements.txt by removing modules that are not imported in project
ตัวอย่างการใช้งานมีดังนี้
pipreqs --use-local ./
ผลจาการรันคำสั่ง
จากนั้นก็จะได้ไฟล์ requirements.txt มาอยู่ในโปรแกรม
ภายในไฟล์นั้นก็จะมีพวกชื่อ package ที่เราได้ทำการติดตั้งภายในโปรแกรม
อันนี้ก็เป็น package ในไฟล์ python ที่ได้ import มาใช้งาน
อ้างอิง
https://www.pypi.org/project/pipreqs/
https://www.dev.to/bhupesh/pipreqs-automatically-generate-python-dependencies-30nl
https://www.github.com/bndr/pipreqs