Jump to content

pyscripter

Members
  • Content Count

    1050
  • Joined

  • Last visited

  • Days Won

    70

Everything posted by pyscripter

  1. pyscripter

    I/O doesn't work

    Use the OnSendUniData event to process data sent by the python engine.
  2. pyscripter

    I/O doesn't work

    TPythonGUIInputOutput works with a linked memo. Use TPythonInputOutput instead.
  3. pyscripter

    Parsing a python collection into a delphi collection

    As you can see from your output AddressNumber is a string (as well as the other fields). You need to convert it to an integer.
  4. pyscripter

    Parsing a python collection into a delphi collection

    I am not exactly sure what you are trying to do, Also the 4th line in your script is doing nothing since you are assigning a new value in the next statement. However, if you want to access these values in Delphi and store them say in a Delphi data structure, the easiest way is using VarPyth. For instance to access the AddressNumber, after running the above script, you use something like: var AddressNumber := MainModule.od[0]['AddressNumber'];
  5. pyscripter

    Is there a Delphi "subprocess" library?

    You can always use the this python module from Delphi using P4D . One of the most advanced such Delphi functions in the Jcl unit JclSysUtils. Look at ExecuteCmdProcess and the various Execute overloads. It uses overlapped IO for super efficient redirection of the produced output, instead of using a special thread or a timer. These functions are also suitable for execution from a task/thread, if you do not want to block the main thread. The unit pyscripter/Source/uSysUtils.pas at master · pyscripter/pyscripter (github.com) extends the jcl functions to allow for an stdin pipe, customized environment variables and a buffered raw output.
  6. pyscripter

    Python freezes when running a certain script

    You don't need to create and destroy zPythonDelphiVar in every thread. Add zPythonDelphiVar to the form: object zPythonDelphiVar: TPythonDelphiVar Engine = PythonEngine1 Module = '__main__' VarName = 'result' Left = 64 Top = 120 end Then modify ExecuteWithPython to procedure TPythonThread_Test1.ExecuteWithPython; var i: Integer; begin fOutputs := TStringList.Create; for i := 1 to 10000 do begin GetPythonEngine.ExecString(UTF8Encode(Script)); GetPythonEngine.CheckError; fOutputs.Add(Form1.zPythonDelphiVar.Value); end; end; and it should work as you would expect. And since you mentioned it, a fellow Brazilian @lmbelo Lucas Belo, is a major contributor to P4D and would certainly be in a position to help.
  7. pyscripter

    Python freezes when running a certain script

    You never explained what is the problem.
  8. pyscripter

    Python freezes when running a certain script

    @djxandytche "Here is my code, please check and find the bugs" is not a good way to get support. Why should anyone spend one hour of their time, understanding and debugging your code? You say you are beginner in Python. Then why do you start by running python code in threads, which requires some expert knowledge? Do you realize that there is no performance benefits in running python code in threads like this? They will be executed sequentially, thanks to the GIL.
  9. For Delphi is here: Fundamental Syntactic Elements (Delphi) - RAD Studio (embarcadero.com) and for fpc Identifier - Free Pascal wiki.
  10. arr := np.&ones(VarPythonCreate([N, N]), np.float64) You do not need the &. It is only needed when using a keyword such as "array" (and Delphi does not need it even then).
  11. Also, since you are interested in image manipulations, have a look at this thread: Place image in a TImage - Python4Delphi - Delphi-PRAXiS [en] (delphipraxis.net)
  12. np.float64 corresponds to pascal double. Use double instead of single. Use BuiltinModule.float instead of BuiltinModule.int. For multidimensional arrays you need to use the ndim and shapes fields of the Buffer structure. An array of Py_ssize_t of length ndim indicating the shape of the memory as an n-dimensional array. Note that shape[0] * ... * shape[ndim-1] * itemsize MUST be equal to len. If you know the dimensions of the array you can directly cast to an equivalent pascal multidimensional array.
  13. pyscripter

    Python freezes when running a certain script

    Have you read the docs and the limitations of using subinterpreters? Initialization, Finalization, and Threads — Python 3.12.4 documentation Also the docs for the PyInterpreterConfig structure? pandas and numpy probably do not support running in subinterpreters. I suggest that you forget about sub-interpreters unless you know very well what you are doing. But then you are on your own.
  14. pyscripter

    Python freezes when running a certain script

    With SafePyEngine you do not get that choice. It is equivalent to emNewState, which is by far the most common use case.
  15. pyscripter

    Python freezes when running a certain script

    @djxandytche Your code for running python code in threads is reinventing the wheel and the result is evidently incorrect. Just follow the guidelines at PythonThreads · pyscripter/python4delphi Wiki (github.com) paying attention also to the preparation section. Also, have a close look also to Demos 33 and 36.
  16. pyscripter

    DelphiVCL TreeView OnCustomDrawItem

    A fix has been applied to P4D. Please check.
  17. pyscripter

    PyScripter - Integration with LLM

    The forthcoming version of PyScripter will have built-in integration with LLM. See the blog post for a taste of the functionality provided.
  18. pyscripter

    PyScripter - Integration with LLM

    I am aware of that. This is due Sourceforge changing the way you download files directly. Will work with the next update for this one just download from PyScripter - Manage /PyScripter-v5.0 at SourceForge.net and install.
  19. pyscripter

    PyScripter - Integration with LLM

    @Stéphane Wierzbicki PyScripter with LLM support was released. See LLM_Support · pyscripter/pyscripter Wiki (github.com) for details.
  20. pyscripter

    Owner receives only Delphi objects

    I don't this is going to work. You are going to have duplicates of what is supposed to be Singletons (WrapDelphi, PythonEngine). It may work with run-time packages, but you would have to put all run-time packages in the same folder as the pyd files.
  21. pyscripter

    PyInstaller

    Have you followed the instructions at DelphiVCL4Python/samples/Installer at main · Embarcadero/DelphiVCL4Python (github.com) for delphivcl DelphiFMX4Python/samples/Installer at main · Embarcadero/DelphiFMX4Python (github.com) for delphifmx
  22. pyscripter

    DelphiVCL4Python

    I have used Python for many many years and really like the language. However it is slow. Really slow. And it does not use those damn CPU cores in my computer. If you look at Python (created in 1989) and Ruby (created in 1993), they have a lot in common and the same limitations. Ruby is also quite nice and there was a lot of buzz around it about 10-15 years ago, but the slowness almost killed the interest in the language. On the other hand, and in a hard to explain way, Python flourished. In an irreversible way. It is now the main programming language in schools and universities, including computer science degrees. It is here to stay for many years to come. Of course you can make python faster (Cython, using optimized python extension modules, multiprocessing etc.), but it takes an effort. The focus of python development has been two areas: type safety (kind of odd for a dynamic language) execution speed The two at some point may converge. There are a few developments regarding speed that offer some hope; Per interpreter Gil introduced in Python 12 (see https://en.delphipraxis.net/topic/10372-true-thread-parallelism-with-p4d-and-python-12). This is only accessible in embedded Python, using the python API. There were proposals to make it accessible through the interpreter, but were rejected in favour of the following developments. Experimental Just-in-Time (JIT) Compilation introduced in the coming Python 3.13 (so far, the speed improvements are negligible) Free threaded python (GIL-free) also introduced in python 3.13. Sounds good but it is incompatible with the GIL-enabled version of python. Extension modules are also incompatible and the two versions will be available in parallel, which sounds messy.
  23. pyscripter

    Records as TDictionary keys

    Just keep in mind [RSP-43423] Using {$WEAKLINKRTTI ON} causes access violation on TList<T>.IndexOf method - Embarcadero Technologies, See also
  24. pyscripter

    VTK in DelphiVCL or DelphiFMX

    WrapDelphi now automatically exposes all events. However, there has been no release of delphivcl recently incorporating these changes. If you create a custom delphivcl using the latest sources you do not need your custom panel. Panel should expose the above events.
  25. pyscripter

    DelphiVCL4Python

    You don't need Parent = self. Otherwise that's the idea.
×