如何离线安装软件包?

发布于 2025-01-12 04:21:01 字数 132 浏览 8 评论 0原文

从 pypi 下载 python 包及其依赖项以便在另一台计算机上离线安装的最佳方法是什么?有没有简单的方法可以使用 pip 或 easy_install 来做到这一点?我正在尝试在未连接到互联网的 FreeBSD 机器上安装 requests 库。

What's the best way to download a python package and its dependencies from pypi for offline installation on another machine? Is there any easy way to do this with pip or easy_install? I'm trying to install the requests library on a FreeBSD box that is not connected to the internet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(14

九公里浅绿 2025-01-19 04:21:01

在可以访问互联网的系统上

pip download 命令可让您下载软件包而不安装它们:(

pip download -r requirements.txt

在以前版本的 pip 中,拼写为 pip install --download -rrequirements.txt.)

在无法访问互联网的系统上

将下载的软件包复制到该系统中,然后您就可以用来

pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt

安装这些下载的模块,而无需访问网络。

On the system that has access to internet

The pip download command lets you download packages without installing them:

pip download -r requirements.txt

(In previous versions of pip, this was spelled pip install --download -r requirements.txt.)

On the system that has no access to internet

Copy over the downloaded packages to this system and then you can use

pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt

to install those downloaded modules, without accessing the network.

攒眉千度 2025-01-19 04:21:01

如果您想离线安装 python 库及其依赖项,请在具有相同操作系统、网络连接且安装了 python 的计算机上执行以下步骤:

  1. 创建一个 requirements.txt 文件,其内容如下(这些是您想要下载的库):
Flask==0.12
requests>=2.7.0
scikit-learn==0.19.1
numpy==1.14.3
pandas==0.22.0

创建需求文件的一种选择是使用 pip freeze >requirements.txt。这将列出您环境中的所有库。然后你可以进入requirements.txt并删除不需要的。

  1. 执行命令mkdir driverhouse && pip download -rrequirements.txt -dwheelhouse 将库及其依赖项下载到目录wheelhouse

  2. 将requirements.txt复制到wheelhouse目录

  3. 使用tar -zcfwheelhouse.tar.gzwheelhouse将wheelhouse存档到wheelhouse.tar.gz< /p>

,然后上传 wheelhouse.tar.gz 到您的目标计算机:

  1. 执行tar -zxfwheelhouse.tar.gz解压文件

  2. 执行 pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse 安装库及其依赖项

If you want install python libs and their dependencies offline, follow these steps on a machine with the same os, network connected, and python installed:

  1. Create a requirements.txt file with content like this (these are the libraries you wish to download):
Flask==0.12
requests>=2.7.0
scikit-learn==0.19.1
numpy==1.14.3
pandas==0.22.0

One option for creating the requirements file is to use pip freeze >requirements.txt. This will list all libraries in your environment. Then you can go in to requirements.txt and remove the unnecessary ones.

  1. Execute command mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse to download libs and their dependencies to directory wheelhouse

  2. Copy requirements.txt into wheelhouse directory

  3. Archive wheelhouse into wheelhouse.tar.gz with tar -zcf wheelhouse.tar.gz wheelhouse

Then upload wheelhouse.tar.gz to your target machine:

  1. Execute tar -zxf wheelhouse.tar.gz to extract the files

  2. Execute pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse to install the libs and their dependencies

双马尾 2025-01-19 04:21:01

如果包位于 PYPI 上,请将其及其依赖项下载到某个本地目录。
例如,

$ mkdir /pypi && cd /pypi
$ ls -la
  -rw-r--r--   1 pavel  staff   237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz
  -rw-r--r--   1 pavel  staff   389741 Feb 22 17:10 Jinja2-2.6.tar.gz
  -rw-r--r--   1 pavel  staff    70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz
  -rw-r--r--   1 pavel  staff  2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz
  -rw-r--r--   1 pavel  staff  1108056 Feb 22 17:10 Werkzeug-0.8.2.tar.gz
  -rw-r--r--   1 pavel  staff   488207 Apr 10 18:26 boto-2.3.0.tar.gz
  -rw-r--r--   1 pavel  staff   490192 Apr 16 12:00 flask-0.9-dev-2a6c80a.tar.gz

某些包可能必须手动归档到类似的 tarball 中。当我想要某个东西的更新(不太稳定)版本时,我经常这样做。有些软件包不在 PYPI 上,因此同样适用于它们。

假设您在 ~/src/myapp 中有一个格式正确的 Python 应用程序。 ~/src/myapp/setup.py 将包含 install_requires 列表,其中提及 /pypi 目录中的一项或多项内容。像这样:

  install_requires=[
    'boto',
    'Flask',
    'Werkzeug',
    # and so on

如果您希望能够运行具有所有必要依赖项的应用程序,同时仍然对其进行黑客攻击,您将执行以下操作:

$ cd ~/src/myapp
$ python setup.py develop --always-unzip --allow-hosts=None --find-links=/pypi

这样您的应用程序将直接从源目录执行。您可以破解一些东西,然后重新运行应用程序而无需重建任何内容。

如果您想将应用程序及其依赖项安装到当前的 python 环境中,您将执行以下操作:

$ cd ~/src/myapp
$ easy_install --always-unzip --allow-hosts=None --find-links=/pypi .

在这两种情况下,如果 /pypi 目录。它不会尝试从互联网上随意安装丢失的东西。

我强烈建议在活动的 虚拟环境以避免污染您的全局Python环境。这就是(virtualenv)几乎要走的路。切勿将任何东西安装到全局 Python 环境中。

如果您构建应用程序的计算机与要部署应用程序的计算机具有相同的架构,则只需将所有内容 easy_install 压缩到整个虚拟环境目录即可。不过,在打包之前,您必须使虚拟环境目录可重定位(请参阅 --relocatable 选项)。 注意:目标计算机需要安装相同版本的 Python,并且您的应用程序可能具有的任何基于 C 的依赖项也必须预先安装在那里(例如,如果您依赖于 PIL,然后必须预安装libpng、libjpeg等)。

If the package is on PYPI, download it and its dependencies to some local directory.
E.g.

$ mkdir /pypi && cd /pypi
$ ls -la
  -rw-r--r--   1 pavel  staff   237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz
  -rw-r--r--   1 pavel  staff   389741 Feb 22 17:10 Jinja2-2.6.tar.gz
  -rw-r--r--   1 pavel  staff    70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz
  -rw-r--r--   1 pavel  staff  2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz
  -rw-r--r--   1 pavel  staff  1108056 Feb 22 17:10 Werkzeug-0.8.2.tar.gz
  -rw-r--r--   1 pavel  staff   488207 Apr 10 18:26 boto-2.3.0.tar.gz
  -rw-r--r--   1 pavel  staff   490192 Apr 16 12:00 flask-0.9-dev-2a6c80a.tar.gz

Some packages may have to be archived into similar looking tarballs by hand. I do it a lot when I want a more recent (less stable) version of something. Some packages aren't on PYPI, so same applies to them.

Suppose you have a properly formed Python application in ~/src/myapp. ~/src/myapp/setup.py will have install_requires list that mentions one or more things that you have in your /pypi directory. Like so:

  install_requires=[
    'boto',
    'Flask',
    'Werkzeug',
    # and so on

If you want to be able to run your app with all the necessary dependencies while still hacking on it, you'll do something like this:

$ cd ~/src/myapp
$ python setup.py develop --always-unzip --allow-hosts=None --find-links=/pypi

This way your app will be executed straight from your source directory. You can hack on things, and then rerun the app without rebuilding anything.

If you want to install your app and its dependencies into the current python environment, you'll do something like this:

$ cd ~/src/myapp
$ easy_install --always-unzip --allow-hosts=None --find-links=/pypi .

In both cases, the build will fail if one or more dependencies aren't present in /pypi directory. It won't attempt to promiscuously install missing things from Internet.

I highly recommend to invoke setup.py develop ... and easy_install ... within an active virtual environment to avoid contaminating your global Python environment. It is (virtualenv that is) pretty much the way to go. Never install anything into global Python environment.

If the machine that you've built your app has same architecture as the machine on which you want to deploy it, you can simply tarball the entire virtual environment directory into which you easy_install-ed everything. Just before tarballing though, you must make the virtual environment directory relocatable (see --relocatable option). NOTE: the destination machine needs to have the same version of Python installed, and also any C-based dependencies your app may have must be preinstalled there too (e.g. say if you depend on PIL, then libpng, libjpeg, etc must be preinstalled).

他夏了夏天 2025-01-19 04:21:01

让我逐步完成该过程:

  1. 在连接到互联网的计算机上,创建一个文件夹。
   $ mkdir packages
   $ cd packages
  1. 打开命令提示符或 shell 并执行以下命令:

    假设你想要的包是 tensorflow

    $ pip download tensorflow

  2. 现在,在目标计算机上,复制 packages 文件夹并应用以下命令

  $ cd packages
  $ pip install 'tensorflow-xyz.whl' --no-index --find-links '.'

注意,tensorflow-xyz.whl 必须替换为所需包的原始名称。

Let me go through the process step by step:

  1. On a computer connected to the internet, create a folder.
   $ mkdir packages
   $ cd packages
  1. open up a command prompt or shell and execute the following command:

    Suppose the package you want is tensorflow

    $ pip download tensorflow

  2. Now, on the target computer, copy the packages folder and apply the following command

  $ cd packages
  $ pip install 'tensorflow-xyz.whl' --no-index --find-links '.'

Note that the tensorflow-xyz.whl must be replaced by the original name of the required package.

压抑⊿情绪 2025-01-19 04:21:01

离线Python。为此,我使用 virtualenv (隔离的 Python 环境)

1) 安装 virtualenv
使用 pip 在线:

pip install virtualenv --user

或使用 whl 离线:转到此 链接 ,下载最新版本(.whl 或tar.gz)并使用此命令安装它:

pip install virtualenv-15.1.0-py2.py3-none-any.whl --user

通过使用 --user 您不需要使用 sudo pip...

2) 在在线机器上使用 virtualenv

使用终端 cd 选择一个目录并运行此代码:

python -m virtualenv myenv
cd myenv
source bin/activate
pip install Flask

安装所有软件包后,您必须生成一个 requirements.txt 所以当您的 virtualenv处于活动状态,请写入

pip freeze > requirements.txt

打开一个新终端并创建另一个环境,例如 myenv2

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
ls

现在您可以转到离线文件夹,其中有 requirements.txttranferred_pa​​ckages 文件夹。使用以下代码下载软件包并将其全部放入 tranferred_pa​​ckages 文件夹中。

pip download -r requirements.txt

将您的离线文件夹带到离线计算机,然后

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
cd offline
pip install --no-index --find-links="./tranferred_packages" -r requirements.txt

离线文件夹中的内容 [requirements.txt , tranferred_pa​​ckages {Flask-0.10.1.tar.gz, ...}]

检查您的包注释列表

pip list

:就像我们在 2017 年一样最好使用 python 3。您可以使用此命令创建 python 3 virtualenv。

virtualenv -p python3 envname

offline python. for doing this I use virtualenv (isolated Python environment)

1) install virtualenv
online with pip:

