No module named '_ssl'

308 views
Skip to first unread message

Robin PICARD

unread,
Jan 26, 2022, 2:42:14 PM1/26/22
to Kivy users support
Hello everyone!

I've run into the issue mentioned in the title when I added to my kivy app a library depending on ssl (before that the app was working perfectly well). I can still package it successfully but then when actually running the app on an Android phone, it crashes. I would be very grateful if someone could help me.

* Python: 3.9.5
* OS: MacOS Big Sur 11.4
* Buildozer: 1.2.0

buildozer.spec
I only changed this line from the default:
requirements = openssl, python3, kivy

main.py
I've tried with the most minimal app to isolate the issue, it fails at the very first line:
import ssl

buildozer android debug
As said at the beginning, everyone looks fine
[DEBUG]:           BUILD SUCCESSFUL in 2s
[DEBUG]:           25 actionable tasks: 5 executed, 20 up-to-date
[INFO]:    <- directory context /Users/robin/Desktop/TestB/.buildozer/android/platform/python-for-android
[INFO]:    Of the existing distributions, the following meet the given requirements:
[INFO]:            myapp: min API 21, includes recipes (hostpython3, libffi, openssl, sdl2_image, sdl2_mixer, sdl2_ttf, sqlite3, python3, sdl2, setuptools, six, pyjnius, android, kivy, certifi), built for archs (armeabi-v7a)
[INFO]:    myapp has compatible recipes, using this one
[INFO]:    # Copying android package to current directory
[INFO]:    # Android package filename not found in build output. Guessing...
[INFO]:    # Found android package file: /Users/robin/Desktop/TestB/.buildozer/android/platform/build-armeabi-v7a/dists/myapp__armeabi-v7a/build/outputs/apk/debug/myapp__armeabi-v7a-debug.apk

