beeware / Python-Apple-support

A meta-package for building a version of Python that can be embedded into a macOS, iOS, tvOS or watchOS project.
MIT License
1.1k stars 159 forks source link

Cannot find dependency in the Python 3 standard library (wsgiref) #126

Closed lukasvasadi closed 3 years ago

lukasvasadi commented 3 years ago

Describe the bug My application uses the gcsfs package for accessing Google Cloud Storage. This package in turn has dependency google-auth-oauthlib, which relies on a module called wsgiref. Previously, wsgiref had to be installed manually for Python 2—however, it is now available in the Python 3 standard library. The application runs as expected in developer mode (briefcase dev), but returns a ModuleNotFoundError in the crash report when run as a packaged app (briefcase run):

Traceback (most recent call last):
  File "ZarrViewer.app/Contents/Resources/app/zarrviewer/__main__.py", line 1, in <module>
    from zarrviewer.app import main
  File "ZarrViewer.app/Contents/Resources/app/zarrviewer/app.py", line 6, in <module>
    from zarrviewer.controller import Controller
  File "ZarrViewer.app/Contents/Resources/app/zarrviewer/controller.py", line 8, in <module>
    from zarrviewer.model import Plates_model, Wells_model, Well_model
  File "ZarrViewer.app/Contents/Resources/app/zarrviewer/model.py", line 11, in <module>
    from zarrviewer.workers import Retrieve_zarrs_worker
  File "ZarrViewer.app/Contents/Resources/app/zarrviewer/workers.py", line 4, in <module>
    import gcsfs
  File "ZarrViewer.app/Contents/Resources/app_packages/gcsfs/__init__.py", line 5, in <module>
    from .core import GCSFileSystem
  File "ZarrViewer.app/Contents/Resources/app_packages/gcsfs/core.py", line 22, in <module>
    from .credentials import GoogleCredentials
  File "ZarrViewer.app/Contents/Resources/app_packages/gcsfs/credentials.py", line 8, in <module>
    from google_auth_oauthlib.flow import InstalledAppFlow
  File "ZarrViewer.app/Contents/Resources/app_packages/google_auth_oauthlib/__init__.py", line 21, in <module>
    from .interactive import get_user_credentials
  File "ZarrViewer.app/Contents/Resources/app_packages/google_auth_oauthlib/interactive.py", line 24, in <module>
    import google_auth_oauthlib.flow
  File "ZarrViewer.app/Contents/Resources/app_packages/google_auth_oauthlib/flow.py", line 65, in <module>
    import wsgiref.simple_server
ModuleNotFoundError: No module named 'wsgiref'

To Reproduce This error can be reproduced simply by packaging any application that imports gcsfs. I recommend creating the helloworld app from the beginner tutorial and adding import gcsfs in app.py. The script should execute normally in developer mode, but produce the same traceback when run as the packaged version.

Environment:

Additional context This cannot be fixed simply by including wsgiref in the toml dependency list, as this package is part of the Python standard library and cannot be installed via pip.

freakboy3742 commented 3 years ago

Thanks for the report! Strictly, this isn't a bug - it's "working as expected", as wsgiref is explicitly excluded from the support package on macOS and iOS.

That said - if packages like gcsfs are using wsgiref because it contains useful WSGI/HTTP utility methods, then we may need to reconsider the inclusion of wsgiref in the support package. It's only 68k of code, and it's pure Python, so it's probably worth it.

I'll also move this ticket to the Python-Apple-support repo, since that's where the underlying problem lies.

freakboy3742 commented 3 years ago

I've just removed wsgiref from the exclusions list, and published new versions of the support packages. Let us know if you have any further problems!

lukasvasadi commented 3 years ago

Thanks for your help! That fixed the issue with wsgiref. Unfortunately, I am now running into a similar ModuleNotFoundError with another package: _scproxy. This module is referenced by aiohttp, which also provides HTTP support for Python. Is it possible to remove this module from the exclusions list, assuming it has been blacklisted?

I want to say thanks for your fast response and quick turnaround time. So far, I have been very impressed with briefcase—especially compared to other Python packaging tools—and plan to use it for all of my future Python app deployment!

freakboy3742 commented 3 years ago

_scproxy is a slightly different case, because it's not a first class module that was being explicitly excluded; it's an internal utility module that wasn't being compiled at all. This has been logged independently as #127; I think I know what needs to be done, so watch that ticket for updates.

lukasvasadi commented 3 years ago

Great, thanks so much! I will keep an eye on that ticket.