I tried to made an Android app with the Package tapo-plug, kivy and buildozer, but the app crashes directly after opening it. I never did something like this before. This is the Error-message send by my phone:
02-04 16:32:53.560 23072 23113 I python : Traceback (most recent call last):
02-04 16:32:53.561 23072 23113 I python : File "/home/daniel/test/ServerManagementApp/.buildozer/android/app/main.py", line 19, in <module>
02-04 16:32:53.561 23072 23113 I python : File "/home/daniel/test/ServerManagementApp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Vexludus/arm64-v8a/tapo_plug/tapoPlugApi.py", line 11, in <module>
02-04 16:32:53.561 23072 23113 I python : File "/home/daniel/test/ServerManagementApp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Vexludus/arm64-v8a/tapo_plug/tapoEncryption.py", line 7, in <module>
02-04 16:32:53.561 23072 23113 I python : File "/home/daniel/test/ServerManagementApp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Vexludus/arm64-v8a/Crypto/PublicKey/RSA.py", line 38, in <module>
02-04 16:32:53.561 23072 23113 I python : File "/home/daniel/test/ServerManagementApp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Vexludus/arm64-v8a/Crypto/IO/PKCS8.py", line 44, in <module>
02-04 16:32:53.561 23072 23113 I python : File "/home/daniel/test/ServerManagementApp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Vexludus/arm64-v8a/Crypto/IO/_PBES.py", line 43, in <module>
02-04 16:32:53.561 23072 23113 I python : File "/home/daniel/test/ServerManagementApp/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/Vexludus/arm64-v8a/Crypto/Hash/MD5.py", line 45, in <module>
02-04 16:32:53.561 23072 23113 I python : NameError: name 'sys' is not defined
02-04 16:32:53.561 23072 23113 I python : Python for android ended.
I already set tapo-plug,Crypto,PyCryptodome,pyjwkest,pycrypto as requirements.
This is my first time doing something like this.
This is the script-part the error occurs in:
from Crypto.Util.py3compat import *
from Crypto.Util._raw_api import (load_pycryptodome_raw_lib,
VoidPointer, SmartPointer,
create_string_buffer,
get_raw_buffer, c_size_t,
c_uint8_ptr)
_raw_md5_lib = load_pycryptodome_raw_lib("Crypto.Hash._MD5",
"""
#define MD5_DIGEST_SIZE 16
int MD5_init(void **shaState);
int MD5_destroy(void *shaState);
int MD5_update(void *hs,
const uint8_t *buf,
size_t len);
int MD5_digest(const void *shaState,
uint8_t digest[MD5_DIGEST_SIZE]);
int MD5_copy(const void *src, void *dst);
int MD5_pbkdf2_hmac_assist(const void *inner,
const void *outer,
const uint8_t first_digest[MD5_DIGEST_SIZE],
uint8_t final_digest[MD5_DIGEST_SIZE],
size_t iterations);
""")
It's hard to guess what cause your issue without minimal reproductable sample. I made simple Kivy project, it works without issues under Windows and Android.
buildozer.spec requirements:
requirements = python3,kivy,pycryptodome,pkcs7,Crypto,tapo-plug,requests,urllib3,charset_normalizer,chardet,idna
Sample code:
from kivy.app import App
from Crypto.Util.py3compat import * # pip install pycryptodome
from Crypto.Hash.MD5 import *
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from tapo_plug import tapoPlugApi # pip install tapo-plug
class app(App):
device = {
"tapoIp": "127.0.0.1",
"tapoEmail": "dummy#dummy.com",
"tapoPassword": "dummy"
}
def build(self):
return BoxLayout(orientation='vertical')
def on_start(self):
self.root.add_widget(Label(text=str(b('test'))))
self.root.add_widget(Label(text=MD5Hash(b'test').hexdigest()))
try:
self.root.add_widget(Label(text=tapoPlugApi.getDeviceInfo(self.device)))
except Exception as e:
self.root.add_widget(Label(text=str(e)))
pass
app().run()
Related
java version "1.8.0_311"
Python 3.10.8
Sikuli:-
<dependency>
<groupId>sikulixapi</groupId>
<artifactId>sikulixapi</artifactId>
<scope>system</scope>
<version>2.0.5</version>
<systemPath>${project.basedir}/sikulixapi-2.0.5.jar</systemPath>
</dependency>
I am getting the below error while running a sample python program from java.
Exception in thread "main" Traceback (most recent call last):
File "foo\boo\sikulixapi-2.0.5.jar\Lib\site.py", line 68, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\os.py", line 64, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\ntpath.py", line 12, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\warnings.py", line 395, in <module>
File "foo\boo\sikulixapi-2.0.5.jar\Lib\warnings.py", line 395, in <module>
File "__pyclasspath__/_warnings.py", line 105, in <module>
NameError: name 'ResourceWarning' is not defined
Python:-
class Hello:
__gui = None
def __init__(self, gui):
self.__gui = gui
def run(self):
print('Hello world!')
Java
package Types.UserInterface.Utilities;
import org.python.core.PyInstance;
import org.python.util.PythonInterpreter;
public class InterpreterExample {
PythonInterpreter interpreter = null;
public InterpreterExample() {
PythonInterpreter.initialize(System.getProperties(),
System.getProperties(), new String[0]);
this.interpreter = new PythonInterpreter();
}
void execfile(final String fileName) {
this.interpreter.execfile(fileName);
}
PyInstance createClass(final String className, final String opts) {
return (PyInstance) this.interpreter.eval(className + "(" + opts + ")");
}
public static void main(String gargs[]) {
InterpreterExample ie = new InterpreterExample();
ie.execfile("hello.py");
PyInstance hello = ie.createClass("Hello", "None");
hello.invoke("run");
}
}
Not sure why it is conflicting with sikuli classes while running the sample java program.
Note: Python program works perfectly fine when they are executed directly. Problem raises only when the same program is called in java.
Could someone give a direction as to what is the approach to fix this?
cf Learning how to use Jython - ResourceWarning error
Jython currently only works with Python 2, you can't use Python 3 with it (for now), hence the error.
I'm trying to translate this Java code
startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS));
to Kivy, so I can open the Android date settings dialog. So far, I tried with
from jnius import autoclass
from jnius import cast
from jnius import autoclass
from jnius import cast
PythonActivity = autoclass('org.renpy.android.PythonActivity')
intent = autoclass("android.provider.Settings")
currentActivity = cast('android.app.Activity', PythonActivity.mActivity)
currentActivity.startActivity(intent.ACTION_DATE_SETTINGS)
but I'm getting
Traceback (most recent call last):
File "main.py", line 282, in read_queue
...
File "<string>", line 7, in <module>
File "jnius/jnius_export_class.pxi", line 900, in jnius.jnius.JavaMultipleMethod.__call__ (jnius/jnius.c:27749)
JavaException: No methods matching your arguments
I tried several alternatives with setAction and setData but none works so far
When I tried to call a python file using Tensorflow library in C++ environment, I got a problem like this. I have no idea how to solve it.
This is my C++ code.
#include <Python.h>
#include <iostream>
int main(int argc, wchar_t** argv)
{
const char* picpath ="/home/senius/Pictures/zys.jpg";
Py_Initialize();
//PySys_SetArgv(argc, argv);
//PyRun_SimpleString("import sys\nprint sys.argv");
if ( !Py_IsInitialized() ) {
return -1;
}
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('/home/senius/Python/Ctensor/')");
PyObject* pMod = NULL;
PyObject* pFunc = NULL;
PyObject* pParm = NULL;
PyObject* pRetVal = NULL;
int iRetVal = -999;
const char* modulName="classify"; //这个是被调用的py文件模块名字
pMod = PyImport_ImportModule(modulName);
if(!pMod)
{
std::cout<<"Import module failed!";
PyErr_Print();
return -1;
}
const char* funcName="evaluate"; //这是此py文件模块中被调用的函数名字
pFunc = PyObject_GetAttrString(pMod, funcName);
if(!pFunc)
{
std::cout<<"Import function failed!";
return -2;
}
pParm = PyTuple_New(1);
PyTuple_SetItem(pParm, 0, Py_BuildValue("s",picpath));//传入的参数,是图片的路径
pRetVal = PyEval_CallObject(pFunc, pParm);//这里开始执行py脚本
PyArg_Parse(pRetVal, "i", &iRetVal);//py脚本返回值给iRetVal
//PyErr_Print();
std::cout<<iRetVal;
return iRetVal;
}
This is my python code.
from PIL import Image
import numpy as np
import sys
import tensorflow as tf
def evaluate(pic):
if not hasattr(sys, 'argv'):
sys.argv = ['']
image = Image.open(pic)
image = image.resize([256, 256])
image_array = np.array(image)
max_index = np.argmax([1, 2, 32])
return max_index
Once I import Tensorflow in python code, there will be a error. If I don't import Tensorflow, error disappears.
Error information is as followed.
Import module failed!Traceback (most recent call last):
File "/home/senius/Python/Ctensor/classify.py", line 4, in <module>
import tensorflow as tf
File "/home/senius/anaconda3/lib/python3.6/site- packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/__init__.py", line 63, in <module>
from tensorflow.python.framework.framework_lib import *
File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/framework_lib.py", line 76, in <module>
from tensorflow.python.framework.ops import Graph
File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 37, in <module>
from tensorflow.python.eager import context
File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/eager/context.py", line 28, in <module>
from tensorflow.python.platform import app
File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/app.py", line 23, in <module>
from tensorflow.python.platform import flags
File "/home/senius/anaconda3/lib/python3.6/site-packages/tensorflow/python/platform/flags.py", line 26, in <module>
_global_parser = _argparse.ArgumentParser()
File "/home/senius/anaconda3/lib/python3.6/argparse.py", line 1622, in __init__
prog = _os.path.basename(_sys.argv[0])
AttributeError: module 'sys' has no attribute 'argv'
You import the tensorflow module - and during that import it attempts to use sys.argv (as you can see from your stack trade) and then sometime later in some function, you have
if not hasattr(sys, 'argv'):
sys.argv = ['']`
which is the workaround to this error - but it can never be called because the import failed.
The fix is to move this to before you import the tensorflow module
I would like to integrate a simple Pygtk window in a C/C++ application (The reason being a previously designed GUI in pyGtk is to be integrated into a bigger GTK+ (in C) application)
I get Segmentation fault error
Here what i did :
=====> In python (tmp.py):
#!/usr/bin/python
#from gi.repository import Gtk, Gio
win=Gtk.Window()
win.connect("delete-event",Gtk.main_quit)
win.show_all()
Gtk.main()
======> In C/C++ (simple.cpp):
i want to just execute that little window
#include <Python.h>
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
FILE *fp = fopen ("tmp.py", "r+");
PyObject *mainModule = PyImport_AddModule("__main__");
PyObject * subModules = PyList_New(0);
PyList_Append(subModules, PyString_FromString("Gtk"));
PyList_Append(subModules, PyString_FromString("Gio"));
PyObject *Gtkstuff = PyImport_ImportModuleEx("gi.repository",NULL,NULL,subModules);
PyObject *GtkMod =PyObject_GetAttr(Gtkstuff,PyString_FromString("Gtk"));
PyObject *GioMod =PyObject_GetAttr(Gtkstuff,PyString_FromString("Gio"));
PyModule_AddObject(mainModule, "Gtk", GtkMod);
PyModule_AddObject(mainModule, "Gio", GioMod);
PyRun_SimpleFile(fp,"tmp.py");
Py_Finalize();
return 0;
}
The way how i compile is :
g++ $(python-config --cflags) -o simple $(python-config --ldflags) ./simple.cpp
The output :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/gi/importer.py", line 68, in load_module
dynamic_module._load()
File "/usr/lib64/python2.7/site-packages/gi/module.py", line 291, in _load
overrides_modules = __import__('gi.overrides', fromlist=[self._namespace])
File "/usr/lib64/python2.7/site-packages/gi/overrides/Gtk.py", line 1502, in <module>
initialized, argv = Gtk.init_check(sys.argv)
AttributeError: 'module' object has no attribute 'argv'
Traceback (most recent call last):
File "tmp.py", line 5, in <module>
win=Gtk.Window()
File "/usr/lib64/python2.7/site-packages/gi/overrides/Gtk.py", line 415, in __init__
if not initialized:
NameError: global name 'initialized' is not defined
This works perfectly, the rest of the code doesn't make sense to me, since you can do all the initialization in the python script.
#include <Python.h>
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]); /* optional but recommended */
Py_Initialize();
FILE *fp = fopen("tmp.py", "r");
if (fp == NULL)
return 2;
PyRun_SimpleFile(fp, "tmp.py");
Py_Finalize();
fclose(fp);
return 0;
}
I've followed the PyCuda instructions here: http://wiki.tiker.net/PyCuda/Installation/Mac
I'm trying to compile the following code:
import pycuda.autoinit
import pycuda.driver as drv
import numpy
from pycuda.compiler import SourceModule
mod = SourceModule("""
__global__ void multiply_them(float *dest, float *a, float *b)
{
const int i = threadIdx.x;
dest[i] = a[i] * b[i];
}
""")
multiply_them = mod.get_function("multiply_them")
a = numpy.random.randn(400).astype(numpy.float32)
b = numpy.random.randn(400).astype(numpy.float32)
dest = numpy.zeros_like(a)
multiply_them(
drv.Out(dest), drv.In(a), drv.In(b),
block=(400,1,1), grid=(1,1))
print dest-a*b
And I'm receiving the following error:
> python test.py
Traceback (most recent call last):
File "test.py", line 12, in <module>
""")
File "/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/compiler.py", line 251, in __init__
arch, code, cache_dir, include_dirs)
File "/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/compiler.py", line 241, in compile
return compile_plain(source, options, keep, nvcc, cache_dir)
File "/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/compiler.py", line 132, in compile_plain
stderr=stderr.decode("utf-8", "replace"))
pycuda.driver.CompileError: nvcc compilation of /var/folders/xr/m_rf4dp96mn2tb4yxlwcft7h0000gp/T/tmpqQcztC/kernel.cu failed
[command: nvcc --cubin -arch sm_30 -m64 -I/Library/Python/2.7/site-packages/pycuda-2013.1.1-py2.7-macosx-10.9-intel.egg/pycuda/cuda kernel.cu]
[stderr:
nvcc fatal : Path to libdevice library not specified
]
I've searched google and found the following threads, but they don't help solve the issue; http://lists.tiker.net/pipermail/pycuda/2011-June/003244.html ...
TIA!
So the problem is that I hadn't installed a minor update from the nvidia control panel. After that and updating my bash_profile it works. Heh.