Skip to main content
 首页 » 编程设计

python之从python创建可执行文件时出错

2024年12月31日11lyj

我在 pycharm 中将一个 python 脚本编码为“probe.py”,然后使用 setup.py 文件中提到的代码从中构建可执行文件 (.exe),但是这样创建的 exe 文件在打开时显示错误 import error mising required dependency['numpy'] 即使它存在于我的项目中。

错误图片

  import sys 
 
  from cx_Freeze import setup,Executable 
 
 
  include_files = ['autorun.inf'] 
  base = None 
 
  if sys.platform == "win32": 
  base = "Win32GUI" 
 
  setup(name="Probe",version="0.1",description="fun", 
  options={'build_exe':{'include_files': include_files}}, 
  executables=[Executable("probe.py",base=base)]) 

`

请您参考如下方法:

from cx_Freeze import setup, Executable 
   base = None 
   if sys.platform == "win32": 
     base = "Win32GUI" 
   build_exe_options = {"packages": ["numpy"], 
     include_files = ['autorun.inf']} 
 
   setup( 
        name = "Probe", 
        version = "0.1", 
        description = "fun", 
        options = {"build_exe": build_exe_options}, 
        executables = [Executable("probe.py",base=base)] 
        ) 

运行这个脚本告诉我是否有问题