PDM: A smarter way to manage Python packages Otesanya David March 24, 2022

PDM: A smarter way to manage Python packages

PDM: A smarter way to manage Python packages

[ad_1]

Modern Python developers use virtual environments, or “venvs,” to keep their projects and dependancies separate. One of the downsides of a virtual environment, though, is the size of a project directory. Each venv can take 10MB or more of disk space — and that’s just the base install, not including the libraries installed into the project. But now there is a language feature, and a package management system to go with it, that can cut down the size of your project’s footprint.

As of Python 3.8, Python has a feature that can automatically recognize the presence of a subdirectory in a project that stores packages associated exclusively with that project. Codified in PEP 582, Python allows a __pypackages__ directory to contain version-specific editions of packages that can be imported before packages from the base install of Python, or even a venv.

Up until recently, most Python developers made use of PEP 582-style package storage only “by hand.” But a recently developed package management tool, PDM — short for Python Development Master — lets you install packages to a project using the PEP 582 storage guidelines. The result is a project that is smaller, more portable, and less awkward to deal with.

Setting up PDM

PDM installs in Python 3.7 or higher. It’s best to install PDM into the user directory accessed by your Python installation, rather than in the Python installation itself. The PDM documentation explains how to do this. Alternatively, pip install --user pdm is a reliable, automatic way to get the same result.

Note that one crucial part of setting up PDM is enabling the use of PEP 582 behaviors. This can be done automatically, or by manually modifying PYTHONPATH.

Once you’ve installed PDM properly, you should be able to run the command pdm on the command line. If you’re dealing with multiple Python installations on Windows, you can (and should) use py <version> -m pdm to trigger PDM from the proper Python version.

Copyright © 2022 IDG Communications, Inc.

[ad_2]

Source link

Write a comment