cx_freeze ImportError when executing file

我的梦境 提交于 2019-12-06 05:17:00

Ah, the joys of packaging standalone Python apps for Windows! Anybody that tells you this is easy hasn't tried it. But don't give up, the result is usually worth it if you can get past the initial situps.

The paths emitted in your frozen executable's error message are most likely a red herring that you can safely ignore. It looks like your app is (indirectly) pulling in a DLL that isn't automatically included by cx_Freeze, and isn't available on the target machine. Figuring out exactly which DLL is missing is the tricky part.

I personally tried running the setup.py you posted on a Windows 7 machine to generate an EXE and support files for your Python script. I then copied the bundle to a Windows XP box. Unfortunately, it ran just fine for me, so I can only give you generic troubleshooting advice. Here's what I'd try:

  1. Download Dependency Walker to the target machine and open your cx_Freeze-generated actWin_Query.exe binary.
  2. Try to determine which DLL is failing to load
  3. Back on your build machine, use the cx_Freeze include-files option to bring in the missing DLL(s)
  4. Rebuild the app
  5. Try running again on the target

Sorry I can't give more specific advice than this. There are so many possible combinations of Windows/Python, plus 32-/64-bit and C runtime variants that it's hard to pinpoint an exact cause. But I've had similar problems at least a dozen times, and it always seems to boil down to missing files.

The case I run into most often is: I'll build the app on a machine that happens to have, say, Visual C++ 2010 [Express] installed, and then find that it fails to run on a machine that does not have VC++2010 installed. Installing the VC++2010 Redistributable on the target often solves the problem, or bundling its installing into a 'super-installer' that also installs the cx_Freeze-generated files. (I suspect the problem you're seeing is slightly different than this, just mentioning it in case it's helpful.) Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!