简体   繁体   English

在服务器上离线安装python软件包

[英]Install python packages offline on server

I want to install some packages on the server which does not access to internet. 我想在无法访问互联网的服务器上安装一些软件包。 so I have to take packages and send them to the server. 所以我必须拿包并将其发送到服务器。 But I do not know how can I install them. 但是我不知道如何安装它们。

You can either download the packages from the website and run python setup.py install . 您可以从网站下载软件包,然后运行python setup.py install Or you can run a pip install on a local dir, such as : 或者,您可以在本地目录上运行pip install ,例如:

pip install path/to/tar/ball

https://pip.pypa.io/en/stable/reference/pip_install/#usage https://pip.pypa.io/zh_CN/stable/reference/pip_install/#usage

Download all the packages you need and send them to the server where you need to install them. 下载所需的所有软件包,并将它们发送到需要安装它们的服务器。 It doesn't matter if they have *whl or *tar.gz extension. 它们是否具有*whl*tar.gz扩展名都没有关系。 Then install them one by one using pip : 然后使用pip逐一安装它们:

pip install path/to/package

or: 要么:

python -m pip install path/to/package

The second option is useful if you have multiple interpreters on the server (eg python2 and python3 or multiple versions of either of them). 如果服务器上有多个解释器(例如python2和python3或它们中的任何一个的多个版本),则第二个选项很有用。 In such case replace python with the one you want to use, eg: 在这种情况下,请将python替换为您要使用的python ,例如:

python3 -m pip install path/to/package

If you have a lot of packages, you can list them in a requirement file as you would normally do when you have access to the internet. 如果您有很多软件包,则可以像在访问Internet时通常所做的那样在需求文件中列出它们。 Then instead of putting the names of the packages into the file, put the paths to the packages (one path per line). 然后,不要将软件包的名称放入文件中,而应将软件包的路径放入(每行一个路径)。 When you have the file, install all packages by typing: 拥有文件后,通过键入以下命令安装所有软件包:

python -m pip install -r requirements.txt

In the requirements file you can also mix between different types of the packages ( *whl and *tar.gz ). 在需求文件中,您还可以在不同类型的软件包之间混合使用( *whl*tar.gz )。 The only thing to take care about is to download the correct versions of the packages you need for the platform you have (64bit packages for 64bit platform etc.). 唯一需要注意的是下载所拥有平台所需的正确版本的软件包(用于64位平台的64位软件包等)。

You can find more information regarding pip install in its documentation . 您可以在其文档中找到有关pip install更多信息。

Download the wheel packages from https://www.lfd.uci.edu/~gohlke/pythonlibs/ . https://www.lfd.uci.edu/~gohlke/pythonlibs/下载wheel包。 You may install the .whl packages by pip install (package.whl) , refer installing wheels using pip for more. 您可以通过pip install (package.whl)安装.whl软件包,有关更多信息,请参阅使用pip安装轮子

Download the package from website and extract the tar ball. 从网站上下载软件包并解压缩tar球。 run python setup.py install 运行python setup.py install

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM