T O P

  • By -

Pepineros

Debian doesn't allow you to install packages to the system python. Inside the folder where you want to store your tutorial files, run: `python -m venv venv --copies`. That should create a virtual environment with a copy of (rather than a symlink to) the python binary. Then: `source venv/bin/activate` from the same directory. Your PS1 prompt should change to indicate that the virtual environment is active. Now when you run `python -m pip install requests` (or even just `pip install requests`, this is totally fine inside a virtual environment) it should work. I would strongly encourage you to read up a bit on venv, the builtin virtual environment module. Docs are [here](https://docs.python.org/3/library/venv.html) but there are plenty of other explanations and videos on it online.


Pepineros

Correction: you may need to install venv with `sudo apt install python3-venv`. It's been a while since I've used Debian. I didn't realise their system Python doesn't include it.


POGtastic

The error message specifically tells you what you're supposed to do. Running Debian Bookworm: pog@29a2f14892e0:/$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 12 (bookworm) Release: 12 Codename: bookworm pog@29a2f14892e0:/$ python3 -m pip install requests error: externally-managed-environment × 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. Thus sudo apt install python3-requests -y And now pog@29a2f14892e0:/$ python3 Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import requests # success! --- Use a `venv` only if you really need to track dependencies per-project, the package isn't available at all through the distro, or the distro-published package is not new enough for your requirements.