Skip to content
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

ImportError: cannot import name 'main' #1052

Closed
brvier opened this issue Apr 8, 2020 · 12 comments
Closed

ImportError: cannot import name 'main' #1052

brvier opened this issue Apr 8, 2020 · 12 comments
Assignees
Labels

Comments

@brvier
Copy link

brvier commented Apr 8, 2020

Build failed while trying to install python dependancies :

[INFO]:    *** PYTHON PACKAGE / PROJECT INSTALL STAGE ***
[INFO]:    The requirements (certifi, gpxpy, oscpy, plyer) don't have recipes, attempting to install them with pip
[INFO]:    If this fails, it may mean that the module has compiled components and needs a recipe.
[INFO]:    -> directory context /home/user/hostcwd/.buildozer/android/platform/build-arm64-v8a/build
stty: 'standard input': Inappropriate ioctl for device
[INFO]:    -> running virtualenv --python=python3 venv
Exception in thread background thread for pid 38291:                                               
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 1540, in wrap
    fn(*args, **kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 2459, in background_thread
    handle_exit_code(exit_code)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 2157, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/user/.local/bin/virtualenv --python=python3 venv

  STDOUT:
Traceback (most recent call last):
  File "/home/user/.local/bin/virtualenv", line 7, in <module>
    from virtualenv import main
ImportError: cannot import name 'main'


  STDERR:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1212, in <module>
    main()
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 680, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 154, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 212, in build_dist_from_args
    args, "ignore_setup_py", False
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 603, in build_recipes
    ignore_setup_py=ignore_project_setup_py
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 773, in run_pymodules_install
    'venv'
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
    for line in output:
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 863, in next
    self.wait()
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 792, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/user/.local/bin/virtualenv --python=python3 venv

  STDOUT:
Traceback (most recent call last):
  File "/home/user/.local/bin/virtualenv", line 7, in <module>
    from virtualenv import main
ImportError: cannot import name 'main'

Versions

  • Python: The one use in the Dockerfile
  • OS: The one use in the Dockerfile
  • Buildozer: master

Description

  • git clone /~https://github.com/kivy/buildozer
  • cd buildozer
  • docker build --tag=buildozer .
  • mkdir test_buildozer
  • cd test_buildozer
  • docker run --volume "${HOME}/.buildozer":/home/user/.buildozer:Z --volume "${PWD}":/home/user/hostcwd:Z buildozer android debug

Logs

[INFO]:    Postbuilding kivy for arm64-v8a
[INFO]:    # Installing pure Python modules
[INFO]:    *** PYTHON PACKAGE / PROJECT INSTALL STAGE ***
[INFO]:    The requirements (certifi, gpxpy, oscpy, plyer) don't have recipes, attempting to install them with pip
[INFO]:    If this fails, it may mean that the module has compiled components and needs a recipe.
[INFO]:    -> directory context /home/user/hostcwd/.buildozer/android/platform/build-arm64-v8a/build
stty: 'standard input': Inappropriate ioctl for device
[INFO]:    -> running virtualenv --python=python3 venv
Exception in thread background thread for pid 38291:                                               
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 1540, in wrap
    fn(*args, **kwargs)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 2459, in background_thread
    handle_exit_code(exit_code)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 2157, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/user/.local/bin/virtualenv --python=python3 venv

  STDOUT:
Traceback (most recent call last):
  File "/home/user/.local/bin/virtualenv", line 7, in <module>
    from virtualenv import main
ImportError: cannot import name 'main'


  STDERR:


Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1212, in <module>
    main()
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 680, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 154, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 212, in build_dist_from_args
    args, "ignore_setup_py", False
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 603, in build_recipes
    ignore_setup_py=ignore_project_setup_py
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 773, in run_pymodules_install
    'venv'
  File "/home/user/hostcwd/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
    for line in output:
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 863, in next
    self.wait()
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 792, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/user/.local/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/user/.local/bin/virtualenv --python=python3 venv

  STDOUT:
Traceback (most recent call last):
  File "/home/user/.local/bin/virtualenv", line 7, in <module>
    from virtualenv import main
ImportError: cannot import name 'main'


  STDERR:

# Command failed: /usr/bin/python3 -m pythonforandroid.toolchain create --dist_name=ohmy --bootstrap=sdl2 --requirements=plyer,kivy,requests,openssl,certifi,gpxpy,oscpy,android --arch arm64-v8a --copy-libs --color=always --storage-dir="/home/user/hostcwd/.buildozer/android/platform/build-arm64-v8a" --ndk-api=26
# ENVIRONMENT:
#     PATH = '/home/user/.buildozer/android/platform/apache-ant-1.9.4/bin:/home/user/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
#     HOSTNAME = '5755fc8b672b'
#     P4A_RELEASE_KEYSTORE = '/home/user/hostcwd/google_keystore.jks'
#     P4A_RELEASE_KEYSTORE_PASSWD = 'xxxx'
#     P4A_RELEASE_KEYALIAS_PASSWD = 'xxxx'
#     P4A_RELEASE_KEYALIAS = 'ohmy'
#     USER = 'user'
#     HOME_DIR = '/home/user'
#     WORK_DIR = '/home/user/hostcwd'
#     SRC_DIR = '/home/user/src'
#     LANG = 'en_US.UTF-8'
#     LANGUAGE = 'en_US.UTF-8'
#     LC_ALL = 'en_US.UTF-8'
#     HOME = '/home/user'
#     PACKAGES_PATH = '/home/user/.buildozer/android/packages'
#     ANDROIDSDK = '/home/user/.buildozer/android/platform/android-sdk'
#     ANDROIDNDK = '/home/user/.buildozer/android/platform/android-ndk-r19b'
#     ANDROIDAPI = '29'
#     ANDROIDMINAPI = '26'
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

@AndreMiras
Copy link
Member

Thanks @brvier for reproducing the bug with docker in master. I'll try to look into it this week

@AndreMiras AndreMiras self-assigned this Apr 8, 2020
@AndreMiras AndreMiras added the bug label Apr 8, 2020
@brvier
Copy link
Author

brvier commented Apr 8, 2020

Wheels dependancy seems missing in the Dockerfile too :)

