python 本地l離線安裝whl文件


記錄下無網絡時安裝Python環境

一: 單獨下載文件

 

1、下載whl離線文件到本地,放到c盤根目錄(任意位置均可,只是方便安裝)

https://pypi.org/

https://www.lfd.uci.edu/~gohlke/pythonlibs/(國內源,速度快。ctrl+f找到自己需要的文件)

 

2、 cmd到存放whl文件的目錄

 

3、pip安裝whl離線文件

pip install ****.whl 

(****.whl是我們下載的whl的文件名稱)

 

二、批量下載(使用requirements.txt文件,適用於公司為內網環境,可以先從外網下載,再拷貝到內網安裝)

1、pip freeze > requirements.txt

2、配置pip(pip安裝速度快的可以忽略這一步)

①在C:\Users\<你的電腦用戶名>\  新建一個文件夾 pip 

②在新建的pip目錄新建一個 pip.ini 文件,內容如下

[global]

index-url = https://mirrors.aliyun.com/pypi/simple/
extra-index-url = https://pypi.douban.com/simple/
timeout = 120

3、(請注意cmd當前路徑需包含requirements.txt文件)

先使用如下命令將包下載到本地(兩條命令都需要執行,第二條命令是對第一條命令的補充),此次是下載到dir目錄中

pip wheel -w DIR -r requirements.txt

pip download -d DIR -r requirements.txt

pip download --dest ./lib_data --no-deps --platform=manylinux2014_x86_64 --only-binary=:all: tensorflow

再將requirements.txt和dir目錄拷貝到離線環境,再使用這條命令安裝即可

pip install --no-index --find-links=DIR -r requirements.txt

 

如果給 pip download 命令添加選項 --platform、 --python-version、 --implementation 和 --abi 可以用於獲取解釋器和系統的依賴關系,而不是運行 pip 的解釋器和系統的依賴關系,當添加了這些選項時,也必須同時添加 --only-binary=:all: 或 --no-deps

 

 

pip download 和 pip wheel 的區別

I'm also curious about this question and the official doc is really ambiguous.

First, with my experiment, the two commands you provided will produce the same output, and the process is quite similar.

But after I read the official doc carefully, I find some options of these two commands is different.

  • for pip download, this command is focus on download packages from somewhere, even it will also try to built it, but it will fallback to download the source packge if it can't built it. There are some options for you to filter the packages you want to download, even the packages is not compatible with your current environment. like --platform--python-version--implementation, so you can download packges for whatever interpreter you want.

  • for pip wheel, this command is focus on build a wheel for package and it's dependencies. It provide an optio --build-option, let you custom the built process. So, with this command you can only download the packages that compatible with your current interpreter and platform.

In my opinion, pip wheel is more like pip install than pip download, cause it can only "download" the packages with current interpreter.


Now for your questions:

  1. Are then the two commands equivalent? (In this case this would look like replication of instructions, not really a good design principle uncle Guido!)

Ans: For packges compatible with current interpreter, yes, they are almost equivalent, except you want some built options.

  1. How can I achieve my goal of obtaining the whls required out of my python environment and ignoring any internet 'index's?

Ans: Both command can download from local index or a local directory, but if you want packages for other platform, pip download is needed. In your situation, you may create your own index or a directory holds all packages you needed and install from there every time.

Expect more precise answers.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM