参考
下载cython源码解压: https://codeload.github.com/cython/cython/zip/refs/heads/master
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 用mayapy编译会提示找不到python.h extra_include_dirs = [] if 'EXTRA_INCLUDE_DIRS' in os.environ: extra_include_dirs = os.environ['EXTRA_INCLUDE_DIRS' ].split(';' ) print("EXTRA_INCLUDE_DIRS: " , extra_include_dirs) extra_libraries = [] if 'EXTRA_LIBRARIES' in os.environ: extra_libraries = os.environ['EXTRA_LIBRARIES' ].split(';' ) print("EXTRA_LIBRARIES: " , extra_libraries) extensions.append(Extension( module, sources=[pyx_source_file], define_macros=defines if '.refnanny' not in module else [], depends=dep_files , library_dirs=extra_libraries, include_dirs=extra_include_dirs, ))
1 2 3 4 set VS90COMNTOOLS=%VS140COMNTOOLS%set EXTRA_INCLUDE_DIRS=C:/Program Files/Autodesk/Maya2022/include/Python27/Pythonset EXTRA_LIBRARIES=C:/Program Files/Autodesk/Maya2022/lib"C:\Program Files\Autodesk\Maya2022\bin\mayapy2.exe" setup.py build_ext --inplace
测试按照这里建立文件夹测试 https://gist.github.com/nrtkbb/5b65d2f5ed42bd9947b5
setup.py 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 from distutils.core import setupfrom distutils.extension import Extensionfrom Cython.Distutils import build_extimport osextra_include_dirs = [] if 'EXTRA_INCLUDE_DIRS' in os.environ: extra_include_dirs = os.environ['EXTRA_INCLUDE_DIRS' ].split(';' ) print("EXTRA_INCLUDE_DIRS: " , extra_include_dirs) extra_libraries = [] if 'EXTRA_LIBRARIES' in os.environ: extra_libraries = os.environ['EXTRA_LIBRARIES' ].split(';' ) print("EXTRA_LIBRARIES: " , extra_libraries) setup( cmdclass = {'build_ext' : build_ext}, ext_modules = [Extension("helloworld" , ["helloworld.pyx" ], library_dirs=extra_libraries, include_dirs=extra_include_dirs, )] )
helloworld.pyx 1 2 3 4 5 6 7 """ This is cython file. Compiled from setup.py and python ( same version to mayapy ) """ def hello (): print "Hello World"
cython_test.py 1 2 3 4 5 6 7 8 9 10 11 """ This is pure python file. Called from maya """ import helloworlddef hello (): helloworld.hello()