Python教程

python 本地l离线安装whl文件

本文主要是介绍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

再将requirements.txt和dir目录拷贝到离线环境,再使用这条命令安装即可

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

 

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.

这篇关于python 本地l离线安装whl文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!