简体   繁体   中英

pyinstaller: popen doesn't run after producing exe

I compiled my python application using pyinstaller and the exe works fine, but when I run it on a different machine without python any part of the code which contains subprocess.Popen() doesn't run.

I read too many questions but I couldn't wrap my head around this.

My popen line:

try:
            process = subprocess.Popen(['python', os.path.abspath('about.py')],stdout=subprocess.PIPE,stderr=subprocess.PIPE,stdin=subprocess.PIPE,
                shell=True)

except Exception as e:
            print(e)

Note that the executable runs on the host machine, but on another machines it runs but fails when launching the popen.

===UPDATE====

The console shows nothing and doesn't print an exception, so I guess this is a problem with python not being found. How can I fix this?

===UPDATE2====

Following the suggestion of viilpe I used "exec(open..." but it required me to import the about.py module first; importing the module runs it on top of the main module.

Putting exec(open...) inside the try\except runs the main module and the about module alongside each other; ruining the application's GUI.

I'm using "kivy" as my GUI library.

Looks like you want to execute about.py but there is no python.exe in pyinstaller bundle. As advised here you can do it this way:

exec(open('about.py').read())

The whole point of PyInstaller is to make the destination computer be able to run your script without having a standalone python installation. You can't run a subprocess on a tool which isn't (necessarily) installed.

There are various ways to run Python as a subprocess of itself natively; start by exploring the multiprocessing library.

If the requirement to run Python twice is not a hard one, the absolutely simplest solution is to import about and run the code as part of your script. This probably requires some refactoring of the code in about.py .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM