首页 > 解决方案 > 我无法为最简单的“hello world”示例创建 .exe

问题描述

我已经成功地将 py2exe 用于以前的构建机器上的以前的项目,但是现在我已经从头开始安装了所有东西,并且无法运行最简单的示例:

设置.py

from distutils.core import setup
import py2exe
  
setup(console=['hello.py'])

你好.py

print("Hello World") 

命令:python3 setup.py py2exe 输出:

running py2exe

  1 missing Modules
  ------------------
? _posixshmem                         imported from multiprocessing.resource_tracker, multiprocessing.shared_memory
Building 'dist\hello.exe'.
error: [WinError 87] The parameter is incorrect.

生成了dest\hello.exe (37 kB!),但运行时出现以下错误:

Could not locate script resource:The specified resource type cannot be found in the image file.
FATAL ERROR: Could not locate script

我安装的版本是:

python --version
Python 3.8.6

pip freeze
cachetools==4.1.1
future==0.18.2
numpy==1.19.3
opencv-python==4.4.0.46
pefile==2019.4.18
py2exe==0.10.1.0
pyreadline==2.1
pywin32==300

systeminfo
OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.19041 N/A Build 19041
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Hotfix(s):                 6 Hotfix(s) Installed.
                           [01]: KB4580419
                           [02]: KB4561600
                           [03]: KB4577266
                           [04]: KB4580325
                           [05]: KB4586864
                           [06]: KB4586781
Hyper-V Requirements:      A hypervisor has been detected. Features required for Hyper-V will not be displayed.

我知道显然发生了一些奇怪的事情(我已经在这里遇到了“numpy”的问题:https ://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows -2004-is-causing-a.html ) ...但我不太明白它是什么。

谢谢 !

- 苹果电脑

标签: python-3.xpy2exe

解决方案


您只是输错了命令行标志,应该是:python setup.py py2exe.
在 Win7、Python 3.8.0 上对我来说效果很好:

(py38) λ python setup.py py2exe
running py2exe

  2 missing Modules
  ------------------
? _posixshmem                         imported from multiprocessing.resource_tracker, multiprocessing.shared_memory
? readline                            imported from cmd, code, pdb
Building 'dist\hello.exe'.
Building shared code archive 'dist\library.zip'.
Copy c:\users\f3k\envs\py38\scripts\python38.dll to dist
...
Copy DLL C:\Python38\DLLs\libffi-7.dll to dist\

C:\temp
(py38) λ dist\hello.exe
Hello World

推荐阅读