pip install virtualenv --user

or offline with whl: go to this link , download last version (.whl or tar.gz) and install that with this command:

pip install virtualenv-15.1.0-py2.py3-none-any.whl --user

by using --user you don't need to use sudo pip….

2) use virtualenv

on online machine select a directory with terminal cd and run this code:

python -m virtualenv myenv
cd myenv
source bin/activate
pip install Flask

after installing all the packages, you have to generate a requirements.txt so while your virtualenv is active, write

pip freeze > requirements.txt

open a new terminal and create another env like myenv2.

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
ls

now you can go to your offline folder where your requirements.txt and tranferred_packages folder are in there. download the packages with following code and put all of them to tranferred_packages folder.

pip download -r requirements.txt

take your offline folder to offline computer and then

python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
cd offline
pip install --no-index --find-links="./tranferred_packages" -r requirements.txt

what is in the folder offline [requirements.txt , tranferred_packages {Flask-0.10.1.tar.gz, ...}]

check list of your package

pip list

note: as we are in 2017 it is better to use python 3. you can create python 3 virtualenv with this command.

virtualenv -p python3 envname
坠似风落 2025-01-19 04:21:01

我有类似的问题。我必须以与 pypi 相同的方式安装它。

我做了以下事情:

  1. 创建一个目录来存储可以访问互联网的计算机中的所有包。

    mkdir -p /path/to/packages/
    
  2. 下载所有包到该路径

