Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法使用多平台编译的外部模块创建setup.py文件_Python_Cython_Cx Freeze - Fatal编程技术网

Python 无法使用多平台编译的外部模块创建setup.py文件

Python 无法使用多平台编译的外部模块创建setup.py文件,python,cython,cx-freeze,Python,Cython,Cx Freeze,我正在尝试使用plataform不可知setup.py文件运行cx_freeze,我不知道如何将编译后的文件.pym、.so添加到可执行文件中 DataProcessor是Cython外部编译的python模块。。。但我不知道如何将其包含在cx_freeze可执行文件中,因为绝对路径取决于plataform和python版本。那我该怎么处理呢 可执行文件已编译,但外部模块未包括在内,因此,当我运行应用程序时,会抛出一个错误,即未加载DLL,或者在MacOS中显示ModuleNotFoundErr

我正在尝试使用plataform不可知setup.py文件运行cx_freeze,我不知道如何将编译后的文件.pym、.so添加到可执行文件中

DataProcessor是Cython外部编译的python模块。。。但我不知道如何将其包含在cx_freeze可执行文件中,因为绝对路径取决于plataform和python版本。那我该怎么处理呢

可执行文件已编译,但外部模块未包括在内,因此,当我运行应用程序时,会抛出一个错误,即未加载DLL,或者在MacOS中显示ModuleNotFoundError:没有名为“DataProcessor”的模块

编辑:我在原始setup.py上看到一个错误,更正此错误cx\U freeze显示此错误

cx_Freeze.freezer.ConfigError:找不到名为DataProcessor的文件/目录

EDIT2:根据@mgracer的建议,Acer试图加入includes部分,但没有成功

ImportError:没有名为“DataProcessor”的模块

因此,我可以做些什么来维护我的setup.py plataform不可知

这就是我现在所拥有的

from Cython.Build import cythonize
from cx_Freeze import setup, Executable
import sys
import os.path

# Windows hack
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# Windows hack

includes = []
excludes = ['tkinter']
packages = ['openpyxl', 'sqlite3', 're', 'collections', 'os']
include_files = ['DataProcessor']
dll_excludes = []

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
    "excludes": excludes,
    "includes": includes,
    "packages": packages,
    "include_files": include_files
}

setup(
    name="analizador",
    version="0.1",
    description="Foo bar",
    options={"build_exe": build_exe_options},
    ext_modules=cythonize("DataProcessor.pyx"),
    executables=[Executable("analisis.py", base=base)]
)

我通过扩展setup.py脚本解决了这个问题 结果是:

from Cython.Build import cythonize
from cx_Freeze import setup, Executable
import sys
import os
import platform

# hack para correr en windows
PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
os.environ['TCL_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(PYTHON_INSTALL_DIR, 'tcl', 'tk8.6')
# hack

setup(ext_modules=cythonize("DataProcessor.pyx"))

# rutina detect the files
arch = platform.machine()
temp = platform.python_version_tuple()
pyver = '%s.%s' % (temp[0], temp[1])
pname = None
pext = ".so"
tfiles = ()

if sys.platform == 'darwin':
    temp = platform.mac_ver()
    tver = '.'.join(temp[0].split('.')[:2])
    ptemp = 'macosx'
    pname = '%s-%s-%s' % (ptemp, tver, temp[2])

if sys.platform == 'win32':
    ptemp = 'win'
    pname = '%s-%s' % (ptemp, arch.lower())
    pext = '.pym'

libpath = os.path.join('build', ('lib.%s-%s' % (pname, pyver)))
afiles = os.listdir(libpath)
for file in afiles:
    afile = file.split('.')
    tfiles = tfiles + ((os.path.join(libpath, file), '.'.join([afile[0],
                        afile[2]])),)
# end

includes = []
excludes = ['tkinter', 'PyQt4']
packages = ['openpyxl', 'sqlite3', 're', 'collections', 'os']
dll_excludes = []

# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == "win32":
    base = "Win32GUI"

# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
    "excludes": excludes,
    "includes": includes,
    "packages": packages,
    "include_files": tfiles
}

setup(
    name="foo",
    version="0.1",
    description="Foobar",
    options={"build_exe": build_exe_options},
    executables=[Executable("analisis.py", base=base)]
)

你在哪里尝试过添加.so文件和.pym文件to@mgracer在include_文件中尝试include部分,而我几乎总是尝试尝试尝试尝试并出错。@mgracer没有成功