How can I import an package into a Kivy app using buildozer

廉价感情. 提交于 2019-12-13 04:26:36

问题


I have created a kivy app in package using the structure:

.
├── bin
│   └── myapp-0.1-debug.apk
├── buildozer.spec
└── kivy_app
    ├── __init__.py
    ├── __main__.py
    ├── main.py
    └── source
        └── kivy_app.py

I wish to use some features contained in another package that I have written:

.
└── python_pkg
    ├── __init__.py
    └── source
        └── version.py

The module version.py contains:

VERSION = '0.0.1'

When I insert the line:

from python_pkg import VERSION

into kivy_app.py, it works perfectly in kivy on the PC.

I have added python_pkg to the requirements line in buildozer.spec.

I can build an APK, but the application will not run on Android. The logcat output at the point of failure is:

ImportError: cannot import name 'VERSION' from 'python_pkg' (/data/user/0/org.test.myapp/files/app/_python_bundle/site-packages/python_pkg/__init__.pyc)

The _init_.py module in python_pkg has the line:

from python_pkg.source.version import VERSION

How must arrange the setup up so that it works?


回答1:


Thanks to @inclement I have a solution. I have created a symlink to python_pkg and placed it in the kivy_app directory. The structure of the application is now

.
├── bin
│   └── myapp-0.1-debug.apk
├── buildozer.spec
└── kivy_app
    ├── __init__.py
    ├── __main__.py
    ├── main.py
    ├── python_pkg -> /home/jeff/projects/kivy_pkg/python_pkg/python_pkg
    └── source
        └── kivy_app.py

The element python_pkg is not needed in the requirements line in buildozer.spec and I have removed it.



来源:https://stackoverflow.com/questions/57786351/how-can-i-import-an-package-into-a-kivy-app-using-buildozer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!