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.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
For Pip 8.1.2 you can use
pip download -r requ.txt
to download packages to your local machine.If you want install python libs and their dependencies offline, finish following steps in a machine with same os, network connected, python installed:
1) Create an
requirements.txt
file with the content like:2) Execute command
mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse
to download libs and their dependencies to direcotrywheelhouse
3) Copy requirements.txt into
wheelhouse
directory4) Archive wheelhouse into
wheelhouse.tar.gz
withtar -zcf wheelhouse.tar.gz wheelhouse
Then upload
wheelhouse.tar.gz
to your target machine:1) Execute
tar -zxf wheelhouse.tar.gz
to extract the files2) Execute
pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse
to install the libs and their dependenciesDownload 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.
offline python. for doing this I use virtualenv (isolated Python environment)
1) install virtualenv online with pip:
or offline with whl: go to this link , download last version (.whl or tar.gz) and install that with this command:
by using
--user
you don't need to usesudo pip…
.2) use virtualenv
on online machine select a directory with terminal
cd
and run this code:after installing all the packages, you have to generate a
requirements.txt
so while your virtualenv is active, writeopen a new terminal and create another env like
myenv2
.now you can go to your offline folder where your
requirements.txt
andtranferred_packages
folder are in there. download the packages with following code and put all of them totranferred_packages
folder.take your offline folder to offline computer and then
what is in the folder offline [requirements.txt , tranferred_packages {Flask-0.10.1.tar.gz, ...}]
check list of your package
note: as we are in 2017 it is better to use python 3. you can create python 3 virtualenv with this command.
Using
wheel
compiled packages.bundle up:
copy tarball and install:
Note
wheel
binary packages are not across machines.More ref. here: https://pip.pypa.io/en/stable/user_guide/#installation-bundles
If the package is on PYPI, download it and its dependencies to some local directory. E.g.
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 haveinstall_requires
list that mentions one or more things that you have in your/pypi
directory. Like so: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:
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:
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 ...
andeasy_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).