-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable sitecustomize paths if in virtual env #623
Disable sitecustomize paths if in virtual env #623
Conversation
This change entirely disables the mechanism by which colcon tells setuptools where to install the package. Without this, colcon will try to install to the interpreter default location, which is completely incorrect. Even when using a virtual environment as you're describing, the installation location will be incorrect. In some simple tests on my machine, this doesn't even solve the problem you're describing, and builds still aren't able to find packages provided by the venv. Depending on how the virtual environment was created, there is another factor which is likely contributing to the issue you're facing. Colcon always uses the same Python interpreter to build/install Python packages as the one which was used to invoke colcon itself. If you're using the This problem is a lot worse if your virtual environment uses a different Python ABI version from the one colcon is using. Even if you were able to force colcon to find the virtual environment's packages, they may not be usable by colcon's interpreter (as would be the case for compiled Python modules like the ones in A naive suggestion might be to simply make colcon always use the I don't think there's a perfect "solution" to this problem, but I can offer some workarounds that may work for you.
|
Scott, thank for having a look at this! I'm a bit puzzled at your results, that's not at all what I get.
I see the patched sitecustomize in As for This means that the package is installed as a normal package, with the system python and the usual ROS install locations, while the only stage when the virtual environment python interpreter is used is to install the dependencies, through |
The purpose of the sitecustomize here is to make setuptools install stuff to our prefix instead of the global prefix, and to appear enough like a virtual environment that platform-specific patches to sysconfig don't interfere with that effort. It isn't inconceivable that there may be subprocesses involved in the build, and we want any installation happening in those subprocesses to also get the redirect, and that currently works as expected as long as the sitecustomize directory remains on PYTHONPATH somewhere. However, if some subprocess is also modifying sys.path, as would be the case if a subprocess was using a new virtual environment, we don't want to override those changes. Since we know what sys.prefix was when colcon was invoked, we can just check to see if it changed.
I wasn't able to get The breakage from the original patch that I was describing was verified by CI, where all of the python build tests were failing to find the package installed to the anticipated location (presumably colcon installed the package under Since we know what the prefix is that we want to override, and we know that any subprocesses that activates a venv would change that prefix, we can just make the conditional compare to that instead. Please verify that this change still resolves the issue for |
Awesome, thanks for taking a second look! |
Currently a sitecustomize python module is loaded during
ament_python
package installs.This impedes the use of a virtual environment during the install process, as is the case while using ament_virtualenv.
Due to sitecustomize module path configuration, mimicking the venv one, even if a script is executed using the venv python binary,
pyvenv.cfg
is not found and the path configuration will not be correct.With this fix, the sitecustomize path configuration will appy only while not using a virtual environment.
In particular in the case of
ament_virtualenv
, the pip dependencies will be installed in the venv lib, while the modules of the package being built will still end up in the package install lib.NB:
ament_virtualenv
is currently being ported to humble, I did not test it in the original targeted distribution (electron).