[PYTHON] Manage the package version number of requirements.txt with pip-tools

Pythonista, how are you upgrading the package written in requirements.txt? Do you regularly copy the package name into the search window of PyPI to find out the version number? pip-tools makes it easier to manage!

Installation method

You can install it with pip (> = 6.1) as follows.

pip install pip-tools

How to use the pip-compile command

Write the name of the package you want to install in the file requirements.in. The writing method is the same as requirements.txt.

requirements.in


Django
easy-thumbnails
Fabric

Then, the following command will generate requirements.txt with the latest run-time version number.

pip-compile requirements.in

It also looks up and writes out dependent packages. Also, if you want to specify "latest than this version" or "latest in the range of this version", you can write as follows. (This is also the same as writing requirements.txt)

requirements.in


Django>=1.8.0,<1.9.0
easy-thumbnails>=2.2
Fabric>=1.8.0,<2.0.0

How to use the pip-sync command

A command that can be used in place of pip install -r requirements.txt. Install the package written in requirements.txt with the following command.

pip-sync

Unlike normal pip install, it uninstalls packages that you have previously installed but no longer use.

This usage may be convenient

pip-compile has a --dry-run option so you can compare the differences with previously generated content like this before updating requirements.txt.

pip-compile --dry-run requirements.in | diff requirements.txt -

You may be happy if you do this in a CI or cron job so that you are automatically notified when you need to upgrade the package.

Recommended Posts

Manage the package version number of requirements.txt with pip-tools
Count the number of characters with echo
Calculate the total number of combinations with python
Predict the number of people infected with COVID-19 with Prophet
Align the version of chromedriver_binary
10. Counting the number of lines
Get the number of digits
Calculate the number of changes
Get the package version to register with PyPI from Git
[Homology] Count the number of holes in data with Python
Let's visualize the number of people infected with coronavirus with matplotlib
Test the version of the argparse module
[Package cloud] Manage python packages with package cloud
Raise the version of pyenv itself
Get the number of views of Qiita
Calculation of the number of Klamer correlations
pyenv-change the python version of virtualenv
Change the Python version of Homebrew
Get the number of Youtube subscribers
Manage each Python version with Homebrew
[Completed version] Try to find out the number of residents in the town from the address list with Python
Get the number of searches with a regular expression. SeleniumBasic VBA Python
Generate a list packed with the number of days in the current month.
Get the number of visits to each page with ReportingAPI + Cloud Functions
Get the number of articles accessed and likes with Qiita API + Python
Display the status of COVID 19 infection in Japan with Splunk (GitHub version)
Align the size of the colorbar with matplotlib
How to check the version of Django
Check the existence of the file with python
About the virtual environment of python version 3.7
Install by specifying the version with pip
Migemo version of the: find command,: mfind
The third night of the loop with for
The second night of the loop with for
Expand any number of arguments with yasnippet
I can't install the package with pip.
Around the authentication of PyDrive2, a package that operates Google Drive with Python
Let Code Day10 Starting from Zero "1431. Kids With the Greatest Number of Candies"
Get only the source code of the PyPI package with pip from the command line
Align the number of samples between classes of data for machine learning with Python
Output the number of CPU cores in Python
The story of doing deep learning with TPU
Try the python version of emacs-org parser orgparse
The meaning of {version-number} in the mysql rpm package
Note: Prepare the environment of CmdStanPy with docker
Prepare the execution environment of Python3 with Docker
Convert data with shape (number of data, 1) to (number of data,) with numpy.
[Note] Export the html of the site with python.
See the behavior of drunkenness with reinforcement learning
Increase the font size of the graph with matplotlib
Divide the string into the specified number of characters
Manage Python multiple version environment with Pythonz, virtualenv
Use the latest version of PyCharm on Ubuntu
Check the date of the flag duty with Python
Find the number of days in a month
Eliminate the inconveniences of QDock Widget with PySide
A note about the python version of python virtualenv
Challenge the Tower of Hanoi with recursion + stack
Try the free version of Progate [Python I]
Fill the browser with the width of Jupyter Notebook
Manage AWS nicely with the Python library Boto