Logo

dev-resources.site

for different kinds of informations.

Python env: be careful with requirements

Published at
5/21/2023
Categories
python
beginners
dependencies
Author
spo0q
Categories
3 categories in total
python
open
beginners
open
dependencies
open
Author
5 person written this
spo0q
open
Python env: be careful with requirements

It's not uncommon to provide a file called requirements.txt that list all third-party packages the script needs to work properly.

This way, users only have to use the following command before running the desired script:

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

The technique relies on pip, the package manager for Python, and the requirements.txt file simply contains a list of all pip packages you have to install (one per line).

Check all dependencies carefully

It's pretty convenient and quite robust, but it's also prone to bad scenarios.

If the script you want to use relies on too much dependencies, it's not necessarily evil, but it's usually a bad sign.

This list should be kept short, in my opinion.

Use venv

You should use venv to create isolated virtual environments "with their own independent set of Python packages installed in their site directories."

source: Python documentation - venv

If you'd like to share your Python scripts or plan to maintain a library, you can include it in your documentation to let beginners know it's possible to install your stuff in a virtual env and not globally.

It does not require any installation, as venv is included in Python.

You will also avoid various compatibility issues, and a virtual env is easy to deactivate.

Wrap up

As a good practice, never install Python packages globally unless you perfectly know what you're doing.

Instead, you can leverage virtual environments to isolate your projects and don't mess with system-wide packages.

It won't solve all situations but you may avoid some headaches.

dependencies Article's
30 articles in total
Favicon
Forge Compatibility Reports for module management
Favicon
A Developer’s Guide to Dependency Mapping
Favicon
The Essence of Task Dependencies in Project Management: Definition & Example
Favicon
Wednesday Links - Edition 2024-09-11
Favicon
You Are Not Saved By IaC
Favicon
The Simplest Way to Extract Your Requirements.txt in Python
Favicon
How I can get away with never installing npm packages globally
Favicon
πŸ“š How to see what changed in Composer files
Favicon
Advanced Usage of Dependencies and Models in FastAPI
Favicon
CDK Dependency Strategies
Favicon
How to link a local npm dependency with pnpm
Favicon
It depends! Exploring my favourite Renovate features for dependency updates
Favicon
ERESOLVE unable to resolve dependency tree
Favicon
πŸ“¦ Upgrading Dependencies
Favicon
Python env: be careful with requirements
Favicon
The Better Npm Audit πŸͺ±
Favicon
Choosing dependencies using deps.dev
Favicon
Tips and tricks for using Renovate
Favicon
How to Keep Project Dependencies Up-To-Date
Favicon
Automatically keep project dependencies up to date with Renovate
Favicon
Another cheat sheet for Dependabot
Favicon
When Package Dependencies Become Problematic
Favicon
Automatically manage Python dependencies with requirements.txt
Favicon
Dockerize the Spring Boot Application.
Favicon
Dependency Injection Explained
Favicon
I broke production 3 times in 3 weeks - Part II
Favicon
5 + 1 tips to reduce the noise of Renovate Bot
Favicon
Lock your Android dependencies πŸ”
Favicon
Sorting a Dependency Graph in Go
Favicon
The Essential Guide to Dependency Graphs

Featured ones: