py2exe를 사용하여 확장 기능을 갖춘 Python 프로그램을 구축하십시오

StackOverflow https://stackoverflow.com/questions/1848275

  •  13-09-2019
  •  | 
  •  

문제

특히 C 확장이 필요한 경우 PY2Exe 레시피를 찾는 데 어려움을 겪고 있습니다.

다음 레시피는 "ext_modules"부분없이 잘 작동합니다. 그것으로 나는 "nameerror : name 'extension'이 정의되지 않습니다.

from distutils.core import setup
import py2exe
import matplotlib
import os

s = os.popen('svnversion')
version = s.read()
f = open('cpa_version.py', 'w')
f.write('VERSION = "%s"\n'%(version.strip()))
f.close()

setup(console=['cpa.py'],
      options={
        'py2exe': {
            'packages' : ['matplotlib', 'pytz', 'MySQLdb', 'pysqlite2'],
            'includes' : ['PILfix', 'version'],
            "excludes" : ['_gtkagg', '_tkagg',
                          "Tkconstants","Tkinter","tcl"],
            "dll_excludes": ['libgdk-win32-2.0-0.dll',
                             'libgobject-2.0-0.dll', 
                             'libgdk_pixbuf-2.0-0.dll',
                             'tcl84.dll', 'tk84.dll']
            }
        },
      data_files=matplotlib.get_py2exe_datafiles(),
      # how to build _classifier.c???
      ext_modules = [Extension('_classifier',
                               sources = ['_classifier.c'],
                               include_dirs=[numpy.get_include()],
                               libraries = ['sqlite3'])]
)

_classifier.c에는 다음이 포함되어 있습니다


#include "sqlite3.h"
#include "Python.h"
#include "numpy/arrayobject.h"
#include <stdio.h>

모든 도움은 대단히 감사하겠습니다.

도움이 되었습니까?

해결책

Extension 가져 오기를 잊어 버려 생성 된 작은 오류를 수정 한 후 -LSQLITE3 플래그에 문제가있는 다른 오류가 발생했습니다. 여기에 요약 된 단계를 따라야한다는 것이 밝혀졌습니다. http://cboard.cprogramming.com/cplusplus-programming/82135-sqlite-questions.html

  1. sqlitedll-3_3_7.zip 및 sqlite-source-3_3_7.zip에서 sqlite.org/download.html에서 다운로드하십시오
  2. sqlitedll-3.3.7.zip을 추출한 다음 명령 줄에서 실행합니다.

    dlltool -d sqlite3.dll -d sqlite3.def -l libsqlite3dll.a

  3. mingw lib 디렉토리에 libsqlite3dll.a (방금 생성)를 배치하십시오.
  4. 시스템 경로에 sqlite3.dll을 배치하십시오 (c : windows system32 나를 위해 일했습니다)
  5. sqlite-source-3_3_7.zip을 추출하고 mingw에 sqlite3.h를 배치합니다.
  6. 연결하면 매개 변수를 제공해야합니다. -lsqlite3dll (라이브러리 변경을 의미합니다 = [ 'sqlite3'] 라이브러리 = [ 'sqlite3dll'])).

... 그 후 빌드는 작동했습니다.

다시 설정 파일은 다음과 같습니다.

from distutils.core import setup, Extension
import py2exe
import matplotlib
import os
import numpy

setup(console=['cpa.py'],
      options={
        'py2exe': {
            'packages' : ['matplotlib', 'pytz', 'MySQLdb', 'pysqlite2'],
            'includes' : ['PILfix', 'version'],
            "excludes" : ['_gtkagg', '_tkagg',
                          "Tkconstants","Tkinter","tcl"],
            "dll_excludes": ['libgdk-win32-2.0-0.dll',
                             'libgobject-2.0-0.dll', 
                             'libgdk_pixbuf-2.0-0.dll',
                             'tcl84.dll', 'tk84.dll']
            }
        },
      data_files=matplotlib.get_py2exe_datafiles(),
      ext_modules = [Extension('_classifier',
                               sources = ['_classifier.c'],
                               include_dirs=[numpy.get_include()],
                               libraries = ['sqlite3dll'])]
)

다른 팁

변경해보십시오

from distutils.core import setup

에게

from distutils.core import setup, Extension
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top