-
Notifications
You must be signed in to change notification settings - Fork 30
how can I call funtions from a python file? #2
Comments
@mhsmith ,thank you very much,but it still not work for me.And can I run the python files in other path,like can I connect you with other place then I can ask you this question quickly and in more detail when you are free. |
To load Python files from another location, you could add that location to If you're unable to load Python modules even from the standard location with Python.getModule, then you'll have to give more details of what you tried and what happened. If you want to pay for private support, please email the contact address on our website. Otherwise, it's better to continue the discussion here so other people can benefit from it. |
@mhsmith I have try like that:
But it not work. |
I assume you didn't receive any error: if you did receive one, then please say what it was. Standard output is ignored by default in Android apps (this applies to Java just as much as Python), so I wouldn't expect your script output to be visible anywhere. The easiest starting point to make it visible would be to use the UnitTestActivity from the demo app, i.e. something like this (untested but should be pretty close):
You'll also need to include a few resource files used by the base activity: build errors should indicate which ones. |
@mhsmith ,I try add UnitTestActivity and ConsoleActivity and other resouce into the project,and change the MainActivity like your answer.
Then get the error:
|
Starting Python in that method is too late because Python is also used by the Alternatively, change |
Have you been able to make it work? |
I suggest to put "Quick Start" an example .py as "Hello Chaquopy" in Chaquopy web site. And more simple examples which like how to use Android Component to indicate pictures, take picture, to use compass, GPS with Google API..... |
@mhsmith thank you for help,I not make it work. I think this solution maybe more difficult for me.When I try an another solution starcore_for_android ,I think is more suitable for me. |
@zcanfly Please try using PyApplication as shown here: chaquopy-hello/app/src/main/AndroidManifest.xml Lines 5 to 6 in 05d720b
If that still doesn't work, please let me know what happens. I agree it's not easy enough to run a simple Python console script. We'll release another example app soon for that use case. Also, the next Chaquopy version will send stdout and stderr to the Android logcat, just like in Java. |
@hushanhsiang The principles of how to use Android APIs in Chaquopy should be clear from the UI demo here: https://github.com/chaquo/chaquopy/blob/master/app/src/main/python/chaquopy/demo/ui_demo.py You should be able to translate examples of any other APIs from Java to Python in the same way, including the things you mention. |
(Moved unrelated question to chaquo/chaquopy#22 -- mhsmith) |
@zcanfly: please have a look at the chaquopy-console project: it provides an easy way to run text-based Python programs on Android. |
It's required to pass a java class as a base class in StaticProxy. How to set StaticProxy of a python class which inheritate another python class? And if the python class contains dependencies(e.g. import six), just need to include the dependency in gradle? |
You can inherit from Python classes, as long as the
Since no Java base classes are specified here, Java will see this class as inheriting only from Dependencies are installed through |
…usable without PyApplication (chaquo/chaquopy-hello#2)
I want to run same python files in my android project.and I config the chaquopy into my android project.Then I read the documents of API,but how can I run the python files or call python file function with those java API?
The text was updated successfully, but these errors were encountered: