Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Flask Blueprints

You're reading from   Flask Blueprints Dive into the world of the Flask microframework to develop an array of web applications

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781784394783
Length 198 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Joel Perras Joel Perras
Author Profile Icon Joel Perras
Joel Perras
Arrow right icon
View More author details
Toc

Avoiding dependency hell, the Python way

New developers might be tempted to install every interesting package that they come across. In doing so, they might realize that this quickly degrades into a Kafkaesque situation where previously installed packages may cease to function and newly installed packages may behave unpredictably, if they manage to get installed successfully at all. The problem with the preceding approach, as some of you may have guessed, is that of conflicting package dependencies. Say for example, we have package A installed; it depends on version 1 of package Q and version 1 of package R. Package B depends on version 2 of package R (where versions 1 and 2 are not API-compatible). Pip will happily install package B for you, which will upgrade package R to version 2. This will, at best, make package A completely unusable or, at worst, make it behave in undocumented and unpredictable ways.

The Python ecosystem has come up with a solution to the basic issues that arise from what is colloquially referred to as dependency hell. While far from perfect, it allows developers to sidestep many of the simplest package version dependency conflicts that can arise in web application development.

The virtualenv tool, of which a similar implementation is now a default module in Python 3.3 and named venv, is essential to ensure that you minimize your chances of ending up in dependency hell. The following quote is from the introduction in the official documentation for virtualenv:

It creates an environment that has its own installation directories, that doesn't share libraries with other virtualenv environments (and optionally doesn't access the globally installed libraries either).

More concisely, virtualenv allows you to create isolated environments for each one of your Python applications (or any Python code).

Note

The virtualenv tool does not, however, help you to manage the dependencies of the Python C-based extensions. For example, if you install the lxml package from pip, it will require that you have the correct libxml2 and libxslt system libraries and headers (which it will link against). The virtualenv tool will not help you isolate these system-level libraries.

You have been reading a chapter from
Flask Blueprints
Published in: Nov 2015
Publisher:
ISBN-13: 9781784394783
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image