通过pip获取python环境下已安装的库——requirements方法

最近被环境问题搞怕了,特别是pyinstaller的打包问题,折腾了好久好久。为了避免下一次有这种库和库的冲突,可以采用这种方法。

获取环境中所有安装的包:

pip freeze >requirements.txt        #在当前目录获取已经安装的python插件

获取当前项目需要的所有的包

安装pipreqs库

pip install pipreqs

然后执行

pipreqs ./  # 报错就执行下面这条
pipreqs ./ --encoding=utf-8

这个时候我们会在当前目录生成一个requiremengt.txt的文件。

我的如下
altgraph0.17
certifi
2020.12.5
cffi1.14.4
chardet
4.0.0
comtypes1.1.8
crypto
1.4.1
cycler0.10.0
future
0.18.2
idna2.10
iso8601
0.1.13
kiwisolver1.3.1
matplotlib
3.1.1
Naked0.1.31
numpy
1.19.5
pandas0.25.3
pefile
2019.4.18
Pillow8.1.0
psutil
5.8.0
PyAudio0.2.11
pycaw
20181226
pycparser2.20
pycryptodome
3.9.9
PyInstaller3.6
pyparsing
2.4.7
pyserial3.5
python-dateutil
2.8.1
pytz2020.5
pywin32
300
pywin32-ctypes0.2.0
PyYAML
5.3.1
requests2.25.1
scipy
1.5.4
serial0.0.97
shellescape
3.8.1
six1.15.0
sounddevice
0.4.1
SoundFile0.10.3.post1
urllib3
1.26.4
WMI1.5.1
XlsxWriter
1.3.7

这个是我项目能成功用pyinstaller打包exe并不报错的环境

那么,下次我在配置新环境时,可以直接用以下命令快速配置环境

pip install -r requirements.txt        #在requirements.txt目录下运行

posted @ 2022-04-02 19:05  JaxonYe  阅读(469)  评论(0编辑  收藏  举报