1

I executed this:

$ pip download virtualenv
Collecting virtualenv
  Using cached virtualenv-20.0.31-py2.py3-none-any.whl (4.9 MB)
  Saved d:\test\gits\virtualenv-20.0.31-py2.py3-none-any.whl
Collecting appdirs<2,>=1.4.3
  Using cached appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
  Saved d:\test\gits\appdirs-1.4.4-py2.py3-none-any.whl
Collecting six<2,>=1.9.0
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
  Saved d:\test\gits\six-1.15.0-py2.py3-none-any.whl
Collecting distlib<1,>=0.3.1
  Using cached distlib-0.3.1-py2.py3-none-any.whl (335 kB)
  Saved d:\test\gits\distlib-0.3.1-py2.py3-none-any.whl
Collecting filelock<4,>=3.0.0
  Using cached filelock-3.0.12-py3-none-any.whl (7.6 kB)
  Saved d:\test\gits\filelock-3.0.12-py3-none-any.whl
Successfully downloaded virtualenv appdirs six distlib filelock

Although I attempted to download one package, I got these wheel files:

appdirs-1.4.4-py2.py3-none-any.whl  
six-1.15.0-py2.py3-none-any.whl
distlib-0.3.1-py2.py3-none-any.whl  
virtualenv-20.0.31-py2.py3-none-any.whl
filelock-3.0.12-py3-none-any.whl

Now my questions are:

  1. Why are there so many wheel files,and not just one file called virtualenv-20.0.31-py2.py3-none-any.whl?
  2. Now once I have this downloaded and stored somewhere on my computer or network location, how do I do the install?
  3. What happens if I just have the virtualenv-20.0.31-py2.py3-none-any.whl and no other wheel file when I attemp the install?
wim
  • 338,267
  • 99
  • 616
  • 750
gyuunyuu
  • 526
  • 5
  • 17

2 Answers2

1

1 . Using pip download also downloads the dependencies, and those extra files that you saw are precisely the deps of the virtualenv distribution:

$ johnnydep virtualenv
name                    summary
----------------------  -------------------------------------------------------------------------------------------------
virtualenv              Virtual Python Environment builder
├── appdirs<2,>=1.4.3   A small Python module for determining appropriate platform-specific dirs, e.g. a "user data dir".
├── distlib<1,>=0.3.1   Distribution utilities
├── filelock<4,>=3.0.0  A platform independent file lock.
└── six<2,>=1.9.0       Python 2 and 3 compatibility utilities

If you only want the package itself without dependencies, use:

pip download --no-deps virtualenv

2 . You can install a wheel file directly with pip

pip install ./virtualenv-20.0.31-py2.py3-none-any.whl

3 . If you install with --no-deps the app won't work properly, probably it will crash with some ImportError due to missing dependencies.

$ pip install -q --no-deps virtualenv
$ virtualenv .venv
Traceback (most recent call last):
    ...
ModuleNotFoundError: No module named 'appdirs'

Otherwise it will just collect and install the dependencies from PyPI, or whatever index your pip is configured at - see pip config list.

wim
  • 338,267
  • 99
  • 616
  • 750
  • ok, now how would one know which is the real package that we must put into the pip install and which are just dependencies? Also, what if someone wants to find out if the wheel represents an old version of a package and not the latest version. – gyuunyuu Sep 30 '20 at 08:40
  • Umm, the package you asked for will have the distribution name in the filename :) If you want to find if it's the latest version, you'll have to check the index - see the options here [How to check if python package is latest version programmatically?](https://stackoverflow.com/q/58648739/674039) – wim Sep 30 '20 at 21:29
  • Yes, I understand that the distribution name shall be in the file name. However, what if I have a folder with lot of wheel files and forget which packages I had downloaded into there? – gyuunyuu Sep 30 '20 at 22:35
  • Yes, what if? Why would that make any difference? – wim Sep 30 '20 at 22:56
  • ok the same basic idea is that when I use pip to download things, I get issues where the work proxy gets in the way. Overtime we have applied fixes but eventually something new problem pops up and we have to then find a new fix. Now, since we just really want to do our real work, one way around this is download and store them packages as wheel files on our own internal network. Now just out of curiosity I am wondering, what if the actual instructions of the specific package names to be used in pip install are lost, can we just install all of them one by one and everything will work at the end? – gyuunyuu Oct 02 '20 at 11:37
  • 1
    You could use a [requirements.txt](https://pip.pypa.io/en/stable/user_guide/#requirements-files) file, once you have a working environment you can generate that with `pip freeze`. Download each of those packages, and use `pip install --no-index -r requirements.txt`, then you don't need internet access at all so the proxy will not cause troubles. For a more modern approach use a [poetry lock file](https://python-poetry.org/docs/basic-usage/). – wim Oct 02 '20 at 15:50
1
  1. Those additional wheels are dependencies, including recursive (transitive) dependencies, i.e. dependencies of dependencies.

pip install --find-links /path/to/download/dir/ virtualenv-20.0.31-py2.py3-none-any.whl
  1. pip tries to download dependencies from the configured index server, default is PyPI. Failed to download any dependency pip fails to install anything. It exits with an error message and an error code.
phd
  • 82,685
  • 13
  • 120
  • 165
  • Maybe if you want to use `--find-links` and a wheelhouse in local dir, it is also good to pass `--no-index` (so that pip won't just go to PyPI if something is missing from your local dir). – wim Sep 30 '20 at 01:10
  • "*good to pass `--no-index`*" Depends if the user is online or offline. – phd Sep 30 '20 at 01:15
  • How would one know which is the real package that we must put into the pip install and which are just dependencies? Also, what if someone wants to find out if the wheel represents an old version of a package and not the latest version. So that I don't have to put up with workplace proxy issues that are very hard to overcome, I want to have the python packages on our work network instead. – gyuunyuu Sep 30 '20 at 20:37
  • @Quantum0xE7 You're looking at it backwards. You've started with `pip download virtualenv` so you surely know that `virtualenv` is the package to install and everything else are dependencies. – phd Oct 01 '20 at 11:29
  • ok the same basic idea is that when I use pip to download things, I get issues where the work proxy gets in the way. Overtime we have applied fixes but eventually something new problem pops up and we have to then find a new fix. Now, since we just really want to do our real work, one way around this is download and store them packages as wheel files on our own internal network. Now just out of curiosity I am wondering, what if the actual instructions of the specific package names to be used in pip install are lost, can we just install all of them one by one and everything will work at the end? – gyuunyuu Oct 02 '20 at 11:38