Skip to content

Python Environment on KNEO Pi

KNEO Pi provides a robust Python development environment with Python3 pre-installed. Please follow the guidelines below to manage Python packages effectively and avoid potential conflicts.

Using Virtual Environments with pip

It is recommended to use a virtual environment when installing Python packages with pip. This isolates project dependencies from the system Python environment and prevents version conflicts or permission issues.

Create a virtual environment:

python3 -m venv myenv
Activate the virtual environment:
source myenv/bin/activate
Install packages within the virtual environment:
pip install {package_name}
Deactivate the virtual environment when done:
deactivate

See error: externally-managed-environment ?

This error occurs when you attempt to use pip outside of a virtual environment in a Python installation managed by your operating system (e.g., installed via pacman). Pacman and Python’s pip both manage packages in the same global directories. Mixing them can cause file conflicts, version mismatches, or break system dependencies.

For detailed specifications, refer to PEP 668

Installing System-wide Packages with Pacman

If you intentionally need to install Python packages system-wide, you can use pacman directly. This approach integrates packages into the system environment and is suitable for administrative or shared setups.

Search for a package from Arch User Repository (AUR)

pacman -Ss python-{package_name}
Install the package:

sudo pacman -S python-{package_name}
Resolving Conflicts

If you have installed packages using pip and encounter conflicts, follow these steps to resolve them:

Uninstall the conflicting pip package:

pip uninstall {package_name}
Install the equivalent package using pacman:

sudo pacman -S python-{package_name}
This approach ensures that the system maintains stability by using the pacman package manager for system-wide installations.