python - 离线安装模块

python模块下载:
https://pypi.org/
https://www.lfd.uci.edu/~gohlke/pythonlibs/
http://mirrors.aliyun.com/pypi/simple/
python官网:https://www.python.org/

whl is not a supported wheel on this platform.解决办法:https://blog.csdn.net/t18438605018/article/details/121769227
pycharm配置python环境(改为安装python程序的路径,即可使用python已安装的模块):https://jingyan.baidu.com/article/e75057f21d6cd1aac81a8934.html

查询自己的python安装路径的exe/app文件位置

  • window:where python
  • macos:which python3.7

查看当前平台支持的版本:pip3.7 debug --verbose
安装模块:pip3.7 install xxx
查看已经安装模块的版本:pip3.7 list

cp37表示自己的python版本是3.7,cp36则表示python版本是3.6;
macosx表示苹果系统,win32表示Windows32位(马上要淘汰了),win_amd64表示Windows64位(大多数人用的),manylinux表示Linux系统。

更新pip工具包:python -m pip install --upgrade pip

离线更新pip工具包

1. 首先使用命令查看当前平台支持的版本:pip debug --verbose

(如果下载的模块不是当前平台支持的版本,会报错whl is not a supported wheel on this platform)

Compatible tags: 826
  cp37-cp37m-macosx_10_11_x86_64
  cp37-cp37m-macosx_10_11_intel
  cp37-cp37m-macosx_10_11_fat64
  cp37-cp37m-macosx_10_11_fat32
  cp37-cp37m-macosx_10_11_universal2
  cp37-cp37m-macosx_10_11_universal
  ......
  cp37-none-any
  py37-none-any
  py3-none-any
  py36-none-any
  py35-none-any
  py34-none-any
  py33-none-any
  py32-none-any
  py31-none-any
  py30-none-any

2. 打开网页https://pypi.org/project/查找需要离线安装的模块

python - 离线安装模块_第1张图片
查看历史版本
python - 离线安装模块_第2张图片
对照平台支持的版本,查看是否能安装,能即可点击下载。
python - 离线安装模块_第3张图片

3. 下载离线包后在终端打指令:pip3.7 install 离线包路径…/xxx.whl

如果安装失败,可以查看是否缺失依赖包,根据提示的下载依赖的模块,安装依赖模块后再次安装初始的模块,如仍然提示缺失,则重复前面的步骤直至提示安装成功。
可以向下兼容,如cp37的可以安装cp36。

安装bs4模块

pip3.7 install …/bs4-0.0.1.tar.gz

报错可以看出,缺失beautifulsoup4模块:
OSError(‘Tunnel connection failed: 407 Proxy Authentication Required’))': /simple/beautifulsoup4/
ERROR: Could not find a version that satisfies the requirement beautifulsoup4 (from bs4) (from versions: none)
ERROR: No matching distribution found for beautifulsoup4

pip3.7 install …/beautifulsoup4-4.11.2-py3-none-any.whl

报错可以看出,缺失soupsieve模块:
OSError(‘Tunnel connection failed: 407 Proxy Authentication Required’))': /simple/soupsieve/
ERROR: Could not find a version that satisfies the requirement soupsieve>1.2 (from beautifulsoup4) (from versions: none)
ERROR: No matching distribution found for soupsieve>1.2

pip3.7 install …/soupsieve-2.4-py3-none-any.whl

最后安装好soupsieve,再安装beautifulsoup4,最终bs4即可安装成功。
Successfully installed soupsieve-2.4
Successfully installed beautifulsoup4-4.11.2
Successfully installed bs4-0.0.1

import sys
sys.path	# 列出搜索路径(一组目录)
sys.path.append('path')	# 把模块所在的位置添加到搜索路径中

安装pyinstaller模块

mac默认安装了python2.7,所以要在pip前面加安装的版本。
pip3.7 debug --verbose

pip3.7 install …/pyinstaller-5.8.0-py3-none-macosx_10_13_universal2.whl

报错可以看出,setuptools模块版本等级太低:
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProxyError(‘Cannot connect to proxy.’, OSError(‘Tunnel connection failed: 407 Proxy Authentication Required’))’: /simple/setuptools/
ERROR: Could not find a version that satisfies the requirement setuptools>=42.0.0 (from pyinstaller) (from versions: none)
ERROR: No matching distribution found for setuptools>=42.0.0

查看已经安装模块的版本:pip3.7 list

要求:setuptools>=42.0.0
查到的:setuptools 41.2.0

pip3.7 install /setuptools-67.5.0-py3-none-any.whl

报错可以看出,缺失importlib-metadata模块:
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘ProxyError(‘Cannot connect to proxy.’, OSError(‘Tunnel connection failed: 407 Proxy Authentication Required’))’: /simple/importlib-metadata/

根据最后一个WARNING提示,安装依赖包。直至安装完成。
更新模块,依赖包:
pip-23.0.1-py3-none-any.whl
setuptools-67.5.0-py3-none-any.whl

importlib_metadata-6.0.0-py3-none-any.whl
typing_extensions-4.5.0-py3-none-any.whl
zipp-3.15.0-py3-none-any.whl
pyinstaller_hooks_contrib-2023.0-py2.py3-none-any.whl
macholib-1.16.2-py2.py3-none-any.whl
altgraph-0.17.3-py2.py3-none-any.whl
pyinstaller-5.8.0-py3-none-macosx_10_13_universal2.whl

你可能感兴趣的:(python,python,开发语言,pycharm)