Fresh Ubuntu Install

Fresh Ubuntu server, ran through the prerequisites for a python install. No issues.

When running pip install “tutor[full]”

I get the error below. Any help will be greatful.

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.

If you wish to install a non-Debian-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 python3-full installed.

If you wish to install a non-Debian 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.

See /usr/share/doc/python3.12/README.venv for more information.

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.

Hi @Rick_Sauer
What you’re missing currently is a Virtual Environment for Python. Without this, any Python packages you install go to the System installation which has the potential to cause conflicts and is known to cause problems. A venv keeps your packages nicely partitioned from the main system packages

After installing Python and before installing Tutor you should create a virtual environment. Once created you can then activate it and begin installing your packages.

  • Install Python
  • Create venv: python -m venv ~/venv
  • Activate your venv: source ~/venv/bin/activate
  • Validate that the paths are working correctly: which python and which pip should point to your venv path, eg /home/tutor/venv/bin/python
  • (Optional) Add activation to ~/.bashrc for automatic activation on login: echo "source ~/venv/bin/activate" >> ~/.bashrc (now whenever you login to your shell then you should see (venv) in the CLI indicating it’s active)

(Change paths according to your preference, in my example ~/venv means /home/yourusername/venv)

Thanks Joel, appreciate the reply.

Is this a new requirement from python or tutor?

I don’t recall having to go through this with the last install…

And there’s no mention of it here in the install instructions.

It’s not necessarily a “new” requirement. Rather it’s recommended for any Python based project, not just specifically Tutor.

My expectation is that it’s not stated in the installation instructions due to the wide variety of possibilities in config, there are also different apps that can manage your python/venv installations.

I agree there ought to be some kind of footnote (at least) recommending that a venv be created

It is not a Tutor or Python requirement. The issue is happening in Ubuntu because Python environment is managed by apt and when pip attempts to install it, it raises the environment error. This became strict starting with Py312 as far as I know.
Also, as Joel mentioned, it is a recommended practice to use dedicated venvs for Python projects.

Thanks Syed, Joel, will set these up as you described.

Though I can foresee a few having the same problem when following the installation instructions.

Thank you very much for your help.

1 Like