Jump to content
Sign in to follow this  
limelect

PyInstaller

Recommended Posts

After very long and many tries I need your help

This is my script works on other Python script

 

pyinstaller.exe  --windowed D4P_export_demo.py  --onefile --paths="C:\Users\LimElect\anaconda3\Lib\site-packages\delphifmx\" --name  D4P_export_demo

 

the path is not needed as I get the same Python error

 

pyinstaller.exe  --windowed D4P_export_demo.py  --onefile  --name  D4P_export_demo

 

It seems to find the packet but cannot use it

The package is used without any problems in PyScripter

warn-D4P_export_demo.txt does not show that the package is missing

 

Any Idea?

 

P.S. Final message    5303 INFO: Building EXE from EXE-00.toc completed successfully. 

Screenshot - 26_06_2024 , 11_35_28.jpg

Share this post


Link to post

I did but still, in some places, there is a misunderstanding of mine 

It compiles OK but exe does not do the job

where am I wrong?

 

pythone.zip

Share this post


Link to post
Posted (edited)

@pyscripter Can you plz put here an FMX or VCL Pas/PY hello World zip project

that you make to an EXE.

I will change the library path compile and see what happens.

Thanks

P.S It will be the best demo possible

Edited by limelect

Share this post


Link to post

Guys to begin thanks for your attention

 

1. Either no one except me plays with Delphi for Python

2. Maybe I found that the Python package cannot make an execute.

3. This that there is no response says something 

4 So I moved to QT designer with PyQt5 where the Python package does work and give me an execute.

5. I prefer Delphi but for the time being until proven otherwise it is out for me

 

P.S I could not install PyQt6 but that is another matter

 

Share this post


Link to post
Posted (edited)

Let's explain ... I'm not an expert about Python, but i work on some P4D projects and I see some issues (they are not really issues, but you cannot do some things if those happens).

 

Look for script TEST.PY and Delphi lib pyTRYSF.pyd in the attached example.

 

First of all: instead to do "onefile", do the standard distribution that pyinstaller do  ... try only (from the pyinstaller environment):

pyinstaller test.py

This will create the folders that containing the executable and all the necessary files (including your .pyd library compiled with Delphi):

    dist\test\_internal

Inside "dist\test" ther will be an executable (test.exe) and in the subfolder "_internal" should be all necessary for running the exe, INCLUDED pyTRYSF.pyd) !!!!

 

For running any delphi library with Python is necessary to link the Pythonxxx.dll main engine at runtime. This mean that this engine should be found.

 

When you run a python script that import a Delphi dll normally (eg. after you installed Python in Windows) your module can link the standard pythonxxx.dll library installed and is the same that the python "shell" call.

 

If you are running the test.exe program created by pyinstaller, the pythonxxx.dll library is not the standard library, but is the DLL that is inside the "_internal" subfolder, where the pyd module is too.

 

This "_internal\pythonxxx.dll" should be link at runtime by Delphi dll (pyTRYSF.pyd in the example). If you don't link this at runtime, you will never be able to execute your "pyd".

 

In the example attached there is an example how I modified the link engine procedure to search the correct lib ... it works without changes with installed python engine or with pyinstaller (but no with --onefile parameters).

 

Why the --onefiles parameters doesn't works ?

2 are the issues:

 

1) The pyd is not included by pyinstaller in the executable (with --onefile).

2) The executable unzip the same files like "_internal" in a temporary directory. This lead the impossibility to link the pythonxxx.dll because when the test.exe is executed the execution path is the ".\" of the test.exe an not the temporary directory. There are no chance for Delphi pyd module to link the correct pythonxxx.dll.

 

May be the P4D guru can help in this.

 

Bye

 

N.B.: the example works only with Python 3.12 by now.

 

 

DelphiDLLforPython.zip

Edited by DelphiUdIT

Share this post


Link to post
Posted (edited)

Unit1.pas :

..

        #- self.Label2.caption=""
        self.Label2.Caption="" #+ should:  Caption  and change all.. Here I have changed everything.

..

delphivclexecutable.spec:

..

#+I'm using: Windows 11, Python 3.10, and pyinstaller==6.8.0

 

a = Analysis(
    #- ['delphivclexecutable.py'],
    ['Project2.py'], #+
    pathex=[],
    binaries=[],
    #- datas=[(r"C:\Users\LimElect\anaconda3\Lib\site-packages\delphivcl", "delphivcl")] ,
    datas=[(r"C:\Users\LimElect\anaconda3\Lib\site-packages\delphivcl", "delphivcl"), ("Unit1.py", "."), ("Unit1.pydfm", ".")] , #+

..

the above correction work for me.

demo:  attach 7z have 2 splits, i can't upload split2. forum limit file only 4m+ sorry :

pythone_Fixed.7z.001

Edited by devd

Share this post


Link to post
16 hours ago, DelphiUdIT said:

Look for script TEST.PY and Delphi lib pyTRYSF.pyd in the attached example.

Where is it?

2. cannot open pythone_Fixed.7z.002 is it zip or 7z? non open

Share this post


Link to post
Posted (edited)

@DelphiUdIT Sorry Your zip gives an error

My zip program is the latest

Also, it is not a zip as I look inside it does not have the zip initials

It should have PK

PLZ make sure it is ZIP

Edited by limelect

Share this post


Link to post

It is strange I can open it. Combine the two split files into a .7z and you open it using Windows Explorer.

Share this post


Link to post
Posted (edited)

Is it for LINOXS as we are working on Windows

there is no 7ZipFM for Windows unless you know the link.

It suppose to be part of 7zip but cannot find it

 

Edited by limelect

Share this post


Link to post

OK I found on the portable project 7ZipFM but is cannot open eiyher

Share this post


Link to post

It is not a rocket science to combine two files:

copy  /b pythone_Fixed.7z.001+pythone_Fixed.7z.002 pythone_Fixed.7z

 

Devd gave the reason why it is not a single zip "attach 7z have 2 splits, i can't upload split2. forum limit file only 4m+ sorry"

Share this post


Link to post

Well I do not understand as I have  3 zip/7zip non open including 7zipfm

I am stack

If it helps (without an exe) my mail  

limelect@gmail,com

or www,limelect.com where you find lots of free staff

Share this post


Link to post
Posted (edited)

@davd Finally it open

can you also send pas sources to see if my D10,2,3 make what needed

I will compile   yours and see

WWWWAAAA great you put also my librery

 

Edited by limelect

Share this post


Link to post
Posted (edited)

It works !!!!! Lovely next to see where I made mistakes

OK it is my PAS file 

THANKS a lot, much appreciate

Edited by limelect

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×