What's the best way to download a python package and its dependencies from pypi for offline installation on another machine? Is there any easy way to do this with pip or easy_install? I'm trying to install the requests library on a FreeBSD box that is not connected to the internet.
-
1Related: [How to pip install packages according to requirements.txt from a local directory?](http://stackoverflow.com/q/7225900/95735) – Piotr Dobrogost Mar 13 '13 at 21:42
13 Answers
On the system that has access to internet
The pip download
command lets you download packages without installing them:
pip download -r requirements.txt
(In previous versions of pip, this was spelled pip install --download -r requirements.txt
.)
On the system that has no access to internet
Then you can use
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt
to install those downloaded modules, without accessing the network.

- 25,404
- 19
- 49
- 81

- 122,012
- 20
- 106
- 116
-
3problem with this is that the dependencies might have other dependencies and those won't be downloaded. – vikki Jul 01 '13 at 06:01
-
[Snake basket](https://github.com/prezi/snakebasket) (built on top of pip) will download the dependencies' dependencies as well. – vikki Jul 01 '13 at 10:53
-
29@vikki Not true, "pip install --download" also downloads dependencies, so the above commands will work correctly even if your requirements have additional dependencies. Snake basket may do other useful things (never used it), but it's definitely not needed for that reason. – Carl Meyer Jul 01 '13 at 18:25
-
`pip install --download -r requirements.txt` only downloads the dependencies listed in requirements.txt, if those dependencies have other requirements e.g in setup.py, pip won't fetch those, sb adds that feature. e.g if a project requires sphinx `pip -d` will only fetch sphinx but not jinja, pygments and docutils (which are needed by sphinx). These will only be fetched once you run setup.py, but since this is supposed to be for offline use you won't have a working connection at the time you run setup.py and the installation will fail citing unmet dependencies as the issue. – vikki Jul 01 '13 at 18:52
-
13@vikki I understand what you are saying, but I am telling you that it is not true :-) You should actually go try it before you post the same assertion again. I just put "pytest" in a requirements.txt, ran "pip install --download . -r requirements.txt", and it downloaded sdists for both pytest and its setup.py dependency, "py". – Carl Meyer Jul 01 '13 at 19:36
-
Okay I'll try again. I could have sworn I tried it today with sphinx, and pip on its own didn't pick up sphinx's deps, only after adding sb did it download them. I'll investigate further. – vikki Jul 01 '13 at 20:26
-
After reading [this](http://engineering.prezi.com/blog/2013/04/19/snakebasket/) I now understand that snakebasket only forces pip to inspect each download's `requirements.txt` and download whatever is listed. Some projects will list their dependencies in `requirements.txt` and the list will vary from that which is in setup.py. [django-oscar](https://github.com/tangentlabs/django-oscar) is an example. – vikki Jul 01 '13 at 20:44
-
I think this is the more correct/simple answer. It takes care of the requirements without an intervening step. – rickfoosusa Feb 13 '15 at 23:36
-
2Like @vikki, for me this also didn't download the entire dependency graph. However, I still appreciate the answer, as it was only one package that was missing, and I just explicitly added it to requirements.txt. – jacderida Apr 14 '15 at 20:12
-
3I think it should be: `--find-links file:/path/to/some/dir/` and you should download and install with the same version of pip - otherwise it might fail – A. Binzxxxxxx Aug 14 '15 at 08:17
-
-
-
i added `--no-deps` to the command, otherwise it will try to find some dependencies online (which was not possible) – Leonard AB Sep 26 '19 at 07:25
-
Can you somehow generate the `requirements.txt` for a certain Python version? Let's say, I have Python 3.8.2 (not the newest version). I want the package `numpy`. How do I know which version I need to download for my Python version? Do the Python versions on the online and offline computer have to be the same? – stackprotector Oct 05 '21 at 11:31
-
1@stackprotector, yes, I discovered that it's very helpful to run `python --version` on the offline computer before attempting this procedure! Then, on your online computer, per the [pip download docs](https://pip.pypa.io/en/stable/cli/pip_download/), you can run (for Python 3.8.2): `pip download --python-version=3.8.2 --only-binary=:all: -r requirements.txt`. – Joel Buursma Oct 17 '22 at 21:08
If you want install python libs and their dependencies offline, finish following these steps on a machine with the same os, network connected, and python installed:
1) Create a requirements.txt
file with similar content (Note - these are the libraries you wish to download):
Flask==0.12
requests>=2.7.0
scikit-learn==0.19.1
numpy==1.14.3
pandas==0.22.0
One option for creating the requirements file is to use pip freeze > requirements.txt
. This will list all libraries in your environment. Then you can go in to requirements.txt
and remove un-needed ones.
2) Execute command mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse
to download libs and their dependencies to directory wheelhouse
3) Copy requirements.txt into wheelhouse
directory
4) Archive wheelhouse into wheelhouse.tar.gz
with tar -zcf wheelhouse.tar.gz wheelhouse
Then upload wheelhouse.tar.gz
to your target machine:
1) Execute tar -zxf wheelhouse.tar.gz
to extract the files
2) Execute pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse
to install the libs and their dependencies