编辑:您也可以尝试:

python3 -m pip wheel --no-cache-dir -rrequirements.txt -w /path/to/packages
pip download -r requirements.txt -d /path/to/packages

Eg:- ls /root/wheelhouse/  # **/root/wheelhouse** is my **/path/to/packages/**
total 4524
-rw-r--r--. 1 root root   16667 May 23  2017 incremental-17.5.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   34713 Sep  1 10:21 attrs-18.2.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 3088398 Oct 15 14:41 Twisted-18.9.0.tar.bz2
-rw-r--r--. 1 root root  133356 Jan 28 15:58 chardet-3.0.4-py2.py3-none-any.whl
-rw-r--r--. 1 root root  154154 Jan 28 15:58 certifi-2018.11.29-py2.py3-none-any.whl
-rw-r--r--. 1 root root   57987 Jan 28 15:58 requests-2.21.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   58594 Jan 28 15:58 idna-2.8-py2.py3-none-any.whl
-rw-r--r--. 1 root root  118086 Jan 28 15:59 urllib3-1.24.1-py2.py3-none-any.whl
-rw-r--r--. 1 root root   47229 Jan 28 15:59 tqdm-4.30.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root    7922 Jan 28 16:13 constantly-15.1.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root  164706 Jan 28 16:14 zope.interface-4.6.0-cp27-cp27mu-manylinux1_x86_64.whl
-rw-r--r--. 1 root root  573841 Jan 28 16:14 setuptools-40.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   37638 Jan 28 16:15 Automat-0.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   37905 Jan 28 16:15 hyperlink-18.0.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   52311 Jan 28 16:15 PyHamcrest-1.9.0-py2.py3-none-any.whl
 -rw-r--r--. 1 root root   10586 Jan 28 16:15 six-1.12.0-py2.py3-none-any.whl
  1. Tar 软件包目录并将其复制到无法访问互联网的计算机。然后做,

    cd /path/to/packages/
    tar -cvzfpackages.tar.gz 。 # 不是 . (点)在最后
    

