Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save pip packages

Tags:

python

pip

django

We have a python/django based web application, many components of which are installed using pip. So I would like to ask if there is a way to save or download and save the particular python packages that we are having pip install (example: pip install django==1.5.1). We would like to have in the end a collection of the packages in the versions known to be working and with which the app was developed locally. Any and all advice will be appreciated.

like image 520
Gary Ridley Avatar asked Nov 29 '22 11:11

Gary Ridley


2 Answers

If I understood your question right, you can pip freeze > requirements.txt, this command will add all the libraries you have used/"downloaded" for your app in the file requirements.txt(in case it exists the file be overwritten). This command allows you to later do pip install -r requirements.txt. However, be aware that your Django project must be running in a virtual environment, otherwise the install command will attempt to install all the python packages in your development machine.

The freeze command will allow you to have the current version of the app so upon installation will attempt to install that same version. Your requirements file will look something like:

Flask==0.8
Jinja2==2.6
Werkzeug==0.8.3
certifi==0.0.8
chardet==1.0.1
distribute==0.6.24
gunicorn==0.14.2
requests==0.11.1

Your packages are installed (if using virtualenv) at: ../<your project>/<your virtual env>/<lib>/<python version>/<site-packages>/

As for downloading you can use pip install --download command as @atupal suggested in his response, however think if this is really needed you can also fork those libraries on github to accomplish the same.

Here is a good source of information on how this works: http://www.pip-installer.org/en/latest/cookbook.html

like image 85
lv10 Avatar answered Dec 06 '22 11:12

lv10


Maybe what you want is:

Download the packages:

pip install --download /path/to/download/to packagename

OR

pip install --download=/path/to/packages/downloaded -r requirements.txt

install all of those libraries just downloaded:

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

Shamelessly stolen from this question

like image 25
atupal Avatar answered Dec 06 '22 10:12

atupal