× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
code
If you wish to install a non-Kali-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have pypy3-venv installed.
If you wish to install a non-Kali-packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
For more information, refer to the following:
* https://www.kali.org/blog/python-externally-managed/
* /usr/share/doc/python3.12/README.venv
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
┌──(qwe㉿localhost)-[~/models/tts-py]
└─$
Assistant
The error you're encountering occurs because your Python environment is externally managed, meaning the system's package manager (like apt on Debian-based systems) is responsible for handling Python packages. To prevent conflicts and maintain system stability, pip is restricted from modifying the global Python environment.
To install PySide6 without disrupting the system-managed environment, you can use one of the following approaches:
1. Use a Virtual Environment (Recommended)
A virtual environment allows you to create an isolated Python environment where you can install packages without affecting the system-wide Python installation.
Steps to Create and Use a Virtual Environment:
Ensure venv is Installed:
First, make sure that the venv module is available. You can install it using apt if it's not already installed:
bash
sudo apt update
sudo apt install python3-venv
Create a Virtual Environment:
Navigate to your project directory and create a virtual environment. You can name it venv or any name you prefer.
bash
cd ~/models/tts-py
python3 -m venv venv
Activate the Virtual Environment:
bash
source venv/bin/activate
After activation, your shell prompt will typically change to indicate that you're now working inside the virtual environment.
Upgrade pip (Optional but Recommended):
It's a good practice to ensure that pip is up to date.
bash
pip install --upgrade pip
Install PySide6:
Now, you can install PySide6 without any restrictions.
bash
pip install PySide6
Deactivate the Virtual Environment (When Done):
Once you're finished working in the virtual environment, you can deactivate it:
bash
deactivate
Advantages of Using a Virtual Environment:
Isolation: Keeps project dependencies separate.
Flexibility: Different projects can use different package versions.
Safety: Prevents accidental changes to system-wide packages.
2. Use pipx for Python Applications
If you're aiming to install a standalone Python application rather than a library for a specific project, pipx is a great tool. It installs applications in isolated environments automatically.
After installation, you might need to restart your terminal or source your shell configuration.
Install the Python Application with pipx:
bash
pipx install PySide6
However, note that PySide6 is typically a library rather than an application. For libraries, using a virtual environment (as described above) is more appropriate.
3. (Not Recommended) Override the System Package Manager
Warning: This method is not recommended as it can lead to conflicts and potentially break your Python or system installation.
If you absolutely need to install the package system-wide and understand the risks, you can override the restriction using the --break-system-packages flag:
bash
pip install PySide6 --break-system-packages
Proceed with caution.
Summary
The best and safest approach is to use a virtual environment. This method ensures that your project dependencies are isolated and don't interfere with system-managed packages. Here's a quick recap of the virtual environment steps:
bash
# Install venv if not already installed
sudo apt update
sudo apt install python3-venv
# Navigate to your project directory
cd ~/models/tts-py
# Create a virtual environment named 'venv'
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activate
# Upgrade pip inside the virtual environment
pip install --upgrade pip
# Install PySide6
pip install PySide6
# When done, deactivate the virtual environment
deactivate
Feel free to reach out if you encounter any issues or have further questions!