c:\Users\sony\Dropbox\notepad_app\2_Paint\build_windows>cat noteapp.spec
# -*- mode: python -*-
block_cipher = None
a = Analysis(['..\\__main__.py'],
pathex=['c:\\Users\\sony\\Dropbox\\notepad_app\\2_Paint\\build_windows'],
binaries=None,
datas=None,
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
exclude_binaries=True,
name='noteapp',
debug=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='noteapp')
最初の行は、これまでにロードされたすべてのモジュールを出力します。 ツイストリアクターがfrom kivy.support import install_twisted_reactor
前にロードされるかどうかを確認するに
c:\Users\sony\Dropbox\notepad_app\2_Paint\build_windows\dist\noteapp>cmd /K noteapp.exe
[<module 'pyimod03_importers' from 'c:\python27\lib\site-packages\PyInstaller-3.2.dev0+g2f86ac6-py2.7.egg\PyInstaller\loader\pyimod03_importers.py'>, <module 'tempfile' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\tempfile.pyc'>, <module 'sys' (built-in)>, <module 'atexit' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\atexit.pyc'>, <module 'ctypes' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\ctypes\__init__.pyc'>, <module 'encodings' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\encodings\__init__.pyc'>, <module 'win32com' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\win32com\__init__.pyc'>, <module 'shutil' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\shutil.pyc'>, <module 'os' from 'c:\Users\sony\Dropbox\NOTEPA~1\2_Paint\BUILD_~1\dist\noteapp\os.pyc'>]
[INFO ] [Logger ] Record log in c:/Users/sony\.kivy\logs\kivy_16-04-17_2.txt
[INFO ] [Kivy ] v1.9.2-dev0
[INFO ] [Python ] v2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)]
Traceback (most recent call last):
File "c:\Users\sony\Dropbox\notepad_app\2_Paint\__main__.py", line 7, in <module>
install_twisted_reactor() # twisted eventloop with kivy on the same reactor
File "c:\python27\lib\site-packages\kivy\support.py", line 176, in install_twisted_reactor
_threadedselect.install()
File "c:\Python27\lib\site-packages\twisted\internet\_threadedselect.py", line 354, in install
installReactor(reactor)
File "c:\Python27\lib\site-packages\twisted\internet\main.py", line 32, in installReactor
raise error.ReactorAlreadyInstalledError("reactor already installed")
twisted.internet.error.ReactorAlreadyInstalledError: reactor already installed
Failed to execute script __main__
#Written according to https://kivy.org/docs/guide/other-frameworks.html
#works fine when using python __main__.py
import sys
modulenames = set(sys.modules)&set(globals())
allmodules = [sys.modules[name] for name in modulenames]
print allmodules
#reactor import (compulsory first import)
from kivy.support import install_twisted_reactor
install_twisted_reactor() # twisted eventloop with kivy on the same reactor
#kivy import
from kivy.app import App
from kivy.config import Config
from kivy.uix.screenmanager import ScreenManager,Screen
from kivy.lang import Builder
#twisted and other-control imports
from twisted.internet import reactor
#screens and widgets imports
from screens.login_screen import LoginScreen
from canvas.canvas_widget import CanvasWidget,RadioButton
from screens.approve_clients import ApproveClients
#server and behaviour configuration file import
from config import config
try:
import _cffi_backend
except:
print "Please install PyInstaller for building. Not necessary for running."
#adding twisted imports
from twisted.internet.defer import DeferredQueue
from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import NetstringReceiver
from twisted.internet import defer
from twisted.protocols.basic import NetstringReceiver
from twisted.internet.defer import inlineCallbacks
from twisted.internet.threads import deferToThread
from twisted.internet.protocol import ClientFactory
import os
###############################################
#Screen specified below have majority behaviour specified in .kv
#Other screens are sin ./screens
class ActivitySelectScreen(Screen):
'''allows user to choose whether to
1. create server
2. connect to a pre-existing one '''
def __init__(self,**kwargs):
super(ActivitySelectScreen, self).__init__(**kwargs)
class PaintApp(Screen):
'''Screen class of the canvas widget'''
def __init__(self,**kwargs):
super(PaintApp, self).__init__(**kwargs)
class AppScreenManager(ScreenManager):
'''ScreenManager class'''
class notepad_app_v0(App):
'''Base application class'''
def build(self):
self.reactor=reactor
self.config_obj=config(allow_all=False,debug=False,activate_audio=True)
return Builder.load_file('.'+os.sep+'kivy'+os.sep+'paint.kv')
if __name__ == '__main__':
#setting resolution
Config.set('graphics', 'width', '960')
Config.set('graphics', 'height', '540') # 16:9
#disabling multi-touch and resizing the app
Config.set('graphics', 'resizable', '0')
Config.set('input', 'mouse', 'mouse,disable_multitouch')
notepad_app_v0().run()
この問題に関する更新または誰かによる解決策はありますか?
pyinstallerによって作成された実行可能ファイルでは、twisted.internet.reactorは、実際のkivyコードが実行される前に初期化されているようです(ただし)。 回避策として、次のことができます。
import kivy
kivy.require('1.9.1')
# fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
import sys
if 'twisted.internet.reactor' in sys.modules:
del sys.modules['twisted.internet.reactor']
# install twisted reactor
from kivy.support import install_twisted_reactor
install_twisted_reactor()
多分回避策はkivy.support.install_twisted_reactor
一部である必要がありますか?
この問題は、最近のアクティビティがないため、自動的に古いものとしてマークされています。 それ以上のアクティビティが発生しない場合は閉じられます。 貢献していただきありがとうございます。
リアクターの選択をオーバーライドする方法、またはツイストフックを完全に無視する方法を許可する方法が必要です。 現在、そのいずれかを行う方法はありますか?
PyInstaller qt5を使用し、カスタムqt5reactorでTwistedを使用した場合にも、同じ問題が発生します。
rnixxの回避策は問題を解決します。
ありがとうございました
# fix for pyinstaller packages app to avoid ReactorAlreadyInstalledError
import sys
if 'twisted.internet.reactor' in sys.modules:
del sys.modules['twisted.internet.reactor']
from PySide2.QtWidgets import QApplication
app = QApplication(sys.argv)
import qt5reactor
qt5reactor.install()
PS:kivy関連のスレッドにqt関連のソリューションを投稿して申し訳ありません。 しかし、このReactorAlreadyInstalledErrorは、異なるリアクターを使用する場合のツイストフックの一般的な問題のようです。
持ち帰ってくれてありがとう、でもそれはKivyのせいではありません。 https://github.com/pyinstaller/pyinstaller/issues/3390について確認して
最も参考になるコメント
pyinstallerによって作成された実行可能ファイルでは、twisted.internet.reactorは、実際のkivyコードが実行される前に初期化されているようです(ただし)。 回避策として、次のことができます。