colcon / colcon-core

Command line tool to build sets of software packages
http://colcon.readthedocs.io
Apache License 2.0
103 stars 46 forks source link

MacOS pythonscriptspath error #513

Closed sundermann closed 1 year ago

sundermann commented 2 years ago

On MacOS the pythonscriptspath extension fails with the following error:

[61.423s] ERROR:colcon.colcon_core.environment:Exception in environment extension 'pythonscriptspath': '/usr/local/bin' is not in the subpath of '/Users/ssundermann/Sourcecode/ros2_humble/install' OR one path is relative and the other is absolute.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/colcon_core/environment/__init__.py", line 175, in create_environment_hooks
    hooks = extension.create_environment_hooks(prefix_path, pkg_name)
  File "/usr/local/lib/python3.10/site-packages/colcon_core/environment/path.py", line 57, in create_environment_hooks
    rel_bin_path = bin_path.relative_to(prefix_path)
  File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/pathlib.py", line 816, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: '/usr/local/bin' is not in the subpath of '/Users/ssundermann/Sourcecode/ros2_humble/install' OR one path is relative and the other is absolute.

I installed python3.10 through brew and symlinked it into /usr/local

The issue seems to be related to #504

sundermann commented 2 years ago

colcon-core==0.8.1 fails with a similar error, however version 0.7.1 works fine:

[10.030s] ERROR:colcon.colcon_core.environment:Exception in environment extension 'pythonpath': '/usr/local/lib/python3.10/site-packages' is not in the subpath of '/Users/ssundermann/Sourcecode/ros2_humble/install' OR one path is relative and the other is absolute.
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/colcon_core/environment/__init__.py", line 175, in create_environment_hooks
    hooks = extension.create_environment_hooks(prefix_path, pkg_name)
  File "/usr/local/lib/python3.10/site-packages/colcon_core/environment/pythonpath.py", line 28, in create_environment_hooks
    rel_python_path = python_path.relative_to(prefix_path)
  File "/usr/local/Cellar/python@3.10/3.10.4/Frameworks/Python.framework/Versions/3.10/lib/python3.10/pathlib.py", line 816, in relative_to
    raise ValueError("{!r} is not in the subpath of {!r}"
ValueError: '/usr/local/lib/python3.10/site-packages' is not in the subpath of '/Users/ssundermann/Sourcecode/ros2_humble/install' OR one path is relative and the other is absolute.
sundermann commented 2 years ago

It seems that the python parts of the packages are installed to /usr/local/lib/python3.10/site-packages instead of the ros2_humble/install/... directory.

sundermann commented 2 years ago

I was able to resolve these issues by reverting the switch to sysconfig and falling back to the deprecated distutils.

cottsay commented 2 years ago

Hi @sundermann, can you please give #512 a try instead of reverting to the deprecated behavior?

sundermann commented 2 years ago

Hi @cottsay. I installed your branch using python3 -m pip install -U git+https://github.com/colcon/colcon-core.git@cottsay/sitecustomize --force-reinstall. Unfortunately, the install directory is still broken and colcon errors out with the same problems as before.

cottsay commented 2 years ago

Well, it looks like Homebrew is engaging in the same shenanigans as Debian and Fedora, and we'll need to specifically work around it.

Here's the spot: https://github.com/Homebrew/homebrew-core/blob/2f008323193f636d32c4a970caa9e8b528c6c430/Formula/python%403.10.rb#L62-L68

sundermann commented 2 years ago

Is there a hack or workaround available?

cottsay commented 2 years ago

You'll need both #512 and #514 to get around the platform patch.

sundermann commented 2 years ago

Having #512 and #514 applied fixes the issue on MacOS. Thanks!

cottsay commented 2 years ago

Great news, thanks for reporting back.