Python Packages Offline Installation

2019-01-01 12:02发布

What's the best way to download a python package and it's 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.

7条回答
荒废的爱情
2楼-- · 2019-01-01 12:46

Update 2018-10-10

pip has a relatively new command called download. The download command let's you get the package without the installation.

DEPRECATION: pip install --download has been deprecated and will be removed in the future. Pip now has a download command that should be used instead.

The command is like this:
pip download -r requirements.txt

For python3:
pip3 download -r requirements.txt

older versions of pip

I use the -d (or --download) option to pip install, which makes the process of downloading sdist tarballs from PyPI much simpler. For instance,

pip install --download /path/to/some/dir celery

will download the sdist tarballs for celery and all its dependencies to /path/to/some/dir (but will not install them). Then you can use pip install --no-index --find-links /path/to/some/dir/ celery to install celery using those downloaded sdists, without accessing the network.

The same process works if you replace celery in both commands with -r requirements.txt, where requirements.txt is a pip requirements file listing all the packages you want (and optionally the versions you want).

查看更多
登录 后发表回答