packages.tar.gz 复制到无法访问互联网的目标计算机中。

  1. 在无法访问 Internet 的计算机中,执行以下操作(假设您将 tarred 包复制到当前计算机中的 /path/to/package/

    cd /path/to/packages/
    tar -xvzf 软件包.tar.gz
    mkdir -p $HOME/.config/pip/
    vi $HOME/.config/pip/pip.conf
    

并将以下内容粘贴到其中并保存。

[global]
timeout = 10
find-links = file:///path/to/package/
no-cache-dir = true
no-index = true
  1. 最后,我建议您使用某种形式的 virtualenv 来安装软件包。

    virtualenv -p python2 venv # 使用 python3,如果你使用的是 python3
    来源 ./venv/bin/activate
    pip install ;
    

您应该能够下载目录 /path/to/package/ 中的所有模块。

注意:我只这样做了,因为我无法添加选项或更改我们安装模块的方式。不然我就这么做了

pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt

I had a similar problem. And i had to make it install the same way, we do from pypi.

I did the following things:

  1. Make a directory to store all the packages in the machine that have internet access.

    mkdir -p /path/to/packages/
    
  2. Download all the packages to the path

Edit: You can also try:

python3 -m pip wheel --no-cache-dir -r requirements.txt -w /path/to/packages
pip download -r requirements.txt -d /path/to/packages

Eg:- ls /root/wheelhouse/  # **/root/wheelhouse** is my **/path/to/packages/**
total 4524
-rw-r--r--. 1 root root   16667 May 23  2017 incremental-17.5.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   34713 Sep  1 10:21 attrs-18.2.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 3088398 Oct 15 14:41 Twisted-18.9.0.tar.bz2
-rw-r--r--. 1 root root  133356 Jan 28 15:58 chardet-3.0.4-py2.py3-none-any.whl
-rw-r--r--. 1 root root  154154 Jan 28 15:58 certifi-2018.11.29-py2.py3-none-any.whl
-rw-r--r--. 1 root root   57987 Jan 28 15:58 requests-2.21.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   58594 Jan 28 15:58 idna-2.8-py2.py3-none-any.whl
-rw-r--r--. 1 root root  118086 Jan 28 15:59 urllib3-1.24.1-py2.py3-none-any.whl
-rw-r--r--. 1 root root   47229 Jan 28 15:59 tqdm-4.30.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root    7922 Jan 28 16:13 constantly-15.1.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root  164706 Jan 28 16:14 zope.interface-4.6.0-cp27-cp27mu-manylinux1_x86_64.whl
-rw-r--r--. 1 root root  573841 Jan 28 16:14 setuptools-40.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   37638 Jan 28 16:15 Automat-0.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   37905 Jan 28 16:15 hyperlink-18.0.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root   52311 Jan 28 16:15 PyHamcrest-1.9.0-py2.py3-none-any.whl
 -rw-r--r--. 1 root root   10586 Jan 28 16:15 six-1.12.0-py2.py3-none-any.whl
  1. Tar the packages directory and copy it to the Machine that doesn't have internet access. Then do,

    cd /path/to/packages/
    tar -cvzf packages.tar.gz .  # not the . (dot) at the end
    

Copy the packages.tar.gz into the destination machine that doesn't have internet access.

  1. In the machine that doesn't have internet access, do the following (Assuming you copied the tarred packages to /path/to/package/ in the current machine)

    cd /path/to/packages/
    tar -xvzf packages.tar.gz
    mkdir -p $HOME/.config/pip/
    vi $HOME/.config/pip/pip.conf
    

and paste the following content inside and save it.

[global]
timeout = 10
find-links = file:///path/to/package/
no-cache-dir = true
no-index = true
  1. Finally, i suggest you use, some form of virtualenv for installing the packages.

    virtualenv -p python2 venv # use python3, if you are on python3
    source ./venv/bin/activate
    pip install <package>
    

You should be able to download all the modules that are in the directory /path/to/package/.

Note: I only did this, because i couldn't add options or change the way we install the modules. Otherwise i'd have done

pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
看海 2025-01-19 04:21:01

对于具有另一个 Python 版本的另一个平台

要下载另一个平台的 python 包,您需要将 --platform 参数[1]--only- 结合​​使用binary=:all: 参数。要同时定义目标系统的 Python 版本,请使用 --python-version 参数。

示例场景:您在 Windows 上,想要下载适用于使用 Python 3.9 的 Linux 系统的 numpy。使用以下命令下载 numpy 及其目标系统的所有依赖项:

pip download --platform=manylinux1_x86_64 --only-binary=:all: --python-version=3.9 numpy

要在目标系统上安装 numpy,请将下载的文件复制到其中并通过以下方式安装软件包:

pip install --no-index --find-links /path/to/package/files numpy

您还可以为这两个命令使用需求文件,而不是定义特定的包名称。例如,只需将包名称替换为 -rrequirements.txt 即可。


[1] 查找正确的平台字符串可能很乏味。您可以在目标系统上执行以下命令来开始:
python -c“导入sysconfig; print(sysconfig.get_platform().replace('-','_').replace('.','_'))”
对于 Linux,您最好在此处查找合适的平台字符串。
但最终,这完全取决于该软件包的维护者是否实际上为特定平台构建了它。您可以通过查看特定包的文件并检查轮子文件的后缀及其标签来查找,例如: numpy 文件

For another platform with another Python version

To download python packages for another platform, you need the --platform parameter[1] in combination with the --only-binary=:all: parameter. To also define the Python version of the target system, use the --python-version parameter.

Example scenario: You are on Windows and want to download numpy for a Linux system that uses Python 3.9. Use the following command to download numpy with all its dependencies for your target system:

pip download --platform=manylinux1_x86_64 --only-binary=:all: --python-version=3.9 numpy

To install numpy on your target system, copy the downloaded files to it and install the package via:

pip install --no-index --find-links /path/to/package/files numpy

Instead of defining a particular package name, you can also use a requirements file for both commands. Just replace the package name by -r requirements.txt, for example.


[1] It can be tedious to find the correct platform string. You can execute the following command on your target system to get a start:
python -c "import sysconfig; print(sysconfig.get_platform().replace('-','_').replace('.','_'))".
For Linux, you better look here for a suitable platform string.
But in the end, it all depends on if the maintainers of the package actually built it for a particular platform. You can look that up by viewing the files of the particular package and by checking the suffixes of the wheel files and their tags, e. g.: numpy files.

沫离伤花 2025-01-19 04:21:01

下载 tarball,将其传输到您的 FreeBSD 计算机并解压,然后运行 ​​python setup.py install 就完成了!

编辑:除此之外,您现在还可以使用 pip 安装 tarball。

Download the tarball, transfer it to your FreeBSD machine and extract it, afterwards run python setup.py install and you're done!

EDIT: Just to add on that, you can also install the tarballs with pip now.

腻橙味 2025-01-19 04:21:01

使用wheel编译的包。

捆绑:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)

