How to use Python's pip to download and keep the zipped files for a package?
Solution 1
pip install --download
is deprecated. Starting from version 8.0.0 you should use pip download
command:
pip download <package-name>
Solution 2
The --download-cache
option should do what you want:
pip install --download-cache="/pth/to/downloaded/files" package
However, when I tested this, the main package downloaded, saved and installed ok, but the the dependencies were saved with their full url path as the name - a bit annoying, but all the tar.gz
files were there.
The --download
option downloads the main package and its dependencies and does not install any of them. (Note that prior to version 1.1 the --download
option did not download dependencies.)
pip install package --download="/pth/to/downloaded/files"
The pip
documentation outlines using --download
for fast & local installs.
Solution 3
I always do this to download the packages:
pip install --download /path/to/download/to_packagename
OR
pip install --download=/path/to/packages/downloaded -r requirements.txt
And when I want to install all of those libraries I just downloaded, I do this:
pip install --no-index --find-links="/path/to/downloaded/dependencies" packagename
OR
pip install --no-index --find-links="/path/to/downloaded/packages" -r requirements.txt
Update
Also, to get all the packages installed on one system, you can export them all to requirement.txt
that will be used to intall them on another system, we do this:
pip freeze > requirement.txt
Then, the requirement.txt
can be used as above for download, or do this to install them from requirement.txt
:
pip install -r requirement.txt
REFERENCE: pip installer
Solution 4
Use pip download <package1 package2 package n>
to download all the packages including dependencies
Use pip install --no-index --find-links . <package1 package2 package n>
to install all the packages including dependencies.
It gets all the files from CWD
.
It will not download anything
Solution 5
In version 7.1.2 pip downloads the wheel of a package (if available) with the following:
pip install package -d /path/to/downloaded/file
The following downloads a source distribution:
pip install package -d /path/to/downloaded/file --no-binary :all:
These download the dependencies as well, if pip is aware of them (e.g., if pip show package
lists them).
Update
As noted by Anton Khodak, pip download
command is preferred since version 8. In the above examples this means that /path/to/downloaded/file
needs to be given with option -d
, so replacing install
with download
works.
John C
Updated on July 23, 2022Comments
-
John C almost 2 years
If I want to use the
pip
command to download a package (and its dependencies), but keep all of the zipped files that get downloaded (say, django-socialregistration.tar.gz) - is there a way to do that?I've tried various command-line options, but it always seems to unpack and delete the zipfile - or it gets the zipfile, but only for the original package, not the dependencies.
-
John C over 12 yearsNice, that did indeed work - although I tagged a
--no-install
option on. And you're right about the funky filenames, but at least the files are there. -
Mohammad Niknam almost 11 yearslast time I checked ,
--download
option download the package with dependencies. -
Mark Gemmill almost 11 years@Danial - yes, as of version 1.1,
--download
now downloads dependancies. -
John C almost 10 yearsAs of version 1.5 (possibly earlier),
pip
has a--no-deps
option, to prevent downloading dependencies. -
ostler.c over 9 years--download-cache is deprecated. use pip install --download <dir> <pkg>
-
Sнаđошƒаӽ over 8 years
pip install --download
in now deprecated, and will be removed from pip 10. pip.pypa.io/en/latest/reference/pip_download/#overview. Usepip download somepackage
. -
rrauenza about 8 yearsSpecifically, the new equivalent is
pip download -d <dir> { -r requirements.txt | <packagename> }
-
knocte over 7 years@rrauenza what is the
requirements.txt
for? -
knocte over 7 yearsand how to install the downloaded packages later?
-
KJ50 over 7 yearsThis is the most up-to-date answer. Thanks
-
Anton Khodak over 7 years@knocte
pip install path-to-downloaded-package
-
knocte over 7 yearstried that some days ago and I think it still tried to retrieve deps from the internet instead of using the downloaded ones; IIRC, I had to use
sudo pip install <path-to-downloaded-package> --no-index --find-links `pwd`
-
Hawkins about 6 yearsNote that
pip download
also supports-r requirements.txt
so you can easily download them all from an internet-connected machine then copy to an offline machine and install how the above commenters mentioned -
cwhisperer about 6 yearsI have to develop in windows and deploy on RH7 with no internet connection at all. So I download the source packages with --no-binary :all: . However this fails when Collecting django-pyodbc-azure==2.0.4.1 as this package has no source. Is there a way to download the source or if this does not exist, to download the weehl?
-
Admin about 5 yearsI think the option changed to
--cache-dir
not--download-cache
can someone verify -
Vic almost 5 yearsor
pip download -d <target dir> <package>
to download to a specific directory. All dependencies are also downloaded. -
John C over 4 yearsMoved the checkmark from here, as the other answer is more up-to-date, sorry. Time marches on.
-
Prometheus about 4 yearsif you dont specify the platform, it will download the files for the current OS. Therefore this will not work if you install the downloaded files on other OS
-
stackprotector over 2 yearsCan you specify a version of the package without using
-r requirements.txt
?