Python cx\U冻结无法包括Cython.pyx模块

Python cx\U冻结无法包括Cython.pyx模块,python,python-3.x,cython,cx-freeze,Python,Python 3.x,Cython,Cx Freeze,我最近在一个Python应用程序中添加了一个Cython模块。使用pyximport从脚本运行它很好,但我还需要一个可执行版本,我使用cx\u Freeze构建该版本 问题是,尝试构建它会给我一个可执行文件,在尝试导入.pyx模块时会引发ImportError 我像这样修改了我的setup.py,看看是否可以让它先编译.pyx,以便cx\U Freeze可以成功地打包它: from cx_Freeze import setup, Executable from Cython.Build impo

我最近在一个Python应用程序中添加了一个Cython模块。使用pyximport从脚本运行它很好,但我还需要一个可执行版本,我使用cx\u Freeze构建该版本

问题是,尝试构建它会给我一个可执行文件,在尝试导入.pyx模块时会引发ImportError

我像这样修改了我的
setup.py
,看看是否可以让它先编译.pyx,以便cx\U Freeze可以成功地打包它:

from cx_Freeze import setup, Executable
from Cython.Build import cythonize


setup(name='projectname',
      version='0.0',
      description=' ',
      options={"build_exe": {"packages":["pygame","fx"]},'build_ext': {'compiler': 'mingw32'}},
      ext_modules=cythonize("fx.pyx"),
      executables=[Executable('main.py',targetName="myproject.exe",base = "Win32GUI")],
      requires=['pygcurse','pyperclip','rsa','dill','numpy']
      )
。。。但是,我得到的只是在构建时cx\U冻结中没有名为fx的模块


如何实现这一点?

解决方案是对
setup()
进行两次单独的调用;一个是用Cython构建
fx.pyx
,另一个是用cx\U Freeze打包exe。下面是修改后的
setup.py

from cx_Freeze import Executable
from cx_Freeze import setup as cx_setup
from distutils.core import setup
from Cython.Build import cythonize

setup(options={'build_ext': {'compiler': 'mingw32'}},
      ext_modules=cythonize("fx.pyx"))

cx_setup(name='myproject',
      version='0.0',
      description='',
      options={"build_exe": {"packages":["pygame","fx"]}},
      executables=[Executable('main.py',targetName="myproject.exe",base = "Win32GUI")],
      requires=['pygcurse','pyperclip','rsa','dill','numpy']
      )

仅供参考,为了使其工作,您必须键入“python setup-cython.py build\u ext--inplace”,然后键入“python setup-cython.py build”