pipreqs คืออะไร - เป็นฟังก์ชั่นที่ใช้สร้างไฟล์ requirements ที่ใช้สำหรับเก็บการ import โมดูลของไพทอน

แชร์ความรู้ภาษา Python ไพทอน การเขียนโปรแกรมภาษาไพทอน

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
jirawoot
PHP VIP Members
PHP VIP Members
โพสต์: 3129
ลงทะเบียนเมื่อ: 17/06/2019 10:30 am

pipreqs คืออะไร - เป็นฟังก์ชั่นที่ใช้สร้างไฟล์ requirements ที่ใช้สำหรับเก็บการ import โมดูลของไพทอน

โพสต์ที่ยังไม่ได้อ่าน โดย jirawoot »

pipreqs คืออะไร
pipreqs คือ เป็นฟังก์ชั่นที่ใช้สร้างไฟล์ requirements ที่ใช้สำหรับเก็บการ import ของตัว module และ package ที่อยู่ใน library ที่ได้ทำการติดตั้งในโปรแกรมที่พัฒนาในภาษา Python ไฟล์ของ requirements จะมีสกุลไฟล์ .txt จะใช้เมื่อทำการนำโปรแกรมที่พัฒนาเสร็จเรียบร้อยแล้วนำใช้ เพื่อที่จะทำการติดตั้ง module ที่ใช้สำหรับโปรแกรม ซึ่งประโยชน์ของ pipreqs ก็คือตัวเป็นสร้าง ไฟล์ requirements เพื่อใช้เก็บ module ที่อยู่ใน library ของโปรแกรม เพื่อไปติดตั้งยังเครื่องอื่น
ขั้นตอนการใช้งาน

ทำการ install pipreqs ก่อน จะใช้คำสั่งดังนี้

โค้ด: เลือกทั้งหมด

$ pip install pipreqs
Selection_021.png
จะมีรูปแบบการใช้ดังนี้

โค้ด: เลือกทั้งหมด

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 ./
Selection_022.png
Selection_022.png (9.78 KiB) Viewed 1550 times
จากนั้นก็จะไฟล์ requirements.txt มาอยู่ในโปรแกรม
Selection_023.png
Selection_023.png (5.29 KiB) Viewed 1550 times
ภายในไฟล์นั้นก็จะมีพวก module ที่เราได้ทำการติดตั้งภายในโปรแกรมครับ
Selection_024.png
Selection_024.png (13.23 KiB) Viewed 1550 times
รูปนี้ก็เป็น module ที่เราในโปรแกรม
Selection_026.png
Selection_026.png (11.18 KiB) Viewed 1550 times
บทเรียน Python เพิ่มเติม


อ้างอิง
https://www.pypi.org/project/pipreqs/
https://www.dev.to/bhupesh/pipreqs-automatically-generate-python-dependencies-30nl
https://www.github.com/bndr/pipreqs
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41410
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: pipreqs คืออะไร - เป็นฟังก์ชั่นที่ใช้สร้างไฟล์ requirements ที่ใช้สำหรับเก็บการ import โมดูลของไพทอน

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ถ้าติดตั้ง pip ไว้แล้ว
สามารถใช้ freeze แทนได้ตามตัวอย่าง
สำหรับ windows

โค้ด: เลือกทั้งหมด

env1\bin\python -m pip freeze > requirements.txt
env2\bin\python -m pip install -r requirements.txt
สำหรับ linux

โค้ด: เลือกทั้งหมด

env1/bin/python -m pip freeze > requirements.txt
env2/bin/python -m pip install -r requirements.txt
ข้อมูลเพิ่มเติม และ Options การใช้งานที่นี่
https://pip.pypa.io/en/stable/cli/pip_freeze/
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 95