@brvier
Copy link
Author

brvier commented Apr 8, 2020

p4a.fork = kivy
p4a.branch = release-2020.04.01

Same error using older p4a repository, so probably not related to p4a changes :)
EDIT : oups i believe it was YYYY-DD-MM ... so that the newer not the older :)

@Sirfanas
Copy link
Contributor

Sirfanas commented Apr 8, 2020

Hi,
I got the same problem, after cloning buildozer repo's I was able to fix by changing the Dockerfile at line 78

As @brvier said, wheel was missing so I add it and I upgrade virtualenv

...
RUN pip3 install --user wheel Cython==0.28.6 ${SRC_DIR}
RUN python3 -m pip install -U pip virtualenv
...

The first one add wheel, the command will failed at the end because of 'bdist_wheel' error
The second will apply previous change without failing and will upgrade virtualenv

After building it I was able to create my apk !

Hope it will help you

PS: @AndreMiras Isn't it possible to make tag on Docker hub ? So we could just pull the previous image and use it to compile ? For eg in this case, even if I used a previous commit to build, it still crash because it was a venv dep's problem, so have a "fixed" image may help ?

@Sirfanas
Copy link
Contributor

Sirfanas commented Apr 8, 2020

I also get the same error for python 2.7 (compiling Pillow)
Opening another pull request for python2.7

brvier added a commit to brvier/buildozer that referenced this issue Apr 8, 2020
@brvier
Copy link
Author

brvier commented Apr 8, 2020

I confirm the workaround.

AndreMiras added a commit that referenced this issue Apr 8, 2020
[Python3] #1052 ImportError: cannot import name 'main'
@pasteurjr
Copy link

Hello,
I tried using android runtime permissions, as suggested by @AndreMiras, but buildozer logcat still returns the error message:

 from virtualenv import main ImportError: cannot import name 'main'

Buildozer.spec :
requirements: python3, kivy, pyjnius
android.add_aars = support-compat-27.0.0.aar

main.py

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from permissions.location import check_permission, ask_permission

class ExampleRoot(BoxLayout):

def check_fine_location_permission(self):
    check_permission("android.permission.ACCESS_FINE_LOCATION")

def request_fine_location_permission(self):
    ask_permission("android.permission.ACCESS_FINE_LOCATION")

class ExampleApp(App):
def build(self):
return ExampleRoot()

if name == 'main':
ExampleApp().run()

permissions/location.py

from jnius import autoclass
from kivy.logger import Logger

PythonActivity = autoclass("org.kivy.android.PythonActivity").mActivity
Context = autoclass('android.content.Context')
ContextCompat = autoclass('android.support.v4.content.ContextCompat')

def check_permission(permission, activity=PythonActivity):
permission_status = ContextCompat.checkSelfPermission(activity,
permission)

Logger.info(permission_status)
permission_granted = 0 == permission_status
Logger.info("Permission Status: {}".format(permission_granted))
return permission_granted

def ask_permission(permission, activity=PythonActivity):
PythonActivity.requestPermissions([permission])

Any suggestion to fix this error?

Thanks a lot

@Sirfanas
Copy link
Contributor

Sirfanas commented Apr 14, 2020

Hi @pasteurjr, are you compiling with buildozer's docker image or by your own installation ?
If you build with docker please pull the latest image

docker pull kivy/buildozer

Then recreate your buildozer's container
If it's your own installation, please update pip and virtual env

pip install --upgrade pip virtualenv

If you have both python3 and python2 installed, be sure to upgrade python3 environment with

python3 -m pip install --upgrade pip virtualenv

Hope this will help you !

@pasteurjr
Copy link

Thanks a lot @Sirfanas , it worked for me!

@dresber
Copy link

dresber commented Apr 16, 2020

@Sirfanas worked for me as well with Linux subsystem on Windows! Thank you.

@crlqjx
Copy link

crlqjx commented Apr 19, 2020

Thanks @Sirfanas

arqeco pushed a commit to arqeco/buildozer that referenced this issue Apr 21, 2020
Includes a command that fixes this issues

kivy#1052
kivy#1057
@leonidas-timefly
Copy link

When I’m building Kivy project into android app, I meet such problem:
——————————————————————
[INFO]: PYTHON PACKAGE/PROJECT INSTALL STAGE
[INFO]: The requirements(certifi) don’t have recipes, attempting to install them with pip
[INFO]: If this fails, it may mean that the module has compiled components and needs a recipe.
——————————————————————
System information:

Ubuntu18.04.4LTS
Python3.6.9(system)
pip3 list: pip(20.1) wheel(0.30.0) cython(0.29.17) certifi(2018.1.18) buildozer(1.0.1.dev0)

Plz help me

@brvier brvier closed this as completed May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants