How to install python package offline

How to install packages offline in Python?

In Python, installing packages from online repositories like PyPI (Python Package Index) is a common practice. However, there might be situations where you don’t have access to the internet, or you want to avoid the internet for security reasons, and you need to install packages offline. In this case, you can use some alternative methods to install packages offline in Python.

Method 1: Using .whl files

To install Python packages offline using .whl files, you can follow these steps:

  1. Download the .whl files for the packages you want to install. You can find these files on the Python Package Index (PyPI) or other sources.
  2. Transfer the .whl files to the offline machine where you want to install the packages.
  3. Open the command prompt or terminal on the offline machine and navigate to the directory where the .whl files are located.
  4. Use the pip install command to install the packages from the .whl files. You can use the —no-index and —find-links options to specify that you want to install the packages from local files instead of from PyPI.

Here is an example command to install a single package from a .whl file:

pip install --no-index --find-links=. some-package.whl

Here is an example command to install multiple packages from .whl files in a directory:

pip install --no-index --find-links=. package1.whl package2.whl package3.whl

You can also use wildcards to install all .whl files in a directory:

pip install --no-index --find-links=. *.whl

Note that some packages may have dependencies that also need to be installed from .whl files. You can use the same pip install command to install these dependencies.

That’s it! With these simple steps, you can easily install Python packages offline using .whl files.

Читайте также:  Java doc rest api

Method 2: Installing from Source Code

Installing Python packages offline can be a challenge, but it is possible to do so by downloading the source code and installing it manually. Here are the steps to follow:

  1. Download the source code for the package you want to install. You can find the source code on the package’s website or on a repository like GitHub.
  2. Extract the source code to a directory of your choice.
  3. Open a terminal or command prompt and navigate to the directory where you extracted the source code.
  4. Run the following command to install the package:

This will compile and install the package on your system.

  1. If the package has any dependencies, you will need to install them manually as well. You can do this by following the same steps for each dependency.
  2. Once you have installed all the dependencies, you can test the package by importing it in a Python script:

If the package is imported without errors, it means that it has been installed successfully.

That’s it! You have now installed a Python package offline from source code. Remember to keep the source code and any dependencies in a safe place so that you can install them again in the future if needed.

Method 3: Using Anaconda Offline Installer

Anaconda is a popular distribution of Python and R for scientific computing and data analysis. It includes a package manager called conda that allows you to easily install, update, and manage Python packages and dependencies. In this tutorial, we will show you how to install Python packages offline using Anaconda.

Step 1: Download Anaconda Installer

First, you need to download the Anaconda installer from the official website. Choose the appropriate version for your operating system and download the offline installer. This will ensure that you have all the necessary packages and dependencies to install Python packages offline.

Step 2: Transfer Installer to Offline Machine

Next, transfer the Anaconda installer to the offline machine. You can use a USB drive or any other method you prefer.

Step 3: Install Anaconda

On the offline machine, run the Anaconda installer and follow the prompts to install Anaconda. Make sure to choose a directory that you have write access to, as this is where your Python environment will be created.

Step 4: Create a Conda Environment

Once Anaconda is installed, you can create a new environment for your Python project. This will ensure that your project has its own isolated Python environment and dependencies.

Читайте также:  Process start html file

To create a new environment, open a terminal or command prompt and run the following command:

Replace myenv with the name of your environment.

Step 5: Activate the Environment

After the environment is created, activate it by running the following command:

Step 6: Install Packages

Now you can install Python packages offline using conda . For example, to install the numpy package, run the following command:

This will install numpy and any dependencies it requires.

Step 7: Export Environment

Once you have installed all the necessary packages, you can export your environment to a YAML file. This file can then be used to recreate the environment on another machine.

To export the environment, run the following command:

conda env export > environment.yml

This will create a file called environment.yml that contains a list of all the packages and dependencies in your environment.

Step 8: Transfer Environment File

Transfer the environment.yml file to the offline machine using the same method as before.

Step 9: Create Environment from File

On the offline machine, create a new environment from the environment.yml file by running the following command:

conda env create -f environment.yml

This will create a new environment with the same packages and dependencies as the original environment.

Step 10: Activate Environment

Finally, activate the new environment by running the following command:

Replace myenv with the name of your environment.

That’s it! You have now installed Python packages offline using Anaconda.

Источник

Python3 установка pip пакетов offline

Бывает необходимо установить пакеты для python на машине без интернета. Способов много, я выбрал для себя один, его и использую. «Легко» и «просто» можно скачать необходимые пакеты вместе с зависимостями и установить на другой машине, если сделать следующие.

На машине с интернетом

python3 -m venv vevn source venv/bin/active pip install pip --upgrade # директория для скачивания пакетов mkdir pkg cd pkg # отдельно скачиваю последнею версию pip pip download pip # скачиваю необходимые пакеты с зависимостями pip download -r ../requirements.txt

На машине без интернета

python3 -m venv vevn source venv/bin/active # устанавливаю ранее скаченный pip (версия может быть другая) pip install pkg/pip-20.1-py2.py3-none-any.whl # установка пакетов из списка requirements.txt, пакеты должны лежать в pkg (директория) pip install --no-index --find-links pkg -r requirements.txt

Результат выполнения

# вывод консоли у меня pip install --no-index --find-links pkg -r requirements.txt Looking in links: pkg Processing ./pkg/Flask-1.1.2-py2.py3-none-any.whl Processing ./pkg/Flask_WTF-0.14.3-py2.py3-none-any.whl Processing ./pkg/et_xmlfile-1.0.1.tar.gz Processing ./pkg/openpyxl-3.0.3.tar.gz Processing ./pkg/jdcal-1.4.1-py2.py3-none-any.whl Processing ./pkg/pylint-2.5.2-py3-none-any.whl Processing ./pkg/itsdangerous-1.1.0-py2.py3-none-any.whl Processing ./pkg/Jinja2-2.11.2-py2.py3-none-any.whl Processing ./pkg/Werkzeug-1.0.1-py2.py3-none-any.whl Processing ./pkg/click-7.1.2-py2.py3-none-any.whl Processing ./pkg/WTForms-2.3.1-py2.py3-none-any.whl Processing ./pkg/mccabe-0.6.1-py2.py3-none-any.whl Processing ./pkg/isort-4.3.21-py2.py3-none-any.whl Processing ./pkg/toml-0.10.1-py2.py3-none-any.whl Processing ./pkg/astroid-2.4.1-py3-none-any.whl Processing ./pkg/MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl Processing ./pkg/typed_ast-1.4.1-cp37-cp37m-manylinux1_x86_64.whl Processing ./pkg/wrapt-1.12.1.tar.gz Processing ./pkg/lazy_object_proxy-1.4.3-cp37-cp37m-manylinux1_x86_64.whl Processing ./pkg/six-1.14.0-py2.py3-none-any.whl Could not build wheels for et-xmlfile, since package 'wheel' is not installed. Could not build wheels for openpyxl, since package 'wheel' is not installed. Could not build wheels for wrapt, since package 'wheel' is not installed. Installing collected packages: itsdangerous, MarkupSafe, Jinja2, Werkzeug, click, Flask, WTForms, Flask-WTF, et-xmlfile, jdcal, openpyxl, mccabe, isort, toml, typed-ast, wrapt, lazy-object-proxy, six, astroid, pylint Running setup.py install for et-xmlfile . done Running setup.py install for openpyxl . done Running setup.py install for wrapt . done Successfully installed Flask-1.1.2 Flask-WTF-0.14.3 Jinja2-2.11.2 MarkupSafe-1.1.1 WTForms-2.3.1 Werkzeug-1.0.1 astroid-2.4.1 click-7.1.2 et-xmlfile-1.0.1 isort-4.3.21 itsdangerous-1.1.0 jdcal-1.4.1 lazy-object-proxy-1.4.3 mccabe-0.6.1 openpyxl-3.0.3 pylint-2.5.2 six-1.14.0 toml-0.10.1 typed-ast-1.4.1 wrapt-1.12.1

Мой файл requirements.txt для примера

Flask==1.1.2 Flask-WTF==0.14.3 et-xmlfile==1.0.1 openpyxl==3.0.3 jdcal==1.4.1 pylint==2.5.2

Установка из tar.gz или whl

# установка одного пакета из архива pip install ./pkg-name.tar.gz

Источник

Читайте также:  Название документа

Как установить модули 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

Источник

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