Установка пакетов python offline

installing python packages without internet and using source code as .tar.gz and .whl

For that we have the packages downloaded from https://pypi.python.org/pypi/python-keystoneclient/1.7.1 and kept it in server. However, while installing tar.gz and .whl packages , the installation is looking for dependent packages to be installed first. Since there is no internet connection in the server, it is getting failed. For ex : For python-keystoneclient we have the following dependent packages

stevedore (>=1.5.0) six (>=1.9.0) requests (>=2.5.2) PrettyTable (=0.7) oslo.utils (>=2.0.0) oslo.serialization (>=1.4.0) oslo.i18n (>=1.5.0) oslo.config (>=2.3.0) netaddr (!=0.7.16,>=0.7.12) debtcollector (>=0.3.0) iso8601 (>=0.1.9) Babel (>=1.3) argparse pbr (=1.6) 

When i try to install packages one by one from the above list, once again its looking for nested dependency . Is there any way we could list ALL the dependent packages for installing a python module like python-keystoneclient.

8 Answers 8

This is how I handle this case:

On the machine where I have access to Internet:

mkdir keystone-deps pip download python-keystoneclient -d "/home/aviuser/keystone-deps" tar cvfz keystone-deps.tgz keystone-deps 

Then move the tar file to the destination machine that does not have Internet access and perform the following:

tar xvfz keystone-deps.tgz cd keystone-deps pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index 

You may need to add —no-deps to the command as follows:

pip install python_keystoneclient-2.3.1-py2.py3-none-any.whl -f ./ --no-index --no-deps 

This could be updated with the «download» option of pip. Additionally, it would be nice to have an explanation of the pip option «no-index».

Читайте также:  Java parsing iso date

@GianlucaD’Ardia — I downloaded a pip wheel as well and you can install it using itself with the following (trippy) command: python ~/eggs/pip-9.0.1-py2.py3-none-any.whl/pip install —no-index ~/eggs/pip-9.0.1-py2.py3-none-any.whl (replace the version particulars with your wheel’s specifics)

To add some details: pip install —help indicates that: (1) -f or —find-links means . If a local path or file:// url that’s a directory, then look for archives in the directory listing. , so here it locates the files in this dir; (2) —no-index means Ignore package index (only looking at —find-links URLs instead). So pip install xxx.whl -f ./ —no-index means: find install files in the current dir instead of searching in remote repo.

To avoid platform issues, you can try to use universal wheels if possible ( none-any wheels). But if you must target a specific platform, see the —platform option of pip. @deed02392

If you want to install a bunch of dependencies from, say a requirements.txt, you would do:

mkdir dependencies pip download -r requirements.txt -d "./dependencies" tar cvfz dependencies.tar.gz dependencies 

And, once you transfer the dependencies.tar.gz to the machine which does not have internet you would do:

tar zxvf dependencies.tar.gz cd dependencies pip install * -f ./ --no-index 

this method worked for me, I just think you don’t need really the quotation marks on the second line.

Is there an equivalent for * on Windows? I get an error saying: ERROR: Invalid requirement: ‘*’ when on Windows station.

Windows does not have tar, but you can make a zip folder. If not from the command line, you can use the typical right click menu to make a zip.

@DominikNovotný there is another answer for this: for %x in (dir *.whl) do python -m pip install %x from stackoverflow.com/a/43314623/8537739. Aso notice, that installation goes alphabetically, and some libraries that depend from not yet installed will fail. So this solution could be improved. Or you need call this command untill all libraries will be installed.

We have a similar situation at work, where the production machines have no access to the Internet; therefore everything has to be managed offline and off-host.

Here is what I tried with varied amounts of success:

  1. basket which is a small utility that you run on your internet-connected host. Instead of trying to install a package, it will instead download it, and everything else it requires to be installed into a directory. You then move this directory onto your target machine. Pros: very easy and simple to use, no server headaches; no ports to configure. Cons: there aren’t any real showstoppers, but the biggest one is that it doesn’t respect any version pinning you may have; it will always download the latest version of a package.
  2. Run a local pypi server. Used pypiserver and devpi . pypiserver is super simple to install and setup; devpi takes a bit more finagling. They both do the same thing — act as a proxy/cache for the real pypi and as a local pypi server for any home-grown packages. localshop is a new one that wasn’t around when I was looking, it also has the same idea. So how it works is your internet-restricted machine will connect to these servers, they are then connected to the Internet so that they can cache and proxy the actual repository.

The problem with the second approach is that although you get maximum compatibility and access to the entire repository of Python packages, you still need to make sure any/all dependencies are installed on your target machines (for example, any headers for database drivers and a build toolchain). Further, these solutions do not cater for non-pypi repositories (for example, packages that are hosted on github).

We got very far with the second option though, so I would definitely recommend it.

