Hi Michael,
I am also not a fan of using virtual environments with UV.
Using either the
PYTHONUSERBASE or even
PYTHONPATH environment variables can be used to great effect to isolate the python module installation away from the python installation.
I mentioned the uvpython and uvpip commands simply because the location of the python installation used by UV is configurable.
it is not possible to totally rely on the UV python installation path being /usr/uv/python, so it is somewhat dangerous to use a hard-coded path of /usr/uv/python/bin/python3 to access the python3 binary from the python installation used by uv.
The /usr/uv/.pyconfig file identifies the the path of the python installation:
root@h113200# cat .pyconfig
PYHOME=/usr/uv/python
PYLIB=/usr/uv/python/lib/libpython3.7m.so
root@h113200#
So to accurately get the path to the python3 binary of the python installation path being used by UV you need to do some extra effort:
IFS='=' read -r var UVPYPATH <<<$(grep PYHOME $(cat /.uvhome)/.pyconfig)
${UVPYPATH}/bin/python3
Whilst this will work it is not an easy thing to remember each time you want to launch the UV python binary.
So wrapping the above into scripts to correctly launch the uv python and pip commands would be very helpful.
It would also open up the ability use use the uopy python module to interact with the UV database from outside of the UV shell, which is a new option for anyone looking to use DevOps or to automate linux processing using UV data.
------------------------------
Gregor Scott
Software Architect
Pentana Solutions
Mount Waverley VIC Australia
------------------------------
Original Message:
Sent: 12-10-2020 14:02
From: Michael Rajkowski
Subject: U2PE, Python and virtual environments
Gregor,
While I mentioned it may be possible to set an active virtual Python environment, I do not recommend it since it would require the environment to stay active, and would have issues if someone then wanted to use multiple virtual environments.
As for uvpip and uvpython, I do not see the benefit, if you are setting up the virtual Python environment, you would be changing the PATH environment variable accordingly.
This is the same step you would need to do if you had several version of Python on a system and wanted to work with one particular version over another.
Note a quick search of the web reveals that there are several options people use to manage which Python versions:
- Aliases
- batch/scripts
- providing the version when launching python or pip
------------------------------
Michael Rajkowski
Rocket Software
Original Message:
Sent: 12-09-2020 19:09
From: Gregor Scott
Subject: U2PE, Python and virtual environments
I have not explored using virtual environments with UV's python, and given how they work I think the only way you will find success is to activate the virtual environment before you launch uv so that UV inherits the active environment setup, including the PATH settings.
I think you would also need to be mindful to use the uv-supplied python3 or pip3 commands to ensure the virtual environment you setup uses the UV-supplied python installation. Either an explicit path to the binary, or having the UV python bin directory at the front of your PATH environment variable should help with this.
It is a pity that there is no uv-supplied command-line launcher for python or pip to ensure you run the correct installation. Something like uvpython or uvpip would go a long way to helping you out with this.
------------------------------
Gregor Scott
gregors
Original Message:
Sent: 12-07-2020 11:03
From: David Howell
Subject: U2PE, Python and virtual environments
Hello Everyone, I have installed Rocket U2/Universe Personal Edition (12.1.1/Python 3.7.3) and I'm trying to get it to work a Python virtual environment and not being successful.
- Is it possible to use virtual environments with Universe Python and if so,
- Are there any (or can one provide) instructions for doing so?
Thanks,
Dave Howell
------------------------------
David Howell
Market America
------------------------------