python項目下生成requirements.txt方法
更新時間:2023年06月18日 14:57:00 作者:岳來
這篇文章主要介紹了python項目下生成requirements.txt的方法,很多小伙伴不知道如何生成requirements.txt,本文就通過代碼示例給大家詳細介紹如何生成,,需要的朋友可以參考下
一、使用pip freeae
pip freeze > requirements.txt
該命令存在局限:
該命令只會生成通過pip install 安裝的包
如果沒有創(chuàng)建Python的虛擬環(huán)境virtualenv,該命令會將環(huán)境中所有的包都輸出到requirements.txt文件,不管你當前的Project有沒有用到這些包
二、使用pipreqs
Pipreqs 只會統(tǒng)計項目使用的包
2.1、安裝pipreqs
pip install pipreqs
2.2、使用方法
pipreqs "目錄" #在目錄下生成requirements.txt
2.3、特殊說明
2.3.1、Mac 下沒法使用
pipreqs zsh: command not found: pipreqs
沒有找到使用辦法
2.3.2、Linux 使用報錯
pipreqs ./ Traceback (most recent call last): File "/usr/bin/pipreqs", line 7, in <module> from pipreqs.pipreqs import main File "/usr/lib/python2.7/site-packages/pipreqs/pipreqs.py", line 51, in <module> from pipreqs import __version__ ImportError: cannot import name __version__
解決辦法,更換pipreqs版本
# 查看可安裝版本 pip install pipreqs==100 You are using pip version 7.1.0, however version 22.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting pipreqs==100 Could not find a version that satisfies the requirement pipreqs==100 (from versions: 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5, 0.2.7, 0.2.8, 0.2.9, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.3.5, 0.3.6, 0.3.7, 0.3.8, 0.3.9, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7, 0.4.8, 0.4.9, 0.4.10, 0.4.11) No matching distribution found for pipreqs==100 # 選擇某一版本安裝 pip install pipreqs==0.4.0 # 查看能否使用 pipreqs --help pipreqs - Generate pip requirements.txt file based on imports Usage: pipreqs [options] <path> Options: --use-local Use ONLY local package info instead of querying PyPI --pypi-server Use custom PyPi server --proxy 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 --encoding <charset> Use encoding parameter for file open --savepath <file> Save the list of requirements in the given file --force Overwrite existing requirements.txt
2.3.3、Windows下使用
pipreqs "目錄" --encoding=utf8
三、更換環(huán)境后安裝requirements.txt
pip install -r requirements.txt
到此這篇關于python項目下生成requirements.txt方法的文章就介紹到這了,更多相關python requirements.txt內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
python結合多線程爬取英雄聯(lián)盟皮膚(原理分析)
多線程是為了同步完成多項任務,不是為了提高運行效率,而是為了提高資源使用效率來提高系統(tǒng)的效率。這篇文章主要介紹了python爬取英雄聯(lián)盟皮膚結合多線程的方法,需要的朋友可以參考下2021-05-05