当前环境:联网机 Win10 x64 + Python 3.7 , 准备将这些包安装到 内网机 Win7 x86 + Python 3.7 机器上。
1 联网机器,查看安装好的包
C:\Python\Python37-32>python -m pip list
Package Version
--------------- ------------
beautifulsoup4 4.10.0
colorama 0.4.6
comtypes 1.2.0
et-xmlfile 1.1.0
jdcal 1.4.1
loguru 0.7.0
lxml 4.8.0
numpy 1.21.6
openpyxl 3.0.9
pandas 1.3.5
pip 20.1.1
python-dateutil 2.8.2
pytz 2023.3.post1
pywin32 306
pywinauto 0.6.8
selenium 3.14.1
setuptools 47.1.0
six 1.16.0
soupsieve 2.3.1
urllib3 1.26.8
win32-setctime 1.1.0
2 导出包列表
python -m pip freeze >requirements.txt
3 下载包
python -m pip download -r requirements.txt -d packages
4 内网机器,离线安装(复制 packages 和 requirements.txt)
python -m pip install --no-index --find-links=./packages -r ./requirements.txt
说明:
--find-links: 指定你的下载离线包的文件夹名称(里面有*.whl文件的地方的文件夹名称)
-r ./requirements.txt: 你的这个文件存放的地方
# 单独下载第三方包(clickhouse-driver 为例)
python -m pip download clickhouse-driver -d clickhouse
# 单独安装第三方包(clickhouse-driver 为例)
python -m pip install clickhouse-driver --no-index --find-links=./clickhouse
# 单独下载第三方包特定版本(clickhouse-connect 为例)
python -m pip download clickhouse-connect==0.6.22 -d clickhouse-connect
查看 包依赖
'''
其他:
01
批量卸载安装好的第三方包
python -m pip uninstall -r requirements.txt -y
02
pip freeze 导出的 requirements 可能含有路径 (@ file:///) 这种,可以使用 pip list 查看版本,将带路径的包改为 显示的版本。
03
经过实验,其实可以将 联网机器上的 Python 打包,直接拷贝到内网机器也可以使用。
'''
'''
参考:
https://blog.csdn.net/wtt234/article/details/128162292
'''