Eventually, getting tired of having to deal with compatibility issues and libraries, we migrated the entire circus of servers to commercially supported docker containers.

This means that we ship everything pre-configured, nothing actually needs to be installed on the production machines and it has been the most headache-free solution for us.

We replaced the pypi repositories with a local docker image server.

Источник

prateek / python-package-offline-install-notes.md

In the case where the target machine connects to the internet over a network proxy, export the following environment vars, as appropriate — http_proxy and https_proxy . Eg:

$ export https_proxy=http://proxy.mydomain.com:port> $ export http_proxy=http://proxy.mydomain.com:port> $ pip install package>

(b) Install without access to the internet

In the case where the target machine does not have connectivity to the internet, you have to download the package and dependencies using a machine which does have connectivity to the internet. After which the install can follow. Sample instructions —

Step 1. Download Packages for Offline Install

Execute the instructions below download the packages on a machine which is able to connect to the internet.

# if a single package is being installed $ pip install package> --download /tmp/offline_packages # or, if a list of dependencies are to be installed $ pip install --download /tmp/offline_packages -r requirements.txt

Step 2. Transfer downloaded packages

Transfer downloaded packages to the target machine where the install is to be performed. Use scp/sftp/etc.

Assuming the directory /tmp/transferred_packages contains the contents of /tmp/offline_packages from the earlier machine, execute the following steps on the the target machine.

# if a single package is being installed $ pip install --no-index --find-links="/tmp/tranferred_packages" package> # if a list of dependencies are to be installed $ pip install --no-index --find-links="/tmp/tranferred_packages" -r requirements.txt

Источник

Скачать пакеты python для оффлайн установки

У меня на работе ограничения и если я скачиваю пакеты с помощью команды pip через командную строку, то с интернета все блокирует служба безопасности. Поэтому мне надо скачать пакеты напрямую, а потом установить в оффлайн режиме с компа. Но не могу найти где их скачать. Подскажите где можно напрямую скачивать пакеты? Мне нужны tqdm, pandas, numpy, sklearn.metrics, statsmodels, scipy, matplotlib

А вообще, при вашем наборе пакетов, попробуйте дистрибутив Anaconda. Ведь у некоторых из перечисленных вами пакетов есть зависимости, которые pip сам устраняет.

@mkkik плохой вариант, Anaconda это хороший вариант для Dev машин, когда на бою это уж чересчур раздутый набор lib, лучше и проще выкачивать нужный lib и установить, ответ Dmitry Erohin

2 ответа 2

  1. Скачивайте нужные вам пакеты отсюда https://pypi.python.org/
  2. Для установки нужно написать pip install полный_путь_до_имени_файла

Вы можете использовать pip , чтобы скачать нужные пакеты:

$ pip download -r requirements.txt --dest dist --only-binary :all: 

Если машина с интернетом отличается от системы, куда вы ставить хотите, то явно укажите платформу, используя —implementation , —platform , —python-version и другие опции. См. pip help download .

Затем перенесите папку dist на желаемую машину и установите без обращения на PyPI:

$ pip install -r requirements.txt --no-index -f dist 

В простейшем случае requirements.txt это просто файл с именем пакета на каждой строчке:

tqdm pandas numpy scikit-learn statsmodels scipy matplotlib 

Если платформы совпадают, то вы можете собрать двоичные wheels самостоятельно, если их ещё нет на PyPI:

$ pip wheel --wheel-dir=dist -r requirements.txt 

Источник

Как установить модули python без интернета и pip?

Возникла проблема, есть основной пк на котором есть интернет и pip, но пакеты нужно установить на компьютер, на котором нет интернета, и нет возможности установить pip.

Средний 2 комментария

kgb_zor

Web Dentist, насколько я понял там для установки .whl используется pip, а у меня его нет возможности установить.

trapwalker

Kostyan4ik, почему это нет возможности? С питоном всегда можно найти какую-нибудь возможность.

Вот, к примеру, вы можете на том компе, где есть питон и интернет, скачать все необходимые пакеты с помощью того же pip:
pip download pip
Так вы можете скачать все необходимые пакеты и принести их на машину без инета просто на флешке.
А там:

python pip-20.1.1-py2.py3-none-any.whl/pip install pip-20.1.1-py2.py3-none-any.whl

Тут происходит маленькая магия: вы с помощью питона запускаете pip прямо изнутри локально лежащего файла с его дистрибутивом. Этим pip’ом вы ставите самого себя на локальную машину. Примерно как Барон Мюнхаузен, но не больно.

Вы также можете сохранить перечень всех установленных пакетов на компе с инетом в текстовый файл, а потом, убрав из него лишнее, скачать все эти пакеты в локальный каталог, отнести на оффлайн-комп и там ставить через тот же pip

pip freeze > r.txt pip download -r r.txt

Источник

Оцените статью