How do you include subprocess with py2exe?

2019-09-10 03:02发布

问题:

When I package my program into an exe using py2exe and try to run it, it comes back with the following:

Traceback (most recent call last):
  File "raman_utility_v1.0.2.pyw", line 386, in <module>
  File "raman_utility_v1.0.2.pyw", line 132, in __init__
  File "raman_utility_v1.0.2.pyw", line 136, in getHome
  File "subprocess.pyc", line 566, in check_output
  File "subprocess.pyc", line 710, in __init__
  File "subprocess.pyc", line 958, in _execute_child
WindowsError: [Error 2] The system cannot find the file specified

Currently my setup.py looks like this:

from distutils.core import setup
import py2exe

setup(
    options={
        "py2exe" : {"includes" : ["sip","subprocess"]}
    },
    windows=[{
        "script" : "raman_utility_v1.0.2.pyw"
    }]
)

And to run the setup.py, I run the following cmd:

python setup.py py2exe --includes sip

I have tried adding subprocess to the cmd like this:

python setup.py py2exe --includes sip,subprocess

but all that did was break sip.

I tried just copying the subprocess.pyc file into the dist folder, and that did not work. The last thing I tried was a suggestion from: py2exe not including the modules from "includes" which was to use "packages" instead of "includes" (for subprocess). That did not change anything. I also tried adding the line:

import subprocess

at the beginning of setup.py but that did not change anything either

Am I even on the right track? Any hints you have would be really helpful!