저는 pySerial을 사용하여 실제 크기의 데이터를 읽는 빠른 프로젝트를 진행하고 있습니다. 파이 게임을 간단한 GUI의 프론트 엔드로 사용하고 있습니다. py2exe를 사용하여 프로젝트를 배포하려고합니다.py2exe는 오류없이 pySerial을 컴파일하지만 com 포트는 열리지 않습니다.
프로젝트는 파이썬을 통해 실행될 때 직렬을 열어 예상대로 읽으면 작동합니다. 내 py2exe에 설치 스크립트에 의해 컴파일
실행 파일 (더 가져 오기 오류)
실행 파일이 제대로 시리얼 열리지 않습니다 정상적으로 실행되지 않습니다. 직렬 포트를 찾을 수 없을 때 발생하는 예외를 묻지 않는 한, 그 시점에서 프로그램이 닫힙니다.
try/catch에서 모든 직렬 코드가 덤프되거나 중첩되어 실행 파일이 올바르게 작동합니다. 파이 게임이나 나머지 코드에는 문제가 없을 것입니다.
여기에 유일한 파일입니다 main.py에서 관련 코드입니다 :
import os, sys
import pygame
from pygame.locals import *
if not pygame.font: print 'Warning, fonts disabled'
#serial
import serial
import io
import time
...
def initSerial():
try:
#The port is hard coded for now
port = 11
ser = serial.Serial(port-1)
ser.baudrate = 2400
ser.timeout = 0.01
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))
print "serial port opened"
return ser, sio
except Exception, message:
print "couldn't open serial"
raise SystemExit, message #The executable dumps here if this line is included
return None, None
그리고 여기 내 setup.py이다가, 내가 주로 복사 한 것 tutorial :
#see http://screeniqsys.com/blog/2009/03/20/making-py2exe-play-nice-with-pygame/
from distutils.core import setup
import py2exe
import sys
import os
import glob, shutil
import pygame
sys.argv.append("py2exe")
VERSION = '1.0'
PRODUCT_NAME = 'Weight Mentor'
SCRIPT_MAIN = 'main.py'
VERSIONSTRING = PRODUCT_NAME + " ALPHA " + VERSION
REMOVE_BUILD_ON_EXIT = True
PYGAMEDIR = os.path.split(pygame.base.__file__)[0]
SDL_DLLS = glob.glob(os.path.join(PYGAMEDIR, '*.dll'))
if os.path.exists('dist/'): shutil.rmtree('dist/')
extra_files = [ ("graphics", glob.glob(os.path.join('graphics','*.png'))),
("fonts", glob.glob(os.path.join('fonts','*.ttf'))) ]
INCLUDE_STUFF = ['encodings',"encodings.latin_1",]
setup(windows=[
{'script': SCRIPT_MAIN}],
options = {"py2exe": {
"optimize": 2,
"includes": INCLUDE_STUFF,
"compressed": 1,
"ascii": 1,
"bundle_files": 3, #unfortunately on x64 we can't use the better bundle files options. So we bundle nothing :(
"ignores": ['tcl', 'AppKit', 'Numeric', 'Foundation']
} },
name = PRODUCT_NAME,
version = VERSION,
data_files = extra_files,
zipfile = None)
if REMOVE_BUILD_ON_EXIT:
shutil.rmtree('build/')
for f in SDL_DLLS:
fname = os.path.basename(f)
try:
shutil.copyfile(f, os.path.join('dist',fname))
except:
pass
일반적으로이 설정 스크립트에는 일부 제외 항목이 포함 된 배포본의 크기를 줄이는 코드가 있지만 제외 된 패키지를 제거하는 오류가 발생하지 않도록 제외했습니다.
그래서 필자는에 추가 할 필요가있는 항목 (DLL? INCLUDE_STUFF의 다른 줄?)이 pySerial과 올바르게 작동하도록해야한다고 생각합니다. 나는 그저 무언가가 뭔지 전혀 모릅니다. py2exe 문서는 pySerial에 대한 특별한 요구 사항을 언급하지 않았으며, 내 인터넷 검색은 아무 것도 나타나지 않았습니다.
도움이 될 것입니다.