我试图在Python3.9+pip22.2.1环境下使用requirement.txt离线保存库,并迁移到另一处电脑离线安装。但在安装 pyautogui 这个库的时候遇到了下面这个报错:

(For Eng user: When I was trying to install the package pyautogui offline, by download in one PC, copy-paste and install in another PC, I meet the following error, it can be solved by adding a pyautogui --no-build-isolation parameter after pip install pip install --no-index --find-links="/yourpath" -r requirements.txt command.)

反复查询发现是pip在安装每个包时会建立一个隔离环境自动获取依赖项,而离线安装时依赖项不能这样获取,因此要在安装时加上 pyautogui --no-build-isolation 参数,下面是一个示例代码:

# install and download package in a new venv
virtualenv venv
.\venv\Scripts\activate.ps1
pip install pyautogui
pip freeze > .\requirements.txt
cd ".\dependent file"
pip download -r "..\requirements.txt"
cd "..\"

# in another PC, install pyautogui offline
# delete .\venv
virtualenv venv
.\venv\Scripts\activate.ps1
pip install --no-index --find-links="./dependent file" -r requirements.txt

# raise error like this:
'''
  error: subprocess-exited-with-error

  × pip subprocess to install build dependencies did not run successfully.
  │ exit code: 1
  ╰─> [3 lines of output]
      Looking in links: ./dependent file
      ERROR: Could not find a version that satisfies the requirement setuptools>=40.8.0 (from versions: none)
      ERROR: No matching distribution found for setuptools>=40.8.0
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
'''

# replace the install command to this can solve this problem:
pip install --no-index --find-links="./dependent file" -r requirements.txt pyautogui --no-build-isolation

解决方案来源:pip install pymsgbox offline always failed

–no-build-isolation 参数的作用:what does no-build-isolation do?

类似文章

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

一条评论