Skip to content

BF: detected installed packages in standalone app for py3.10#6771

Merged
peircej merged 1 commit intopsychopy:releasefrom
mh105:release-py310-import
Sep 6, 2024
Merged

BF: detected installed packages in standalone app for py3.10#6771
peircej merged 1 commit intopsychopy:releasefrom
mh105:release-py310-import

Conversation

@mh105
Copy link
Contributor

@mh105 mh105 commented Aug 5, 2024

@peircej I finally tracked down why does pip install during plugins manager ignore the existing package distributions under /Applications/PsychoPy.app/Contents/Resources/lib/python<major>.<minor>. This issue affects both py3.8 and py3.10 on macOS, but the Windows installations are fine because they organize the python distributions in a slightly different file structure.

The root cause is due to the way distributions are packaged for the macOS builds. For python versions <3.11, pip uses its internal pkg_resources backend to find distributions on sys.path. But pkg_resources doesn't correctly resolve the distribution info inside zip files, yielding no detected distributions even though the correct sys.path is present.

This issue is pretty difficult to overcome for py3.8 because pkg_resources expects .disc-info folders for distributions during resolution. And the alternative importlib backend inside pip requires a name attribute of PathDistribution objects that is only available after python 3.10.

On py3.10, I dug up an undocumented environment variable _PIP_USE_IMPORTLIB_METADATA to force importlib as the backend in order to find distributions on sys.path. Fortunately this works fine and prevents the PsychoPy plugins manager from installing potentially conflicting versions of other dependent packages (e.g., numpy, pyserial, etc.) when installing plugin packages.

In the long run though, the macOS builds might need to use a more pip-compatible file structure for packages shipped with the PsychoPy app. Reading distribution info from the .zip file will be dropped after pip 24.3. Maybe both the package and .dist-info folders can be put into ~/Contents/Resources/lib/python<major>.<minor> (or using the ~/Contents/Resources/lib/python<major>.<minor>/site-packages convention)? This way all versions of pip on both py3.8 and py3.10 can resolve these existing distributions on macOS. The CPython files can still live inside the .zip file.

Here's an example output from Plugins & Packages GUI inside PsychoPy on py3.10 after this fix:

>> /Applications/PsychoPy.app/Contents/MacOS/python -m pip install psychopy-crs --user --prefer-binary --no-input --no-color --disable-pip-version-check
Collecting psychopy-crs

DEPRECATION: Loading egg at /Applications/PsychoPy.app/Contents/Resources/lib/python310.zip is deprecated. pip 24.3 will enforce this behaviour change. A possible replacement is to use pip for package installation.. Discussion can be found at https://github.com/pypa/pip/issues/12330

  Using cached psychopy_crs-0.0.2-py3-none-any.whl.metadata (2.0 kB)
Requirement already satisfied: pyserial in ./lib/python310.zip (from psychopy-crs) (3.5)
Requirement already satisfied: numpy in ./lib/python310.zip (from psychopy-crs) (1.26.4)
Using cached psychopy_crs-0.0.2-py3-none-any.whl (67 kB)
Installing collected packages: psychopy-crs


####################### Finished installing psychopy-crs #######################
For more information about the Cambridge Research Systems devices plugin, read the documentation at:
https://psychopy.github.io/psychopy-crs/

@TEParsons TEParsons requested a review from mdcutone August 7, 2024 11:47
@peircej peircej merged commit 16b2d2b into psychopy:release Sep 6, 2024
@mh105 mh105 deleted the release-py310-import branch September 22, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants