Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
580 stars 341 forks source link

`scons install` (python_package=full) fails on latest Ubuntu without virtual environment #1687

Closed mefuller closed 2 months ago

mefuller commented 2 months ago

Problem description

Building and installing from source fails during the install phase on Ubuntu owing to a lack of virtual environment for pip. I think there should be a way to directly install system-wide, without a venv, from scons install.

Steps to reproduce

  1. scons build python_package=full
  2. scons test
  3. sudo scons install: fails without output provided below

Behavior

"/usr/bin/python3" -m pip install --no-build-isolation --no-deps -v --force-reinstall build/python
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.11/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.
scons: *** [build/python/dummy] Error 1
scons: building terminated because of errors.

System information

bryanwweber commented 2 months ago

Unfortunately, I don't think there's anything we can do about this. This is an error from pip, which obviously we don't control. I guess the only option is to replace pip as the installer, but I don't think there are any other installers out there and anyways this is codified in a PEP apparently so presumably other installers would have the same behavior. Frankly, I can't think of a good reason not to use a virtual environment, what's your use case here?

Edit: whoops I didn't read the error message, I guess we can add --break-system-packages to the install line. I'm not in favor of that, though, owing to not seeing a reason not to use a venv. Maybe we can add a scons option to add this option?

speth commented 2 months ago

More specifically, this installation behavior is very explicitly being blocked by Debian's patched version of pip. I'm not particularly keen on adding an option just to circumvent this protection.

If you really want to specify this option, pip allows you to set this (and other arguments) via environment variables. Assuming you run scons with the env_vars=all option, I think you could specify this option by setting PIP_BREAK_SYSTEM_PACKAGES=1.