kivy / kivy-ios

Toolchain for compiling Python / Kivy / other libraries for iOS
https://kivy.org/docs/guide/packaging-ios.html
MIT License
777 stars 240 forks source link

ModuleNotFoundError: No module named '_ctypes' when building host_setuptools3 on Apple Silicon #640

Closed sltoo777 closed 3 years ago

sltoo777 commented 3 years ago

Versions

Describe the bug error when i run toolchain build kivy

Logs

[INFO    ] Building with 8 processes, where supported
[INFO    ] Want to build ['kivy']
[INFO    ] Loaded recipe kivy (depends of ['sdl2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'ios', 'pyobjus', 'python', 'host_setuptools3'], optional are [])
[INFO    ] Loaded recipe sdl2 (depends of [], optional are [])
[INFO    ] Loaded recipe sdl2_image (depends of ['sdl2'], optional are [])
[INFO    ] Loaded recipe sdl2_mixer (depends of ['sdl2'], optional are [])
[INFO    ] Loaded recipe sdl2_ttf (depends of ['sdl2', 'freetype'], optional are [])
[INFO    ] Loaded recipe ios (depends of ['python'], optional are [])
[INFO    ] Loaded recipe pyobjus (depends of ['python'], optional are [])
[INFO    ] Loaded recipe python (depends of ['python3'], optional are [])
[INFO    ] Loaded recipe host_setuptools3 (depends of ['openssl', 'hostpython3', 'python3'], optional are [])
[INFO    ] Loaded recipe freetype (depends of [], optional are [])
[INFO    ] Loaded recipe python3 (depends of ['hostpython3', 'libffi', 'openssl'], optional are [])
[INFO    ] Loaded recipe openssl (depends of [], optional are [])
[INFO    ] Loaded recipe hostpython3 (depends of ['hostlibffi', 'hostopenssl'], optional are [])
[INFO    ] Loaded recipe libffi (depends of [], optional are [])
[INFO    ] Loaded recipe hostlibffi (depends of [], optional are [])
[INFO    ] Loaded recipe hostopenssl (depends of [], optional are [])
[INFO    ] Build order is ['freetype', 'hostlibffi', 'hostopenssl', 'libffi', 'openssl', 'sdl2', 'hostpython3', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'python3', 'host_setuptools3', 'python', 'ios', 'pyobjus', 'kivy']
[INFO    ] Recipe order is ['freetype', 'hostlibffi', 'hostopenssl', 'libffi', 'openssl', 'sdl2', 'hostpython3', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', 'python3', 'host_setuptools3', 'ios', 'pyobjus', 'kivy']
[INFO    ] Include dir added: {arch.arch}/freetype
[INFO    ] Include dir added: {arch.arch}/hostlibffi
[INFO    ] Include dir added: {arch.arch}/ffi
[INFO    ] Include dir added: {arch.arch}/openssl
[INFO    ] Include dir added: common/sdl2
[INFO    ] Global: hostpython located at /Users/mahdi/Documents/ios-app/dist/hostpython3/bin/python
[INFO    ] Global: hostpgen located at /Users/mahdi/Documents/ios-app/dist/hostpython3/bin/pgen
[INFO    ] Include dir added: common/sdl2_image
[INFO    ] Include dir added: common/sdl2_mixer
[INFO    ] Include dir added: common/sdl2_ttf
[DEBUG   ] Cached result: Download freetype. Ignoring
[DEBUG   ] Cached result: Extract freetype. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites freetype. Ignoring
[DEBUG   ] Cached result: Build_all freetype. Ignoring
[DEBUG   ] Cached result: Download hostlibffi. Ignoring
[DEBUG   ] Cached result: Extract hostlibffi. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites hostlibffi. Ignoring
[INFO    ] Build hostlibffi for x86_64 (filtered)
[DEBUG   ] Cached result: Build hostlibffi. Ignoring
[DEBUG   ] New State: hostlibffi.build_all at 2021-09-04 10:42:54.926362
[DEBUG   ] Cached result: Download hostopenssl. Ignoring
[DEBUG   ] Cached result: Extract hostopenssl. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites hostopenssl. Ignoring
[DEBUG   ] Cached result: Build_all hostopenssl. Ignoring
[DEBUG   ] Cached result: Download libffi. Ignoring
[DEBUG   ] Cached result: Extract libffi. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites libffi. Ignoring
[DEBUG   ] Cached result: Build_all libffi. Ignoring
[DEBUG   ] Cached result: Download openssl. Ignoring
[DEBUG   ] Cached result: Extract openssl. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites openssl. Ignoring
[DEBUG   ] Cached result: Build_all openssl. Ignoring
[DEBUG   ] Cached result: Download sdl2. Ignoring
[DEBUG   ] Cached result: Extract sdl2. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites sdl2. Ignoring
[DEBUG   ] Cached result: Build_all sdl2. Ignoring
[DEBUG   ] Cached result: Download hostpython3. Ignoring
[DEBUG   ] Cached result: Extract hostpython3. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites hostpython3. Ignoring
[DEBUG   ] Cached result: Build_all hostpython3. Ignoring
[DEBUG   ] Cached result: Download sdl2_image. Ignoring
[DEBUG   ] Cached result: Extract sdl2_image. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites sdl2_image. Ignoring
[DEBUG   ] Cached result: Build_all sdl2_image. Ignoring
[DEBUG   ] Cached result: Download sdl2_mixer. Ignoring
[DEBUG   ] Cached result: Extract sdl2_mixer. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites sdl2_mixer. Ignoring
[DEBUG   ] Cached result: Build_all sdl2_mixer. Ignoring
[DEBUG   ] Cached result: Download sdl2_ttf. Ignoring
[DEBUG   ] Cached result: Extract sdl2_ttf. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites sdl2_ttf. Ignoring
[DEBUG   ] Cached result: Build_all sdl2_ttf. Ignoring
[DEBUG   ] Cached result: Download python3. Ignoring
[DEBUG   ] Cached result: Extract python3. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites python3. Ignoring
[DEBUG   ] Cached result: Build_all python3. Ignoring
[DEBUG   ] Cached result: Download host_setuptools3. Ignoring
[DEBUG   ] Cached result: Extract host_setuptools3. Ignoring
[DEBUG   ] Cached result: Install_hostpython_prerequisites host_setuptools3. Ignoring
[INFO    ] Build_all host_setuptools3
[INFO    ] Build host_setuptools3 for x86_64 (filtered)
[DEBUG   ] Cached result: Build host_setuptools3. Ignoring
[INFO    ] Install include files for host_setuptools3
[DEBUG   ] Cached result: Install_include host_setuptools3. Ignoring
[INFO    ] Install frameworks for host_setuptools3
[DEBUG   ] Cached result: Install_frameworks host_setuptools3. Ignoring
[INFO    ] Install sources for host_setuptools3
[DEBUG   ] Cached result: Install_sources host_setuptools3. Ignoring
[INFO    ] Install python deps for host_setuptools3
[DEBUG   ] Cached result: Install_python_deps host_setuptools3. Ignoring
[INFO    ] Install host_setuptools3
[INFO    ] Install host_setuptools3
[DEBUG   ] Setting PYTHONPATH to /Users/mahdi/Documents/ios-app/dist/root/python3/lib/python3.9/site-packages
[INFO    ] cd /Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2
[INFO    ] Running Shell: /Users/mahdi/Documents/ios-app/dist/hostpython3/bin/python ('setup.py', 'install', '--prefix=/Users/mahdi/Documents/ios-app/dist/root/python3') {'_iter': True, '_out_bufsize': 1, '_err_to_out': True}
[DEBUG   ] Traceback (most recent call last):
[DEBUG   ]   File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setup.py", line 7, in <module>
[DEBUG   ]     import setuptools
[DEBUG   ]   File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/__init__.py", line 18, in <module>
[DEBUG   ]     from setuptools.dist import Distribution
[DEBUG   ]   File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/dist.py", line 34, in <module>
[DEBUG   ]     from setuptools import windows_support
[DEBUG   ]   File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/windows_support.py", line 2, in <module>
[DEBUG   ]     import ctypes
[DEBUG   ]   File "/Users/mahdi/Documents/ios-app/dist/hostpython3/lib/python3.9/ctypes/__init__.py", line 8, in <module>
[DEBUG   ]     from _ctypes import Union, Structure, Array
[DEBUG   ] ModuleNotFoundError: No module named '_ctypes'
Exception in thread background thread for pid 62030:
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/sh.py", line 1683, in wrap
    fn(*rgs, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/sh.py", line 2662, in background_thread
    handle_exit_code(exit_code)
  File "/opt/homebrew/lib/python3.9/site-packages/sh.py", line 2349, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/opt/homebrew/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /Users/mahdi/Documents/ios-app/dist/hostpython3/bin/python setup.py install --prefix=/Users/mahdi/Documents/ios-app/dist/root/python3

  STDOUT:
Traceback (most recent call last):
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setup.py", line 7, in <module>
    import setuptools
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/__init__.py", line 18, in <module>
    from setuptools.dist import Distribution
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/dist.py", line 34, in <module>
    from setuptools import windows_support
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/windows_support.py", line 2, in <module>
    import ctypes
  File "/Users/mahdi/Documents/ios-app/dist/hostpython3/lib/python3.... (138 more, please see e.stdout)

  STDERR:

[INFO    ] cd /Users/mahdi/Documents/ios-app
[DEBUG   ] Setting PYTHONPATH to None
Traceback (most recent call last):
  File "/opt/homebrew/bin/toolchain", line 8, in <module>
    sys.exit(main())
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1536, in main
    ToolchainCL()
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1293, in __init__
    getattr(self, args.command)()
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1354, in build
    build_recipes(args.recipe, ctx)
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1136, in build_recipes
    recipe.execute()
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 703, in execute
    self.build_all()
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 73, in _cache_execution
    f(self, *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 829, in build_all
    self.install()
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 73, in _cache_execution
    f(self, *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/recipes/host_setuptools3/__init__.py", line 20, in install
    shprint(hostpython, "setup.py", "install",
  File "/opt/homebrew/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 55, in shprint
    for line in cmd:
  File "/opt/homebrew/lib/python3.9/site-packages/sh.py", line 953, in next
    self.wait()
  File "/opt/homebrew/lib/python3.9/site-packages/sh.py", line 879, in wait
    self.handle_command_exit_code(exit_code)
  File "/opt/homebrew/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /Users/mahdi/Documents/ios-app/dist/hostpython3/bin/python setup.py install --prefix=/Users/mahdi/Documents/ios-app/dist/root/python3

  STDOUT:
Traceback (most recent call last):
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setup.py", line 7, in <module>
    import setuptools
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/__init__.py", line 18, in <module>
    from setuptools.dist import Distribution
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/dist.py", line 34, in <module>
    from setuptools import windows_support
  File "/Users/mahdi/Documents/ios-app/build/host_setuptools3/x86_64/setuptools-54.1.2/setuptools/windows_support.py", line 2, in <module>
    import ctypes
  File "/Users/mahdi/Documents/ios-app/dist/hostpython3/lib/python3.... (138 more, please see e.stdout)

  STDERR:
misl6 commented 3 years ago

Are you on a M1-based device?

sltoo777 commented 3 years ago

yes it's macbook pro 13-inch M1 2020

misl6 commented 3 years ago

Are you using rosetta?

sltoo777 commented 3 years ago

I try with rosetta and without rosetta and both give me the same error

misl6 commented 3 years ago

The error log you posted is from a rosetta terminal?

sltoo777 commented 3 years ago

yes

costa-rica commented 3 years ago

I am having the same issue. Mac OS: 11.2.3 Python: 3.9.7 Xcode: 12.5.1 Cython:0.29.23

akshayaurora commented 3 years ago

I just built using rosetta, without any issues. Try cleaning the .buildozer dir and then making sure you run with rosetta.

To test when you open terminal with rosetta, open System Monitor in CPU tab it should show intel instead of apple on the architecture column.

Similarly Make sure when you run python3 from the terminal, the binary python shows up as intel. Once you have made sure of these 2 things. Just clean the build and start a new one. It should work.

Also make sure to use Python3.9.x multi arch download from Python.org. <-this was the key to get python3 to show up as running from intel arch.

sltoo777 commented 3 years ago

How I run python3 with rosetta?

akshayaurora commented 3 years ago

How I run python3 with rosetta?

Also make sure to use Python3.9.x multi arch download from Python.org. <-this was the key to get python3 to show up as running from intel arch.

costa-rica commented 3 years ago

Thank you yes, I am now getting 'configure: error: Unexpected output of 'arch' on OSX'. Would you provide a little more specifics on how I can check or replace that file/dir?

sltoo777 commented 3 years ago

It's give me this error `[DEBUG ] FileNotFoundError: [Errno 2] No such file or directory: '/opt/homebrew/bin/cython' Exception in thread background thread for pid 41644: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 973, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 910, in run self._target(*self._args, *self._kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sh.py", line 1683, in wrap fn(rgs, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sh.py", line 2662, in background_thread handle_exit_code(exit_code) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sh.py", line 2349, in fn return self.command.handle_command_exit_code(exit_code) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code raise exc sh.ErrorReturnCode_1:

RAN: /Users/mahdi/Documents/ios-app/venv/bin/python /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py ios.pyx

STDOUT: -- cythonize ['/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py', 'ios.pyx'] cythonize: ios.pyx Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py", line 58, in do(fn) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py", line 32, in do subprocess.Popen([cython, fn], env=os.environ).communicate() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/Library/Frameworks/Python.framewor... (222 more, please see e.stdout)

STDERR:

Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/bin/toolchain", line 8, in sys.exit(main()) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1519, in main ToolchainCL() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1276, in init getattr(self, args.command)() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1337, in build build_recipes(args.recipe, ctx) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1127, in build_recipes recipe.execute() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 699, in execute self.build_all() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 73, in _cache_execution f(self, *args, *kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 793, in build_all self.build(arch) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 73, in _cache_execution f(self, args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 780, in build self.build_arch(arch) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1079, in build_arch self.cythonize_build() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1052, in cythonize_build self.cythonize_file(join(root, filename)) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 1044, in cythonize_file shprint(sh.python, cythonize_script, filename) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/toolchain.py", line 55, in shprint for line in cmd: File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sh.py", line 953, in next self.wait() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sh.py", line 879, in wait self.handle_command_exit_code(exit_code) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/sh.py", line 905, in handle_command_exit_code raise exc sh.ErrorReturnCode_1:

RAN: /Users/mahdi/Documents/ios-app/venv/bin/python /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py ios.pyx

STDOUT: -- cythonize ['/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py', 'ios.pyx'] cythonize: ios.pyx Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py", line 58, in do(fn) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/kivy_ios/tools/cythonize.py", line 32, in do subprocess.Popen([cython, fn], env=os.environ).communicate() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 951, in init self._execute_child(args, executable, preexec_fn, close_fds, File "/Library/Frameworks/Python.framewor... (222 more, please see e.stdout)

STDERR:

`

akshayaurora commented 3 years ago

Please don't mix homebrew modules modules with python3 from python.org.

I am closing this issue cause this is a support request, not a actual issue. Please use support channels for support request.