Install Python dependencies in an application | Divio Documentation (2024)

See also

  • How to install system packages

It's beyond the scope of this documentation to discuss all the ways in which Python dependencies can be installed inDivio applications. However, the options described here are sufficient to cover most needs.

If you are using Aldryn Django, refer to the section Python package installation in Aldryn Django applications below.

pip install and requirements.txt

The simplest option is to list Python requirements in a requirements.txt file, and include the command:

RUN pip install -r requirements.txt

in the Dockerfile. See How to configure an existing Django application for deployment on Divio for an example.

However this is only adequate as a quick expedient in the early stages of development and is not recommended beyondthat, as it does not allow for complete pinning of all dependencies.

Pin all dependencies

warning

Unpinned dependencies are the number one cause of deployment failures. Nothing in thecodebase may have changed, but a fresh build can unexpectedly pick up a newly-releasedversion of a package.

All Python dependencies, including implicit sub-dependencies, should be pinned to particular versions.

If any dependency is unpinned (that is, a particular version is not specified in the application's requirements)pip will install the latest version it finds, even if a different version was previously installed. This can causeyour application to fail with an deployment error or worse, a runtime error, the next time it is built - even if youdidn't change anything in it yourself.

To pin all dependencies, your application's requirements should be compiled to a complete list of explicitly specifiedpackage versions. This list should then be committed in the application repository, and not be changed until you need toupdate dependencies.

With pip

Once you are able to build and run your application successfully, you know have a working set of Python dependenciesinstalled. Use pip freeze to write them in a new file:

docker-compose run web pip freeze > compiled_requirements.txt

And then ensure that the pip command in the Dockerfile uses that list:

RUN pip install -r compiled_requirements.txt

Other tools

There are multiple Python tools such as pip-tools and Poetry that are more sophisticated than pip, that can also generate a complete list ofpinned dependencies.

You can use the tool of your choice. In each case, the tool itself needs to be available in the Docker buildenvironment. You can expect to find pip to be installed by default, but other tools will generally need to beinstalled manually in the Dockerfile.

An example using pip-tools:

RUN pip install pip-tools==5.5.0
RUN pip-compile requirements.in
RUN pip-sync requirements.txt

This installs pip-tools, compiles requirements.in to requirements.txt, then installs the components listedin requirements.txt.

Once you have a working set of dependencies, remove the pip-compile instruction so that the dependencies are pinnedand frozen in requirements.txt.

Python package installation in Aldryn Django applications

By default, applications using an Aldryn Django Dockerfile use our own pip-reqs tool to compile a list wheel URLs from our wheels proxy server,and installs all packages as wheels.

To install Python dependencies an Aldryn application, list them in the requirements.in file. They need to beoutside the:

# <INSTALLED_ADDONS>
...
# </INSTALLED_ADDONS>

tags, since that part of the file is maintained automatically and is overwritten automatically withthe requirements from the Addons system.

This list is processed by the pip commands in the Dockerfile when the image is built.

Pinning dependencies in an Aldryn application

Compile requirements.txt

First, you need to have a working local set-up. Then run:

docker-compose run --rm web pip-reqs compile

This will create a requirements.txt file in the application, containing a list of all the packages in theenvironment, along with their versions.

When your application is built using the new requirements.txt instead of requirements.in,you'll have a guarantee that no unexpected changes will be permitted to find their way in to theapplication.

Amend the Dockerfile

In order to have your application built using requirements.txt instead of requirements.in, youneed to remove the pip-reqs compile instruction from your application's Dockerfile.

First, remove the Divio-specific comment tags from the Dockerfile:

# <PYTHON>
...
# </PYTHON>

otherwise the Control Panel will simply overwrite your changes.

Then remove the pip-reqs compile instruction, so that requirements.txt will not be amended at the next build.

The next time you need to create a fresh requirements.txt, run:

docker-compose run web pip-reqs compile

Specifying packages via a URL

Please use a commit hash when specifying packages via a URL of a tarballed or zipped archive.

For example:

https://github.com/account/repository/archive/2d8197e2ec4d01d714dc68810997aeef65e81bc1.zip#egg=package-name==1.0

important

Branch names or tags are not supported as part of the archive name and will break. Please use the commit hash asdescribed above.

Recent versions of pip-tools require the use of URLS that provide both the egg fragment and the versionfragment (for example, egg=package-name==1.0), and will raise a Bad Request for url error if they encounterURLs lacking it. Older versions would allow you to omit the fragment.

See also Bad request for URL (from from pip-reqs resolve).

pip-tools does note support VCS protocols- for example, you cannot use URLs starting with git+ or hg+, such as[email protected]:divio/django-cms.git.

Install Python dependencies in an application | Divio Documentation (2024)
Top Articles
How Much Do Real Estate Agents Make in Tennessee
Relative Strength Index (RSI): Definition & Calculation Guide
Mickey Moniak Walk Up Song
Pet For Sale Craigslist
What Are Romance Scams and How to Avoid Them
Froedtert Billing Phone Number
Visitor Information | Medical Center
Blanchard St Denis Funeral Home Obituaries
PontiacMadeDDG family: mother, father and siblings
Camstreams Download
Caliber Collision Burnsville
A Guide to Common New England Home Styles
Mini Handy 2024: Die besten Mini Smartphones | Purdroid.de
Procore Championship 2024 - PGA TOUR Golf Leaderboard | ESPN
The Exorcist: Believer (2023) Showtimes
Indiana Wesleyan Transcripts
Walmart Car Department Phone Number
Aerocareusa Hmebillpay Com
Craigslist Lewes Delaware
Air Traffic Control Coolmathgames
1973 Coupe Comparo: HQ GTS 350 + XA Falcon GT + VH Charger E55 + Leyland Force 7V
Miltank Gamepress
Garnish For Shrimp Taco Nyt
Red8 Data Entry Job
Ceramic tiles vs vitrified tiles: Which one should you choose? - Building And Interiors
Avatar: The Way Of Water Showtimes Near Maya Pittsburg Cinemas
Craigslist Dubuque Iowa Pets
R Baldurs Gate 3
Pacman Video Guatemala
Hobby Lobby Hours Parkersburg Wv
Yayo - RimWorld Wiki
Imagetrend Elite Delaware
Craig Woolard Net Worth
Learn4Good Job Posting
Litter-Robot 3 Pinch Contact & DFI Kit
Ark Unlock All Skins Command
Cvb Location Code Lookup
National Insider Threat Awareness Month - 2024 DCSA Conference For Insider Threat Virtual Registration Still Available
Dr Adj Redist Cadv Prin Amex Charge
Gravel Racing
Wunderground Orlando
Tgirls Philly
Shell Gas Stations Prices
All Weapon Perks and Status Effects - Conan Exiles | Game...
Unit 11 Homework 3 Area Of Composite Figures
Rocket League Tracker: A useful tool for every player
Wvu Workday
Nfl Espn Expert Picks 2023
Sdn Dds
Worlds Hardest Game Tyrone
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 6284

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.