- 3
- 3

- 2,177
- 1
- 12
- 12
-
6but following your instruction, when I `pip install` in the end, it says: ERROR: could not find a version that satisfies the requirement ..` – DennisLi May 29 '20 at 07:15
-
-
I figured this out, that is because pip can't find the specific version of the pandas package in my requirements.txt, as I used pip3 to install the pandas 0.2 – DennisLi Jun 09 '20 at 06:42
-
same happened to me. with pip3 i received same error message mentioned. maybe it only works with python2 only. – Han Whiteking Jun 24 '20 at 07:28
-
@chaokunyang Thanks a lot. Could you please also give me a hint how I can embed this process into the `setup.py` so when installing my own package, it goes and installs all the deps as well ? – Hossein Jul 08 '20 at 03:02
-
4One problem with this workflow is different architectures. If you run `pip download ...` on a mac, you will have `*-macosx*.whl` files that are unusable on e.g. linux – shuckc May 05 '21 at 14:22
-
Hi, I got the following error in the step 1 of target machine:- "tar: Must specify one of -c, -r, -t, -u, -x". – Debayan Paul Feb 19 '23 at 13:24
-
@DennisLi Were you able to solve this problem? I keep getting this error on some of my packages and it gives me a ton of problems creating the requirements.txt file. – Zarif Rahman Mar 21 '23 at 17:10
If the package is on PYPI, download it and its dependencies to some local directory. E.g.
$ mkdir /pypi && cd /pypi $ ls -la -rw-r--r-- 1 pavel staff 237954 Apr 19 11:31 Flask-WTF-0.6.tar.gz -rw-r--r-- 1 pavel staff 389741 Feb 22 17:10 Jinja2-2.6.tar.gz -rw-r--r-- 1 pavel staff 70305 Apr 11 00:28 MySQL-python-1.2.3.tar.gz -rw-r--r-- 1 pavel staff 2597214 Apr 10 18:26 SQLAlchemy-0.7.6.tar.gz -rw-r--r-- 1 pavel staff 1108056 Feb 22 17:10 Werkzeug-0.8.2.tar.gz -rw-r--r-- 1 pavel staff 488207 Apr 10 18:26 boto-2.3.0.tar.gz -rw-r--r-- 1 pavel staff 490192 Apr 16 12:00 flask-0.9-dev-2a6c80a.tar.gz
Some packages may have to be archived into similar looking tarballs by hand. I do it a lot when I want a more recent (less stable) version of something. Some packages aren't on PYPI, so same applies to them.
Suppose you have a properly formed Python application in ~/src/myapp
. ~/src/myapp/setup.py
will have install_requires
list that mentions one or more things that you have in your /pypi
directory. Like so:
install_requires=[
'boto',
'Flask',
'Werkzeug',
# and so on
If you want to be able to run your app with all the necessary dependencies while still hacking on it, you'll do something like this:
$ cd ~/src/myapp $ python setup.py develop --always-unzip --allow-hosts=None --find-links=/pypi
This way your app will be executed straight from your source directory. You can hack on things, and then rerun the app without rebuilding anything.
If you want to install your app and its dependencies into the current python environment, you'll do something like this:
$ cd ~/src/myapp $ easy_install --always-unzip --allow-hosts=None --find-links=/pypi .
In both cases, the build will fail if one or more dependencies aren't present in /pypi
directory. It won't attempt to promiscuously install missing things from Internet.
I highly recommend to invoke setup.py develop ...
and easy_install ...
within an active virtual environment to avoid contaminating your global Python environment. It is (virtualenv that is) pretty much the way to go. Never install anything into global Python environment.
If the machine that you've built your app has same architecture as the machine on which you want to deploy it, you can simply tarball the entire virtual environment directory into which you easy_install
-ed everything. Just before tarballing though, you must make the virtual environment directory relocatable (see --relocatable option). NOTE: the destination machine needs to have the same version of Python installed, and also any C-based dependencies your app may have must be preinstalled there too (e.g. say if you depend on PIL, then libpng, libjpeg, etc must be preinstalled).

- 30,663
- 1
- 34
- 41
-
4
-
Can you please elaborate how to create a properly formed Python application? – psr Sep 23 '16 at 10:11
-
4@PrabhjotRai please refer to https://packaging.python.org/distributing/ – Pavel Repin Sep 26 '16 at 19:34
Let me go through the process step by step:
- On a computer connected to the internet, create a folder.
$ mkdir packages
$ cd packages
open up a command prompt or shell and execute the following command:
Suppose the package you want is
tensorflow
$ pip download tensorflow
Now, on the target computer, copy the
packages
folder and apply the following command
$ cd packages
$ pip install 'tensorflow-xyz.whl' --no-index --find-links '.'
Note that the tensorflow-xyz.whl
must be replaced by the original name of the required package.

- 581
- 5
- 15
offline python. for doing this I use virtualenv (isolated Python environment)
1) install virtualenv online with pip:
pip install virtualenv --user
or offline with whl: go to this link , download last version (.whl or tar.gz) and install that with this command:
pip install virtualenv-15.1.0-py2.py3-none-any.whl --user
by using --user
you don't need to use sudo pip…
.
2) use virtualenv
on online machine select a directory with terminal cd
and run this code:
python -m virtualenv myenv
cd myenv
source bin/activate
pip install Flask
after installing all the packages, you have to generate a requirements.txt
so while your virtualenv is active, write
pip freeze > requirements.txt
open a new terminal and create another env like myenv2
.
python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
ls
now you can go to your offline folder where your requirements.txt
and tranferred_packages
folder are in there. download the packages with following code and put all of them to tranferred_packages
folder.
pip download -r requirements.txt
take your offline folder to offline computer and then
python -m virtualenv myenv2
cd myenv2
source bin/activate
cd -
cd offline
pip install --no-index --find-links="./tranferred_packages" -r requirements.txt
what is in the folder offline [requirements.txt , tranferred_packages {Flask-0.10.1.tar.gz, ...}]
check list of your package
pip list
note: as we are in 2017 it is better to use python 3. you can create python 3 virtualenv with this command.
virtualenv -p python3 envname

- 285
- 2
- 5
-
3There appears to be steps missing or "obfuscated" here, I would expect to see a 'deactivate' and then 'pip freeze'... cd offline and ./tranferred_packages appears from nowhere - clearly this needs a cleanup? – Hannu Jan 07 '18 at 22:57
-
maybe, but you should consider 'I wanted a brief post' , 'that process was complex and I couldn't write every step (that only possible in YouTube)'. – cyera Jan 27 '18 at 23:57
-
-
1This would be the best answer if it said anything at all on how to setup the tranferred_packages folder. Without crucial steps, -1 – Zim Nov 16 '19 at 00:56
I had a similar problem. And i had to make it install the same way, we do from pypi.
I did the following things:
Make a directory to store all the packages in the machine that have internet access.
mkdir -p /path/to/packages/
Download all the packages to the path
Edit: You can also try:
python3 -m pip wheel --no-cache-dir -r requirements.txt -w /path/to/packages
pip download -r requirements.txt -d /path/to/packages
Eg:- ls /root/wheelhouse/ # **/root/wheelhouse** is my **/path/to/packages/**
total 4524
-rw-r--r--. 1 root root 16667 May 23 2017 incremental-17.5.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 34713 Sep 1 10:21 attrs-18.2.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 3088398 Oct 15 14:41 Twisted-18.9.0.tar.bz2
-rw-r--r--. 1 root root 133356 Jan 28 15:58 chardet-3.0.4-py2.py3-none-any.whl
-rw-r--r--. 1 root root 154154 Jan 28 15:58 certifi-2018.11.29-py2.py3-none-any.whl
-rw-r--r--. 1 root root 57987 Jan 28 15:58 requests-2.21.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 58594 Jan 28 15:58 idna-2.8-py2.py3-none-any.whl
-rw-r--r--. 1 root root 118086 Jan 28 15:59 urllib3-1.24.1-py2.py3-none-any.whl
-rw-r--r--. 1 root root 47229 Jan 28 15:59 tqdm-4.30.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 7922 Jan 28 16:13 constantly-15.1.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 164706 Jan 28 16:14 zope.interface-4.6.0-cp27-cp27mu-manylinux1_x86_64.whl
-rw-r--r--. 1 root root 573841 Jan 28 16:14 setuptools-40.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 37638 Jan 28 16:15 Automat-0.7.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 37905 Jan 28 16:15 hyperlink-18.0.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 52311 Jan 28 16:15 PyHamcrest-1.9.0-py2.py3-none-any.whl
-rw-r--r--. 1 root root 10586 Jan 28 16:15 six-1.12.0-py2.py3-none-any.whl
Tar the packages directory and copy it to the Machine that doesn't have internet access. Then do,
cd /path/to/packages/ tar -cvzf packages.tar.gz . # not the . (dot) at the end
Copy the packages.tar.gz into the destination machine that doesn't have internet access.
In the machine that doesn't have internet access, do the following (Assuming you copied the tarred packages to /path/to/package/ in the current machine)
cd /path/to/packages/ tar -xvzf packages.tar.gz mkdir -p $HOME/.config/pip/ vi $HOME/.config/pip/pip.conf
and paste the following content inside and save it.
[global]
timeout = 10
find-links = file:///path/to/package/
no-cache-dir = true
no-index = true
Finally, i suggest you use, some form of
virtualenv
for installing the packages.virtualenv -p python2 venv # use python3, if you are on python3 source ./venv/bin/activate pip install <package>
You should be able to download all the modules that are in the directory /path/to/package/.
Note: I only did this, because i couldn't add options or change the way we install the modules. Otherwise i'd have done
pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt

- 6,390
- 1
- 15
- 19
-
Can you clarify the last paragraph? To me it says that your pip.conf approach is just an alternative to doing "pip install --no-index --find-links /path/to/download/dir/ -r requirements.txt" ? Why is that you could not launch this command? – Kiteloopdesign Nov 09 '22 at 18:36
-
1@Kiteloopdesign It's been sometime, but i guess it was because we had no control over the `pip install` call – han solo Nov 09 '22 at 18:50
Download the tarball, transfer it to your FreeBSD machine and extract it, afterwards run python setup.py install
and you're done!
EDIT: Just to add on that, you can also install the tarballs with pip now.

- 5,917
- 1
- 33
- 52
-
1What about all the dependencies? What's the best way to resolve them? Do I need to install the dependencies manually as well? – Chris Drantz Jun 18 '12 at 21:55
-
Using wheel
compiled packages.
bundle up:
$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ pip wheel -r requirements.txt --wheel-dir=$tempdir
$ cwd=`pwd`
$ (cd "$tempdir"; tar -cjvf "$cwd/bundled.tar.bz2" *)
copy tarball and install:
$ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
$ (cd $tempdir; tar -xvf /path/to/bundled.tar.bz2)
$ pip install --force-reinstall --ignore-installed --upgrade --no-index --no-deps $tempdir/*
Note wheel
binary packages are not across machines.
More ref. here: https://pip.pypa.io/en/stable/user_guide/#installation-bundles

- 4,235
- 2
- 23
- 23
-
1I had issues with bundling up on machine with Python 3.6 and extracting on another with Python 3.5: "_
.whl is not a supported wheel on this platform_". The source and destination versions might be required to match with some packages. – Juuso Ohtonen Oct 12 '17 at 09:28
For Windows I have used below things
Internet Connection
1.Create directory with any name.I have created with "repo"
2.Download libraries using below command (it will download not install)
pip download libraray_name -d"C:\repo"
pip download openpyxl -d"C:\repo"
No Internet Connection
- Now Move this folder and files to PC where no internet connection and run the below command.
pip install -r requirements.txt --find-links=C:\repo --no-index
You can read the detailed blog Link

- 349
- 4
- 11
As a continues to @chaokunyang answer, I want to put here the script I write that does the work:
- Write a "requirements.txt" file that specifies the libraries you want to pack.
- Create a tar file that contains all your libraries (see the Packer script).
- Put the created tar file in the target machine and untar it.
- run the Installer script (which is also packed into the tar file).
"requirements.txt" file
docker==4.4.0
Packer side: file name: "create-offline-python3.6-dependencies-repository.sh"
#!/usr/bin/env bash
# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983
LIBRARIES_DIR="python3.6-wheelhouse"
if [ -d ${LIBRARIES_DIR} ]; then
rm -rf ${LIBRARIES_DIR}/*
else
mkdir ${LIBRARIES_DIR}
fi
pip download -r requirements.txt -d ${LIBRARIES_DIR}
files_to_add=("requirements.txt" "install-python-libraries-offline.sh")
for file in "${files_to_add[@]}"; do
echo "Adding file ${file}"
cp "$file" ${LIBRARIES_DIR}
done
tar -cf ${LIBRARIES_DIR}.tar ${LIBRARIES_DIR}
Installer side: file name: "install-python-libraries-offline.sh"
#!/usr/bin/env bash
# This script follows the steps described in this link:
# https://stackoverflow.com/a/51646354/8808983
# This file should run during the installation process from inside the libraries directory, after it was untared:
# pythonX-wheelhouse.tar -> untar -> pythonX-wheelhouse
# |
# |--requirements.txt
# |--install-python-libraries-offline.sh
pip3 install -r requirements.txt --no-index --find-links .

- 2,018
- 1
- 16
- 18
-
One more thing that helped when installing the packages in virtual environment is adding this command just after creating the environment. `python3 -m pip install --upgrade pip` . Not doing this led to spurious errors. – user238607 Jun 04 '21 at 00:47
For Pip 8.1.2 you can use pip download -r requ.txt
to download packages to your local machine.

- 391
- 3
- 14
For another platform with another Python version
To download python packages for another platform, you need the --platform
parameter in combination with the --only-binary=:all:
parameter. To also define the Python version of the target system, use the --python-version
parameter.
Example scenario: You are on Windows and want to download numpy
for a Linux system that uses Python 3.9. Use the following command to download numpy
with all its dependencies for your target system:
pip download --platform=manylinux1_x86_64 --only-binary=:all: --python-version=3.9 numpy
To install numpy
on your target system, copy the downloaded files to it and install the package via:
pip install --no-index --find-links /path/to/package/files numpy
Instead of defining a particular package name, you can also use a requirements file for both commands. Just replace the package name by -r requirements.txt
, for example.

- 10,498
- 4
- 35
- 64
-
FYI can use sysconfig.get_platform() to get the value for --platform with all hyphens `-` and periods `.` replaced with underscore `_` – Geordie Jun 08 '23 at 20:24
Download the wheel file (for example dlb-0.5.0-py3-none-any.whl) from Pypi and
pip install dlb-0.5.0-py3-none-any.whl

- 404
- 4
- 13