复制 tarball 并安装:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*

注意 wheel 二进制包不能跨机器。

更多参考。这里: https://pip.pypa.io/en/stable/user_guide/ #安装包

Using wheel compiled packages.

bundle up:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)

copy tarball and install:

$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*

Note wheel binary packages are not across machines.

More ref. here: https://pip.pypa.io/en/stable/user_guide/#installation-bundles

玉环 2025-01-19 04:21:01

对于 Windows,我使用了以下内容

Internet 连接

1.创建任意名称的目录。我使用“repo”创建了

2.使用以下命令下载库(它将下载而不是安装)

pip download libraray_name -d "C:\repo"

pip download openpyxl -d"C:\repo"
  1. 然后你会发现多个.whl扩展文件

  2. 复制requirements.txt中的所有文件名
    输入图片此处描述

没有互联网连接

  1. 现在将此文件夹和文件移动到没有互联网连接的电脑并运行以下命令。
pip install -r requirements.txt --find-links=C:\repo --no-index

您可以阅读详细博客链接

For Windows I have used below things

Internet Connection

1.Create directory with any name.I have created with "repo"

2.Download libraries using below command (it will download not install)

pip download libraray_name -d"C:\repo"

pip download openpyxl -d"C:\repo"
  1. Then you will find multiple .whl extension files

  2. copy all the filename in requirements.txt
    enter image description here

