tomye 1 Posted October 29, 2022 wriiten a scipt, it can be run in Python environment but run in P4D, got an error anyone knows? Share this post Link to post
pyscripter 694 Posted October 29, 2022 (edited) Is there another sqlite dll in your path? Edited October 29, 2022 by pyscripter Share this post Link to post
SwiftExpat 65 Posted October 29, 2022 Anaconda shows to be 64 bit, what platform are you targeting in Delphi? Share this post Link to post
tomye 1 Posted October 30, 2022 (edited) 9 hours ago, pyscripter said: Is there another sqlite dll in your path? actually , i don't know why the torch uses the SQLite, however , i searched the DLL files, they are all there and all of them are 64bit and this error message ( Not a valid win32 application ) is only appear on P4D Demo01, but in my project, there is another error message the error message is : OSError: [WinError 127] The specified program could not be found same script i could run it in Python envirnoment, but can not be run in P4D , BTW, my project uses P4D thread mode ( TPythonThread.Py_Begin_Allow_Threads; ) and then i test the script in P4D Demo01, got an another error message: Not a valid win32 application 😞 Edited October 30, 2022 by tomye Share this post Link to post
tomye 1 Posted October 30, 2022 7 hours ago, SwiftExpat said: Anaconda shows to be 64 bit, what platform are you targeting in Delphi? my project is 64-bit the anaconda which i installed is 64-bit the python dependent libraries are all 64-bit Share this post Link to post
David Heffernan 2353 Posted October 30, 2022 This kind of error is all too familiar when embedding Anaconda. I never have such troubles with vanilla Python. Share this post Link to post
pyscripter 694 Posted October 30, 2022 16 hours ago, tomye said: the anaconda which i installed is 64-bit PythonHome needs to be set even for registered conda distributions See TPythonVersion.AssignTo(PythonEngine: TPersistent); in PythonVersions.pas about this is done. Note also that for conda distributions to work properly, you need to add Format('%s;%0:s\Library\bin;', [Version.InstallPath] to your Windows path if it is not there already. Share this post Link to post
tomye 1 Posted October 31, 2022 (edited) 9 hours ago, pyscripter said: PythonHome needs to be set even for registered conda distributions See TPythonVersion.AssignTo(PythonEngine: TPersistent); in PythonVersions.pas about this is done. Note also that for conda distributions to work properly, you need to add Format('%s;%0:s\Library\bin;', [Version.InstallPath] to your Windows path if it is not there already. i found this issue comes from the P4D thread mode i am not sure if it is P4D BUG because now i can run the script in P4D Demo01 after i PIP INSTALL PYSQLITE3, but still can not be run in my project, will raise an error: could not find cudnn_adv_infer64_8.dll or one of its dependent file the cudnn_adv_infer64_8.dll and all of its dependent files are existing as i said, i set TPythonThread.Py_Begin_Allow_Threads; in my code, and all running are in thread mode, i don't know if the Python path is lost in thread mode Edited October 31, 2022 by tomye Share this post Link to post
pyscripter 694 Posted October 31, 2022 (edited) 17 hours ago, tomye said: as i said, i set TPythonThread.Py_Begin_Allow_Threads; Why are you making things complicated? Follow the KISS rule. Using threads in this way requires deep knowledge of the Python API and the complexities of GIL. If do have to use threads, please study Demo 11 and the related posts in this forum Showing results for 'Py_Begin_Allow_Threads'. - Delphi-PRAXiS [en] (delphipraxis.net) Edited October 31, 2022 by pyscripter Share this post Link to post
tomye 1 Posted November 1, 2022 (edited) 15 hours ago, pyscripter said: Why are you making things complicated? Follow the KISS rule. Using threads in this way requires deep knowledge of the Python API and the complexities of GIL. If do have to use threads, please study Demo 11 and the related posts in this forum Showing results for 'Py_Begin_Allow_Threads'. - Delphi-PRAXiS [en] (delphipraxis.net) I don't want it to be that complicated either, but Python's performance is too low if i don't use thread to run , the speed and GPU useage % as below: if i lanuch 2 threads : if i lanuch 3 threads: single fps will be reduced but Avg fps will be raised if i use 3 threads so this is only way i can figure out to up the speed. 😞 acutally, i have finished the thread mode program running in the past months but recently, i changed the AI engine from ONNX to TORCH, after installed pytorch everything becomes unsteady, but if i switch the pythone envirnoment to old path everything comes back , very steady. i feel the issue comes from CUDA apis and CUDA envirnoment but i still can not find it out, so come here for help . 😞 Edited November 1, 2022 by tomye Share this post Link to post
pyscripter 694 Posted November 1, 2022 Running python in threads does not increase python code speed due to the GIL. Only one thread executes at any point in time. Torch can do its own mutli-threading so again there is no need to use threads. The main reason for using python threads is to avoid blocking the UI. Share this post Link to post
tomye 1 Posted November 2, 2022 12 hours ago, pyscripter said: Running python in threads does not increase python code speed due to the GIL. Only one thread executes at any point in time. Torch can do its own mutli-threading so again there is no need to use threads. The main reason for using python threads is to avoid blocking the UI. Yes, Torch is much better than onnx, i have tested. yesterday, i droped the thread mode and create a new project without thread mode but still got this error: very strange, if i run the onnx script first and then run the torch script , then will get this error , but if i run the torch script first and then run the onnx script , all are ok i think it should be an old version of CUDA dlls is called if the onnx script runs first and torch does not support this version but the onnxruntime supports the high version which the torch is used, that's why if i run the torch script first everything is ok. Share this post Link to post