使用Cython创建Pyd文件,Pyx

时间:2017-11-18 06:33:44

标签: python python-2.7 cython pyinstaller

我正在尝试创建一个pyd文件和一个c文件。我被告知当前脚本运行速度不够快,所以我希望通过cython运行它并将其作为windows exe分发到整个办公室

我只是创建了python文件并通过名为dd1.pyx的pycharm将其重命名为pyx

然后我做了一个set up.py引用dd1 尝试:

    from setuptools import setup
    from setuptools import Extension
except ImportError:
    from distutils.core import setup
    from distutils.extension import Extension

from Cython.Distutils import build_ext
import numpy as np

ext_modules = [Extension("my_code_cython",["dd1.pyx"]),
               Extension("another_code_cython",["dd1.pyx"])]

setup(
    name= 'Generic model class',
    cmdclass = {'build_ext': build_ext},
    include_dirs = [np.get_include()],
    ext_modules = ext_modules)

我已经投入:

python dd1.pyx build_ext --inplace

这创建了一个pyd文件,我也相信一个C文件。

pyd文件已损坏或至少我认为它与我尝试通过pyinstaller分发时一样:

Pyinstaller -F --onefile dd1.pyd 



C:\Users\da>python dd1.pyd build_ext --inplace
running build_ext
cythoning vvblue2.py to vvblue2.c
building 'my_code_cython' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\da\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\da\Anaconda3\include -IC:\Users\da\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcvvblue2.c /Fobuild\temp.win-amd64-3.6\Release\vvblue2.obj
vvblue2.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\da\Anaconda3\libs /LIBPATH:C:\Users\da\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" /EXPORT:PyInit_my_code_cython build\temp.win-amd64-3.6\Release\vvblue2.obj /OUT:C:\Users\da\my_code_cython.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\my_code_cython.cp36-win_amd64.lib
vvblue2.obj : warning LNK4197: export 'PyInit_my_code_cython' specified multiple times; using first specification
   Creating library build\temp.win-amd64-3.6\Release\my_code_cython.cp36-win_amd64.lib and object build\temp.win-amd64-3.6\Release\my_code_cython.cp36-win_amd64.exp
Generating code
Finished generating code
skipping 'vvblue2.c' Cython extension (up-to-date)
building 'another_code_cython' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\da\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\da\Anaconda3\include -IC:\Users\da\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tcvvblue2.c /Fobuild\temp.win-amd64-3.6\Release\vvblue2.obj
vvblue2.c
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\da\Anaconda3\libs /LIBPATH:C:\Users\da\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" /EXPORT:PyInit_another_code_cython build\temp.win-amd64-3.6\Release\vvblue2.obj /OUT:C:\Users\da\another_code_cython.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\another_code_cython.cp36-win_amd64.lib
LINK : error LNK2001: unresolved external symbol PyInit_another_code_cython
build\temp.win-amd64-3.6\Release\another_code_cython.cp36-win_amd64.lib : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1120

关于我如何能够实现这一目标的任何想法都无法解决。如果这是基本的,我道歉,我花了2天的时间来试图实现这一目标

0 个答案:

没有答案