Python Best way to fix "externally managed environment" error?

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on resolving the "externally managed environment" error encountered when installing Python packages globally on Linux systems. It highlights the adoption of PEP-668 standards by Linux distributions, which prevents global installations by default to avoid conflicts with system package managers. The third method discussed, using "pipx," is presented as a viable workaround that automates the creation of virtual environments for each package, thus mitigating potential conflicts. However, it is noted that while pipx is effective for utility installations, each project should ideally maintain its own virtual environment or use tools like Poetry to manage dependencies properly.

PREREQUISITES
  • Understanding of PEP-668 standards and their implications on Python package management
  • Familiarity with pip and its role in Python package installation
  • Knowledge of virtual environments and their importance in Python development
  • Experience with package management tools like Poetry and Gradle
NEXT STEPS
  • Research how to effectively use pipx for managing Python utilities
  • Learn about creating and managing virtual environments with venv and Poetry
  • Explore the implications of PEP-668 on package management in Linux distributions
  • Investigate best practices for avoiding package conflicts in Python projects
USEFUL FOR

Python developers, system administrators, and anyone managing Python packages on Linux who seeks to avoid conflicts between system and Python package management tools.

Swamp Thing
Insights Author
Messages
1,045
Reaction score
775
This page gives three ways to bypass the "externally managed environment" error when trying to install python packages globally.
https://www.makeuseof.com/fix-pip-error-externally-managed-environment-linux/

But it also says,
The latest versions of all Linux distributions are adopting the standards defined in PEP-668. These changes ensure that pip packages will not be installed in a global context by default.

This was implemented in an attempt to avoid conflict between the distribution's package manager and Python package management tools.

So it would seem that the first method (delete the EXTERNALLY-MANAGED file) may create more problems than it solves.

But how about the third method - installing and using "pipx" ? Are there any pitfalls here, or does it take care of the package management conflicts?

=======================
Edit:
Sorry, just noticed that the same page does say this:
It automates steps like creating virtual environments for each package and creating symbolic links to the packages in the .local/bin folder so you can call each package from the shell at all times.

Using pipx to install packages helps you avoid the "externally-managed-environment" error as it installs packages in virtual environments.

This suggests that pipx should be a safe and trouble free solution.

But I can't delete a new post, and anyway if someone has used pipx they might care to weigh in and share how well it actually works.
 
Technology news on Phys.org
Swamp Thing said:
This suggests that pipx should be a safe and trouble free solution.
It's actually not a solution to be exact, but a workaround. Virtual environments were not really made to be used like that. Each project should anyway have its own venv or Poetry environment to avoid clashes with any other project, similar to the way we use Gradle. But we cannot forget that in Linux distros, there are many utilities that come in the form of a python package and have to be installed using pip. These utilities are not supposed to be for a project, e.g. a markdown editor. So in those cases, the concept that pipx uses is good, IMO. Avoid the clash with system packages, but still be able to download and use utilities.
 
We have many threads on AI, which are mostly AI/LLM, e.g,. ChatGPT, Claude, etc. It is important to draw a distinction between AI/LLM and AI/ML/DL, where ML - Machine Learning and DL = Deep Learning. AI is a broad technology; the AI/ML/DL is being developed to handle large data sets, and even seemingly disparate datasets to rapidly evaluated the data and determine the quantitative relationships in order to understand what those relationships (about the variaboles) mean. At the Harvard &...

Similar threads

  • · Replies 13 ·
Replies
13
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 3 ·
Replies
3
Views
4K