OSError: Cannot load native module ‘Crypto.Hash._SHA256’

  kivy, pycrypto, pycryptodome, python, xcode

I have made an app entirely on my pc and am now bringing it across to mac to get it running one my iPhone. I am a newbie.
This is my first time using a mac and so I’ve been following this very helpful tutorial on how to package.

https://www.youtube.com/watch?v=6gLGyrlgqCU

I have done everything shown in this video and followed all kivy documentation, created a virtual environment, installed cython, build py and kivy with toolchain, added any required packages through python toolchain.py pip install, got it onto xcode and added the last remaining packages it asked for through pip.

Everything so far has been straight forward and not too complex. I’ve now hit a large hurdle that I simply cannot get over, even after spending half the day scrubbing the internet for an answer.

The answers i’m seeing seem to point to it being a problem with either loading the pyrebase module or pycryptodome (or its variants).
I have tried almost everything I’ve come across from deleting the "Crypto" folder from site-packages to even renaming every single reference to "Crypto" in that folder.

I did not build pycrypto through toolchain, is that possibly a requirement? I didn’t do so because i have seen many the post saying not to use pycrypto.

I am using:
Python 3.9.7
Xcode Version 12.5.1
Kivy
Homebrew 3.2.13

Please please help me out, I’m so close, yet so far from finishing this.

I will include the statement from Xcode that shows every time I try to run it.

2021-09-21 22:37:53.707342+1000 wxstrip[1244:30170] Available orientation: KIVY_ORIENTATION=LandscapeLeft LandscapeRight Portrait PortraitUpsideDown
2021-09-21 22:37:53.707546+1000 wxstrip[1244:30170] Initializing python
2021-09-21 22:37:54.064759+1000 wxstrip[1244:30170] Running main.py: /Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/YourApp/main.pyc
[INFO   ] [Kivy        ] v2.1.0.dev0
[INFO   ] [Kivy        ] Installed at "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/kivy/__init__.py"
[INFO   ] [Python      ] v3.9.2 (default, Sep 21 2021, 16:44:20) 
[Clang 12.0.5 (clang-1205.0.22.11)]
[INFO   ] [Python      ] Interpreter at "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/wxstrip"
[INFO   ] [Factory     ] 186 symbols loaded
[INFO   ] [Image       ] Providers: img_imageio, img_tex (img_dds, img_sdl2, img_ffpyplayer, img_pil ignored)
[INFO   ] [Text        ] Provider: sdl2
 Traceback (most recent call last):
   File "/Users/paulwilson/Weatherstrip/kivy-ios/wxstrip-ios/YourApp/main.py", line 11, in <module>
   File "/Users/paulwilson/Weatherstrip/kivy-ios/wxstrip-ios/YourApp/myfirebase.py", line 2, in <module>
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/pyrebase/__init__.py", line 1, in <module>
     from .pyrebase import initialize_app
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/pyrebase/pyrebase.py", line 17, in <module>
     from oauth2client.service_account import ServiceAccountCredentials
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/oauth2client/service_account.py", line 25, in <module>
     from oauth2client import client
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/oauth2client/client.py", line 47, in <module>
     from oauth2client import crypt
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/oauth2client/crypt.py", line 55, in <module>
     from oauth2client import _pycrypto_crypt
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/oauth2client/_pycrypto_crypt.py", line 16, in <module>
     from Crypto.Hash import SHA256
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/Crypto/Hash/SHA256.py", line 45, in <module>
     _raw_sha256_lib = load_pycryptodome_raw_lib("Crypto.Hash._SHA256",
   File "/Users/paulwilson/Library/Developer/CoreSimulator/Devices/74A68A94-885B-434D-8315-C4B6D5221FBA/data/Containers/Bundle/Application/B348F01F-CE3E-485F-ACAB-8E48061A5C01/wxstrip.app/lib/python3.9/site-packages/Crypto/Util/_raw_api.py", line 168, in load_pycryptodome_raw_lib
     raise OSError("Cannot load native module '%s'" % name)
 OSError: Cannot load native module 'Crypto.Hash._SHA256'
2021-09-21 22:37:55.369489+1000 wxstrip[1244:30170] Application quit abnormally!
2021-09-21 22:37:55.423162+1000 wxstrip[1244:30170] Leaving

Source: Python Questions

LEAVE A COMMENT