Tuesday, September 12, 2017

[Python] pip - export package list and restore

 Python   pip   restore 



▌Introduction


In this article, we will use pip to export a project’s installed package list and restore them in another project.



▌Environment

▋Git bash
▋Python 3.6.2
▋Git bash



▌Implement


▋Where are the installed packages?

They are in ~/Lib/site-packages of the virtual environment.

For a global or per-user site-packages, use the following command.

1.Global site-packages

$ python –m site

2.per-user (where Python installs the local packages)

$ python -m site --user-site




▋Export the packages list

▋List installed packages

$  pip list


▋Export installed packages

$ pip freeze --local > requirements.txt





▋Restore

Now we have another new project and we would like to restore the packages from requirments.txt.


▋pip is required

If pip is not installed, follow DOC: installation to install it.

For example, get get-pip.py and execute it by $ python get-pip.py


▋Restore


Copy the requirements.txt to the new project and execute the following command.

$ pip install -r requirements.txt --force-reinstall

--force-reinstall: Reinstall all packages even if they are already up-to-date.


OR

$ pip install -r requirements.txt --ignore-installed

--ignore-installed: Ignore the installed packages/files







▌Reference

▋pip list — pip 9.0.1 documentation




No comments:

Post a Comment