问题
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