python---使用pipreqs及遇到的问题
目录
pipreqs简介
pipreqs安装
pipreqs使用时遇到的问题
pipreqs简介
项目开发的过程中, 避免不了搭建和部署开发环境, 而搭建和部署开发环境需要项目依赖的python第三方包, 如何获取一个项目中所需依赖的python第三方包, 这就需要使用pipreqs包, 它可以自动生成项目中依赖的第三方包, 并能生成requirements.txt
文件, 方便在搭建和部署项目开发环境时安装依赖包.
pipreqs安装
复制pip install pipreqs
可以使用--help
参数, 查看pipreqs支持的参数
复制pipreqs - Generate pip requirements.txt file based on imports
Usage:
pipreqs [options] [<path>]
Arguments:
<path> The path to the directory containing the application
files for which a requirements file should be
generated (defaults to the current working
directory).
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.
--no-follow-links Do not follow symbolic links in the project
--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.
--no-pin Omit version of output packages.
pipreqs与freeze的区别
pipreqs对项目目录进行扫描, 发现使用了哪些第三方包, 自动生成依赖包列表. 但有时候可能会有一点偏差, 需要检查调整一下.
freeze配合虚拟环境使用时效果更好, 因为freeze是把整个环境中的包都列出来, 不论项目中是否使用了, 都会被列出来.
pipreqs使用时遇到的问题
出现UnicodeDecodeError
出现编码错误时, 可以指定编码格式
复制pipreqs ./ --encoding=utf-8
出现SyntaxError
出现语法错误时, 一般时python2和python3之间的不兼容问题, 可以使用--debug
找到问题文件, 然后--ignore
忽略掉问题文件所在的目录.
复制pipreqs ./ --encoding=utf-8 --debug
pipreqs ./ --encoding=utf-8 --ignore dir目录
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人