Skip to content

ModuleNotFoundError: No module named '_struct' #48

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

Closed
notverypc opened this issue Jan 10, 2023 · 12 comments
Closed

ModuleNotFoundError: No module named '_struct' #48

notverypc opened this issue Jan 10, 2023 · 12 comments

Comments

@notverypc
Copy link

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.

@notverypc
Copy link
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.

@natewalck
Copy link
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.

@notverypc
Copy link
Author

I think labelling it beta would be good.

@MagerValp
Copy link

MagerValp commented Feb 24, 2023

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

@nmcspadden
Copy link

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()

@erikng
Copy link
Member

erikng commented Feb 2, 2024

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.

@notverypc
Copy link
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.

@erikng
Copy link
Member

erikng commented Feb 2, 2024

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.

@erikng
Copy link
Member

erikng commented Feb 2, 2024

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.

@erikng
Copy link
Member

erikng commented Feb 2, 2024

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()

@erikng
Copy link
Member

erikng commented Feb 2, 2024

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
>>>

@erikng
Copy link
Member

erikng commented Feb 2, 2024

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.

@erikng erikng closed this as completed Feb 2, 2024
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

No branches or pull requests

5 participants