Skip to content

Edoardo Vignati

– Always looking for something awesome –

Menu
  • About me
  • Studies
  • Publications
  • Skills
  • Portfolio
  • Projects
  • Career
  • Blog
Menu

How to install a venv in Python without network connection

Posted on 11/09/202102/12/2022 by Edoardo

In some cases you have to replicate a Python project on a computer without internet connection. In these cases you must not simply copy the venv folder.

Requirements for this process: the project, a memory mass storage, another computer with internet connection.

First of all, you have to to install Python on the offline machine. Now let’s go deeper into the venv replication process.

Take a look to the requirements.txt file of the project where all the dependencies are declared. Keep in mind: this file might not contain all the recursive dependencies.

Now we are going to download all the dependencies: jump into the root of the project and launch the following command (the first one for a single dependency, the second one for the entire list of requirements) from the terminal:

pip download <package-name/version>
pip download -r ./path/to/requirements.txt -d ./download/folder/

For example:

pip download itsdangerous==2.0.1

Collecting itsdangerous==2.0.1
  Using cached itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Saved ./itsdangerous-2.0.1-py3-none-any.whl
Successfully downloaded itsdangerous

We can see that a wheel file or a compressed package has been now downloaded with all its recursive dependencies.

Repeat this process for the packages declared in the requirements.txt file and you will have a pool of libraries, ready to be copied into the new project.

If you have downloaded all the packages is now time to create a new fresh virtual envoronment into the project in the offline computer:

python -m venv ./venv/

Copy all the python libraries downloaded into a directory inside the project and jump inside.

To install a single wheel:

pip install xyz.wheel

To install an unpacked dependency:

pip install ./my/dependency/

To install all the dependencies automatically using the requirements.txt file:

pip install -r requirements.txt --no-index --find-links file:./path/to/dependencies/folder/

If you need to download for a different platform, you should use the extra option:

--platform

Cheers


Buy Me A Coffee


This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. Edoardo on [SOLVED] XMLHttpRequest error in Flutter web is a CORS error06/01/2023
  2. Fabi on [SOLVED] XMLHttpRequest error in Flutter web is a CORS error20/12/2022
  3. Edoardo on How to install hplip on Ubuntu28/11/2022
  4. Alex K on How to install hplip on Ubuntu28/11/2022

© 2023 Edoardo Vignati | Powered by Minimalist Blog WordPress Theme
Manage Cookie Consent
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}