buildozer android logcat
Here comes the trouble
01-26 20:12:24.635 15154 15178 I python  : Initializing Python for Android
01-26 20:12:24.635 15154 15178 I python  : Setting additional env vars from p4a_env_vars.txt
01-26 20:12:24.635 15154 15178 I python  : Changing directory to the one provided by ANDROID_ARGUMENT
01-26 20:12:24.635 15154 15178 I python  : /data/user/0/org.test.myapp/files/app
01-26 20:12:24.635 15154 15178 I python  : Preparing to initialize python
01-26 20:12:24.635 15154 15178 I python  : _python_bundle dir exists
01-26 20:12:24.635 15154 15178 I python  : calculated paths to be...
01-26 20:12:24.635 15154 15178 I python  : /data/user/0/org.test.myapp/files/app/_python_bundle/stdlib.zip:/data/user/0/org.test.myapp/files/app/_python_bundle/modules
01-26 20:12:24.635 15154 15178 I python  : set wchar paths...
01-26 20:12:24.667  3124  3166 I ActivityManager: Displayed org.test.myapp/org.kivy.android.PythonActivity: +299ms
01-26 20:12:24.667  3124  3166 D DPerf   : DPerf module initialized
01-26 20:12:24.668   548   548 W /system/bin/hwservicemanager: getTransport: Cannot find entry vendor.qti.hardware.iop@2.0::IIop/default in either framework or device manifest.
01-26 20:12:24.668  3124  3166 E ANDR-PERF-JNI: Iop tryGetService failed
01-26 20:12:24.668  3124  3166 D SmartisanLaunch: cold launch: package:org.test.myapp    activity:org.test.myapp/org.kivy.android.PythonActivity   start_time:86622608   end_time:86622939   duration:331ms
01-26 20:12:24.670 15154 15154 V SDL     : onWindowFocusChanged(): true
01-26 20:12:24.670 15154 15178 I python  : Initialized python
01-26 20:12:24.670 15154 15178 I python  : AND: Init threads
01-26 20:12:24.671 15154 15178 I python  : testing python print redirection
01-26 20:12:24.672 15154 15178 I python  : Android path ['.', '/data/user/0/org.test.myapp/files/app/_python_bundle/stdlib.zip', '/data/user/0/org.test.myapp/files/app/_python_bundle/modules', '/data/user/0/org.test.myapp/files/app/_python_bundle/site-packages']
01-26 20:12:24.672 15154 15178 I python  : os.environ is environ({'PATH': '/sbin:/system/sbin:/system/bin:/system/xbin:/vendor/bin:/vendor/xbin', 'DOWNLOAD_CACHE': '/data/cache', 'ANDROID_BOOTLOGO': '1', 'ANDROID_ROOT': '/system', 'ANDROID_ASSETS': '/system/app', 'ANDROID_DATA': '/data', 'ANDROID_STORAGE': '/storage', 'EXTERNAL_STORAGE': '/sdcard', 'ASEC_MOUNTPOINT': '/mnt/asec', 'BOOTCLASSPATH': '/system/framework/QPerformance.jar:/system/framework/DPerformance.jar:/system/framework/core-oj.jar:/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/bouncycastle.jar:/system/framework/apache-xml.jar:/system/framework/legacy-test.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/org.apache.http.legacy.boot.jar:/system/framework/android.hidl.base-V1.0-java.jar:/system/framework/android.hidl.manager-V1.0-java.jar:/system/framework/smartisanos.jar:/system/framework/sys-framework.jar:/system/framework/tcmiface.jar:/system/framework/telephony-ext.jar:/system/framework/WfdCommon.jar', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar:/system/framework/com.android.location.provider.jar:/system/framework/smartisan-services-tnt.jar:/system/framework/sys-services.jar', 'ANDROID_SOCKET_zygote_secondary': '8', 'ANDROID_ENTRYPOINT': 'main.pyc', 'ANDROID_ARGUMENT': '/data/user/0/org.test.myapp/files/app', 'ANDROID_APP_PATH': '/data/user/0/org.test.myapp/files/app', 'ANDROID_PRIVATE': '/data/user/0/org.test.myapp/files', 'ANDROID_UNPACK': '/data/user/0/org.test.myapp/files/app', 'PYTHONHOME': '/data/user/0/org.test.myapp/files/app', 'PYTHONPATH': '/data/user/0/org.test.myapp/files/app:/data/user/0/org.test.myapp/files/app/lib', 'PYTHONOPTIMIZE': '2', 'P4A_BOOTSTRAP': 'SDL2', 'PYTHON_NAME': 'python', 'P4A_IS_WINDOWED': 'True', 'P4A_ORIENTATION': 'portrait', 'P4A_NUMERIC_VERSION': 'None', 'P4A_MINSDK': '21', 'LC_CTYPE': 'C.UTF-8'})
01-26 20:12:24.672 15154 15178 I python  : Android kivy bootstrap done. __name__ is __main__
01-26 20:12:24.672 15154 15178 I python  : AND: Ran string
01-26 20:12:24.672 15154 15178 I python  : Run user program, change dir and execute entrypoint
01-26 20:12:24.689 15154 15178 I python  : Traceback (most recent call last):
01-26 20:12:24.689 15154 15178 I python  :   File "/Users/robin/Desktop/TestB/.buildozer/android/app/main.py", line 1, in <module>
01-26 20:12:24.689 15154 15178 I python  :   File "<frozen zipimport>", line 259, in load_module
01-26 20:12:24.689 15154 15178 I python  :   File "/Users/robin/Desktop/TestB/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/python3/armeabi-v7a__ndk_target_21/python3/Lib/ssl.py", line 98, in <module>
01-26 20:12:24.689 15154 15178 I python  : ModuleNotFoundError: No module named '_ssl'
01-26 20:12:24.689 15154 15178 I python  : Python for android ended.

I've tried some of the things I found online but with no success:
I am quite confused since I have seen in the python-for-android module that the recipe for python2 does included ssl (https://github.com/kivy/python-for-android/blob/develop/pythonforandroid/recipes/python3/__init__.py)

Have a good day!

Robert

unread,
Jan 26, 2022, 4:35:09 PM1/26/22
to Kivy users support
The message implies to me that Python was not built with ssl.

Look further up the log at the builds of python and hostpython, are there any ssl related warnings?

I suggest you'd have a better chance of finding a Buildozer with Mac user on Discord https://discord.gg/7NUjWA77

Robin PICARD

unread,
Jan 27, 2022, 4:33:46 AM1/27/22
to Kivy users support
Hi Robert!

Thanks so much for your answer! I will look at the Discord group.
You were right in suggesting to look further up in the log of the hostpython's build. There, I could see that setup.py failed to build the _ssl module.
I used a bunch of print statements in the setup.py file to try to understand what's going on. 
It does find a openssl/ssl.h file at the location /usr/local/include/.

But then, when running:
            self.add(Extension(
                '_ssl', ['_ssl.c'],
                include_dirs=openssl_includes,
                library_dirs=openssl_libdirs,
                libraries=openssl_libs,
                depends=['socketmodule.h', '_ssl/debughelpers.c'])
            )
,
the values of the 3 variables included are set (a few lines before) to the configuration variables OPENSSL_INCLUDES, OPENSSL_LDFLAGS and OPENSSL_LIBS

My values of those configuration variables are:
  • OPENSSL_INCLUDES= -I/tmp/_py/libraries/usr/local/include
  • OPENSSL_LDFLAGS= -L/tmp/_py/libraries/usr/local/lib
  • OPENSSL_LIBS= -lssl -lcrypto
Those values don't look like the kind of paths I'm used to (and indeed do not seem to point to anything).
I'm quite surprised by those since when going to the Makefile that is supposed to set such variables, I see the following (which does point to the right places):

# OpenSSL options for setup.py so sysconfig can pick up AC_SUBST() vars.
OPENSSL_INCLUDES=-I/usr/local/Cellar/openssl@3/3.0.1/include
OPENSSL_LIBS=-lssl -lcrypto
OPENSSL_LDFLAGS=-L/usr/local/Cellar/openssl@3/3.0.1/lib

Do you have an idea of what could be going on? It seems I'm getting in quite a dark wood haha.
In any case, thanks again for taking the time to answer to my initial post!

Robert

unread,
Jan 27, 2022, 12:27:27 PM1/27/22
to Kivy users support
Good degug, it does look like a (p4a) Python build issue.
And yes /tmp/_py/ looks strange to me too.

But I do not have any idea why this would be.
My guess is this is Mac/Brew related.

There are not a lot of Buildozer/Mac users, better chance of finding somebody who knows on Discord.

Robin PICARD

unread,
Jan 27, 2022, 1:27:03 PM1/27/22
to Kivy users support
I just posted a message there!
Have a good evening

Reply all
Reply to author
Forward
0 new messages