Python venv sourcing is not working properly in Manjaro (?)
$cd /data
$which python
/usr/bin/python
$sudo -u user python -m venv project
$cd project
$source bin/activate
(313)$ sudo -u user pip install -U pip
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
python-xyz', where xyz is the package you are trying to
install.
If you wish to install a non-Arch-packaged Python package,
create a virtual environment using 'python -m venv path/to/venv'.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
If you wish to install a non-Arch packaged Python application,
it may be easiest to use 'pipx install xyz', which will manage a
virtual environment for you. Make sure you have python-pipx
installed via pacman.
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.
(313)$ which pip
/data/project/bin/pip
(313)$which python
/data/project/bin/python
So my question is why is my … sudo -u user pip install -U pip
… command not working as I am clearly in my venv?
sudo -u user ./bin/pip install -U pip
Does work by the way, but still it should work no?
Seems to be, I just checked and of course got the same result as you.
It’s not quite the same as being logged in, if you really need a different user then you could try su $USER or su $USER -, obviously replace $USER with the username.
Is the project user different from your user? Normally it’s run as your user.
Yes it is. Like pgadmin or mayan or any other project I want then to run under their own username as they run in a semi-production environment (e.g. my own server).
I am sure venv is ‘normaly’ not run as your own user, only in development environments I guess.
But thanks, I understand now that sudo isn’t working in venv the way I used too (as it was before).
I will play around with su $USER see if that suits me. Still… sudo -u $USER should work in my opinion and it doesn’t.
I’ve written websites in Python + CherryPy, using the same exact setup, as I described. Moved them to a Local web server for testing, then to an off site server for production.
What’s your perceived issue?
I certainly can’t develop the image conversion utilities, I posted to GitLab recently, under the user names of the people who might find them useful.
So what problem are you trying to solve, in this problematic manner?