Skip to content

ModuleNotFoundError: No module named '_struct' #48

Closed

Description

@notverypc

Hi

I've installed "Python 3.11.1.80716" and tested a script that works with the previous Python 3.9.10 release.

I get the following error:

Could not find platform dependent libraries <exec_prefix>
Traceback (most recent call last):
  File "/Users/xxxxx/ClearMDMCommands/./CoolKids.py", line 2, in <module>
    import requests
  File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/__init__.py", line 11, in <module>
    from . import exceptions
  File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/exceptions.py", line 3, in <module>
    from .packages.six.moves.http_client import IncompleteRead as httplib_IncompleteRead
  File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/packages/six.py", line 693, in <module>
    import struct
  File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/struct.py", line 13, in <module>
    from _struct import *
ModuleNotFoundError: No module named '_struct'

I'll install the other pre-release versions and test with those.

Thanks
Ben
I’m #MadeByDyslexia – expect creative thinking & creative spelling.

Activity

  1. notverypc commented on Jan 10, 2023

    @notverypc
    Author

    Just tested the same script with:
    python_recommended_signed-3.10.9.80716.pkg
    python_recommended_signed-3.9.13.80712.pkg

    And the script works with both of those versions.

  2. natewalck commented on Jan 10, 2023

    @natewalck
    Member

    Thanks for doing this testing. It looks like requests itself doesn't full support Python 3.11.x yet: https://github.com/psf/requests/releases/tag/v2.28.0

    In the meantime, perhaps we should mark 3.11 as beta or otherwise indicate that not all libraries may support it.

  3. notverypc commented on Jan 11, 2023

    @notverypc
    Author

    I think labelling it beta would be good.

  4. MagerValp commented on Feb 24, 2023

    @MagerValp

    I don't think this has anything to do with requests per se, it's a general issue with 3.11 and relocatable-python:
    gregneagle/relocatable-python#31

  5. nmcspadden commented on Jun 20, 2023

    @nmcspadden

    With gregneagle/relocatable-python#31 (comment), I was able to work around this with simple script:

    #!/bin/zsh
    
    bin="/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/bin/python3.11"
    
    PYTHONHOME=/Library/ManagedFrameworks/Python.framework/Versions/3.11
    PYTHONPATH=/Library/ManagedFrameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload
    exec "${bin}" "$@"
    

    This script could replace the symlink for managed_python3, and solves the immediate issue:

    % /usr/local/bin/managed_python3_fixed
    Python 3.11.1 (v3.11.1:a7a450f84a, Dec  6 2022, 15:24:06) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import requests
    >>> exit()
    
  6. erikng commented on Feb 2, 2024

    @erikng
    Member

    Per the suggestion by Nick I have potentially applied his fix for both 3.11 and 3.12

    https://github.com/macadmins/python/releases/tag/v3.11.7.80735
    https://github.com/macadmins/python/releases/tag/v3.12.1.80735

    need help testing.

  7. notverypc commented on Feb 2, 2024

    @notverypc
    Author

    Hi @erikng
    I've tested the releases with a script that uses the requests library.
    Both python_recommended_signed-3.9.13.80735 and python_recommended_signed-3.10.11.80735 work as expected.

    However both python_recommended_signed-3.11.7.80735 and python_recommended_signed-3.12.1.80735 error with the following errors:

    Could not find platform dependent libraries <exec_prefix>
    Traceback (most recent call last):
      File "/Users/breilly/GitLab/MacOps/devicemigration/./V2_DeviceMigration.py", line 3, in <module>
        import requests
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/site-packages/requests/__init__.py", line 43, in <module>
        import urllib3
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/__init__.py", line 14, in <module>
        from . import exceptions
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/site-packages/urllib3/exceptions.py", line 3, in <module>
        import socket
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.11/lib/python3.11/socket.py", line 51, in <module>
        import _socket
    ModuleNotFoundError: No module named '_socket'
    
    Could not find platform dependent libraries <exec_prefix>
    Traceback (most recent call last):
      File "/Users/breilly/GitLab/MacOps/devicemigration/./V2_DeviceMigration.py", line 3, in <module>
        import requests
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.12/lib/python3.12/site-packages/requests/__init__.py", line 43, in <module>
        import urllib3
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/__init__.py", line 14, in <module>
        from . import exceptions
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/exceptions.py", line 3, in <module>
        import socket
      File "/Library/ManagedFrameworks/Python/Python3.framework/Versions/3.12/lib/python3.12/socket.py", line 52, in <module>
        import _socket
    ModuleNotFoundError: No module named '_socket'
    

    Thanks for looking into this.

    Ben
    I’m #MadeByDyslexia – expect creative thinking & creative spelling.

  8. erikng commented on Feb 2, 2024

    @erikng
    Member

    What is your shebang? Or how are you invoking the script? Per Nick's comment it seemed to suggest that you would not be able to use the direct shebang path by the instead use the shim.

  9. erikng commented on Feb 2, 2024

    @erikng
    Member

    Okay I think my build script failed. I see the original symbolic link and I think it didn't get installed, but you already have it from the 3.9 and 3.10 tests. Will investigate today.

  10. erikng commented on Feb 2, 2024

    @erikng
    Member

    https://github.com/macadmins/python/releases/tag/v3.9.13.80737
    https://github.com/macadmins/python/releases/tag/v3.10.11.80737
    https://github.com/macadmins/python/releases/tag/v3.11.7.80737
    https://github.com/macadmins/python/releases/tag/v3.12.1.80737

    I've tested 3.12.1.80737 and I am able to import the requests library

    → managed_python3
    Python 3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:39) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import requests
    >>> exit()
    
  11. erikng commented on Feb 2, 2024

    @erikng
    Member

    so interestingly, I can't get the error reported with requests when not using the shim

    → /Library/ManagedFrameworks/Python/Python3.framework/Versions/3.12/bin/python3.12
    Python 3.12.1 (v3.12.1:2305ca5144, Dec  7 2023, 17:23:39) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import requests
    >>>
    
  12. erikng commented on Feb 2, 2024

    @erikng
    Member

    I read the other linked ticket again and now I understand why. so if you call it's full path it works, the shim is what doesn't work. I'm closing this as it's solved for now with the hack nick posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions