Py2Exe-解决NumPy和SciPy依赖关系

时间:2018-07-09 22:01:02

标签: python python-3.x numpy scipy py2exe

目标(最终目标): 我想创建一个独立的可执行Python脚本(仅 一个文件),其中包括适用于我的应用程序的NumPy和SciPy依赖项。

背景: 据我了解,要在Python中创建可执行脚本-可以使用以下三个选项:

  1. PyInstaller
  2. Py2exe
  3. CxFreeze

我继续尝试Py2exe进行开发。看来CxFreeze不支持单文件选项(来自文档here)。我还考虑了使用PyInstaller的选项,但是遇到了有关缺少DLL的问题(类似于找到的here)。即使在我的笔记本电脑中安装了Microsoft Visual C ++ 2010可再发行组件包,问题仍然持续存在。

我按照教程使用Py2exe here,并且能够使虚拟脚本可执行文件(Hello World!)工作。但是,我尝试重新修改特定于我的应用程序的setup.py脚本,以包括numpy和scipy依赖关系(见下文):

from distutils.core import setup
import py2exe,sys,numpy,scipy

sys.argv.append('py2exe')

setup(
console=['Application.py'],
options={
  'py2exe': {
     'includes':['numpy','scipy','scipy.integrate','scipy.special.*','scipy.linalg.*'],
     'bundle_files':1,
     'compressed':True
  }
},
zipfile=None)

这是我尝试运行脚本时收到的结果错误:

Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2018.1.4\helpers\pydev\pydev_run_in_console.py", line 52, in run_file
pydev_imports.execfile(file, globals, locals)  # execute the script
File "C:\Program Files\JetBrains\PyCharm 2018.1.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/prest/PycharmProjects/Application/setup.py", line 15, in <module>
zipfile=None
File "C:\Python34\lib\distutils\core.py", line 149, in setup
dist.run_commands()
File "C:\Python34\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Python34\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\distutils_buildexe.py", line 188, in run
self._run()
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\distutils_buildexe.py", line 267, in _run
builder.analyze()
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\runtime.py", line 164, in analyze
mf.import_hook(modname)
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\prest\PycharmProjects\Application\venv\lib\site-packages\py2exe\mf3.py", line 337, in _find_and_load
raise ImportError(name)
ImportError: scipy.linalg.*

这些是我正在使用的与我的应用程序相关的版本:

  1. Python 3.4
  2. NumPy 1.14.5
  3. SciPy 1.1.0

问题: 谁能提供我为什么会收到此错误的任何见解以及解决此问题的任何后续步骤?感谢您的投入!

谢谢

普雷斯顿

1 个答案:

答案 0 :(得分:0)

关闭-继续并将PyInstaller用于单文件可执行文件。我重新修改了脚本以解决特定的依赖性(仅用于NumPy)。