No Internet Connection

  1. Now Move this folder and files to PC where no internet connection and run the below command.
pip install -r requirements.txt --find-links=C:\repo --no-index

You can read the detailed blog Link

话少心凉 2025-01-19 04:21:01

作为@chaokunyang 的继续回答,我想将我编写的完成工作的脚本放在这里:

  1. 编写一个“requirements.txt”文件,指定要打包的库。
  2. 创建一个包含所有库的 tar 文件(请参阅 Packer 脚本)。
  3. 将创建的 tar 文件放入目标机器并解压。
  4. 运行安装程序脚本(也打包到 tar 文件中)。

“requirements.txt”文件

docker==4.4.0

打包端:文件名:“create-offline-python3.6-dependency-repository.sh”

#!/usr/bin/env bash

# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983

LIBRARIES_DIR="python3.6-wheelhouse"

if [ -d ${LIBRARIES_DIR} ]; then
    rm -rf ${LIBRARIES_DIR}/*
else
    mkdir ${LIBRARIES_DIR}
fi

pip download -r requirements.txt -d ${LIBRARIES_DIR}

files_to_add=("requirements.txt" "install-python-libraries-offline.sh")

for file in "${files_to_add[@]}"; do
    echo "Adding file ${file}"
    cp "$file" ${LIBRARIES_DIR}
done

tar -cf ${LIBRARIES_DIR}.tar ${LIBRARIES_DIR}

安装端:文件名:“install-python-libraries-offline.sh”

#!/usr/bin/env bash

# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983

# This file should run during the installation process from inside the libraries directory, after it was untared:
# pythonX-wheelhouse.tar -> untar -> pythonX-wheelhouse
# |
# |--requirements.txt
# |--install-python-libraries-offline.sh


pip3 install -r requirements.txt --no-index --find-links .

As a continues to @chaokunyang answer, I want to put here the script I write that does the work:

  1. Write a "requirements.txt" file that specifies the libraries you want to pack.
  2. Create a tar file that contains all your libraries (see the Packer script).
  3. Put the created tar file in the target machine and untar it.
  4. run the Installer script (which is also packed into the tar file).

"requirements.txt" file

docker==4.4.0

Packer side: file name: "create-offline-python3.6-dependencies-repository.sh"

#!/usr/bin/env bash

# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983

LIBRARIES_DIR="python3.6-wheelhouse"

if [ -d ${LIBRARIES_DIR} ]; then
    rm -rf ${LIBRARIES_DIR}/*
else
    mkdir ${LIBRARIES_DIR}
fi

pip download -r requirements.txt -d ${LIBRARIES_DIR}

files_to_add=("requirements.txt" "install-python-libraries-offline.sh")

for file in "${files_to_add[@]}"; do
    echo "Adding file ${file}"
    cp "$file" ${LIBRARIES_DIR}
done

tar -cf ${LIBRARIES_DIR}.tar ${LIBRARIES_DIR}

Installer side: file name: "install-python-libraries-offline.sh"

#!/usr/bin/env bash

# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983

# This file should run during the installation process from inside the libraries directory, after it was untared:
# pythonX-wheelhouse.tar -> untar -> pythonX-wheelhouse
# |
# |--requirements.txt
# |--install-python-libraries-offline.sh


pip3 install -r requirements.txt --no-index --find-links .
余生共白头 2025-01-19 04:21:01

对于 Pip 8.1.2,您可以使用 pip download -r requ.txt 将软件包下载到本地计算机。

For Pip 8.1.2 you can use pip download -r requ.txt to download packages to your local machine.

谁许谁一生繁华 2025-01-19 04:21:01

从 Pypi 下载轮文件(例如 dlb-0.5.0-py3-none-any.whl)并

pip install dlb-0.5.0-py3-none-any.whl

Download the wheel file (for example dlb-0.5.0-py3-none-any.whl) from Pypi and

pip install dlb-0.5.0-py3-none-any.whl
盛装女皇 2025-01-19 04:21:01

我发现了一种更简单的方法,根本不涉及 pip。

只需将 site-packages 文件夹从在线计算机复制到离线计算机即可。

我在 %USERPROFILE%\AppData\Local\Programs\Python\Python312\Lib\site-packages\ 中找到了我的。有关位置,请参阅 pip 在哪里安装其软件包?

然后,我将 site-packages 文件夹压缩到 site-packages.zip,进行传输,然后将所有丢失的包复制到另一台计算机的 site-packages 文件夹中。之后就成功了。

最好确保两台计算机上的 python 版本相同

I found a much simpler way that does not involve pip at all.

Just copy the site-packages folder from your online machine to the offline one.

I found mine in %USERPROFILE%\AppData\Local\Programs\Python\Python312\Lib\site-packages\. See Where does pip install its packages? for the location.

I then zipped the site-packages folder to site-packages.zip, transferred it, and then copied any missing packages to the other computer's site-packages folder. After that it worked.

Best make sure your python versions are the same on both computers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文