前提
AttributeError: 'NoneType' object has no attribute 'apps'で処理が止まる。
実現したいこと
Windows 11 & Python 3.10.8の環境で最新 xlwings ライブラリを使っています。
ソース.pyの実体からや、cx_Freezeを使用したexeファイルを作成して、目的の動作が行われている事を確認しています。
比較のためpy2exeを使って同様にexeファイルを作成したところ、distフォルダの中には実行ファイル群が作成されていたのですが、作成したソース.exeを実行すると、Excel処理の箇所でエラーログが吐き出されて動作が止まってしまいます。
発生している問題・エラーメッセージ
Traceback (most recent call last):
File "hoge.py", line 666, in <module>
File "hoge.py", line 404, in hogeExcel
File "xlwings\main.pyc", line 294, in init
AttributeError: 'NoneType' object has no attribute 'apps'
hoge.pyソース内の 666行目 & 404行目の内容は
rf = hogeExcel(True) → 666行目(モジュール呼び出し)
def hogeExcel(bool):
app = xw.App(visible = False, add_book = False) → 404行目
xlwingsのライブラリ処理の中でエラーが吐き出されているようですが、py2exeってxlwingsとの相性が悪いのでしょうか?
それとも私のソース内での書き方が悪いのか、ビルドするスクリプトの記述に問題があるのか、よく分からない部分が多いので質問させて頂きました。
ビルドするpy2exeのスクリプト内容です
from distutils.core import setup
from setuptools import find_packages
import py2exe
option = {
'compressed': 1,
'optimize': 2,
'bundle_files': 1,
}
setup(
options = {
'py2exe': option,
},
windows = [
{'script': 'hoge.py',
'icon_resources': [(1, 'hoge.ico')]
},
],
py_modules = [],
zipfile = 'lib\libs.zip',
)
ビルド処理しているリストでは、以下の通りxlwingsでのメッセージが多いようですが、これで正常なのでしょうか?
※環境を変えて 3.11 でビルドしましたが、3.10.8でも同じ結果です。
先にも書きましたが、実行ファイル群は作成されています。
PS C:\Users\ore> python setup.py py2exe
setup(
| 44 missing Modules |
|---|
| ? Foundation imported from send2trash.plat_osx_pyobjc |
| ? PIL imported from PySimpleGUI.PySimpleGUI, xlwings._xlmac, xlwings._xlwindows, xlwings.main, xlwings.pro.reports.main |
| ? PIL.Image imported from xlwings.pro.reports.main |
| ? main imported from bdb, pdb |
| ? _frozen_importlib imported from importlib, importlib.abc, zipimport |
| ? _frozen_importlib_external imported from importlib, importlib._bootstrap, importlib.abc, zipimport |
| ? _posixshmem imported from multiprocessing.resource_tracker, multiprocessing.shared_memory |
| ? _winreg imported from platform |
| ? aem imported from xlwings._xlmac |
| ? appscript imported from xlwings._xlmac |
| ? appscript.reference imported from xlwings._xlmac |
| ? asyncio.DefaultEventLoopPolicy imported from - |
| ? asyncio.get_event_loop imported from xlwings.udfs |
| ? asyncio.get_running_loop imported from xlwings.udfs |
| ? conversion.Converter imported from xlwings.pro.reports.markdown |
| ? cryptography.fernet imported from xlwings.pro.utils |
| ? dummy.Process imported from multiprocessing.pool |
| ? gi.repository imported from send2trash.plat_gio |
| ? java.lang imported from platform |
| ? jinja2 imported from xlwings.pro.reports.main |
| ? matplotlib imported from xlwings.main, xlwings.utils |
| ? matplotlib.backends.backend_agg imported from xlwings.main |
| ? matplotlib.figure imported from xlwings.pro.reports.main, xlwings.utils |
| ? matplotlib.pyplot imported from xlwings.utils |
| ? numpy imported from xlwings._xlmac, xlwings._xlwindows, xlwings.conversion, xlwings.conversion.numpy_conv, xlwings.conversion.standard, xlwings.pro._xlcalamine, xlwings.pro._xlremote, xlwings.pro.reports.filters, xlwings.pro.reports.main, xlwings.utils |
| ? org.python.core imported from copy, pickle |
| ? os.path imported from ctypes._aix, distutils.file_util, os, pkgutil, py_compile, send2trash.plat_other, send2trash.plat_win_legacy, send2trash.plat_win_modern, sysconfig, tracemalloc, unittest, unittest.util, xlwings.udfs |
| ? osax imported from xlwings._xlmac |
| ? pandas imported from xlwings._xlmac, xlwings._xlwindows, xlwings.conversion, xlwings.conversion.numpy_conv, xlwings.conversion.pandas_conv, xlwings.main, xlwings.pro._xlcalamine, xlwings.pro._xlremote, xlwings.pro.reports.main |
| ? pdfrw imported from xlwings.pro.reports.pdf |
| ? plotly imported from xlwings.pro.reports.main |
| ? plotly.graph_objects imported from xlwings.utils |
| ? plugins.PLUGINS imported from xlwings.mistune |
| ? pro.Markdown imported from xlwings.conversion.standard |
| ? pro.reports.render_template imported from xlwings.main |
| ? pro.verify_execute_permission imported from xlwings.udfs |
| ? psutil imported from xlwings._xlmac |
| ? readline imported from cmd, code, pdb |
| ? reports.Markdown imported from xlwings.pro |
| ? reports.MarkdownStyle imported from xlwings.pro |
| ? requests imported from xlwings.pro.module_permissions |
| ? resource imported from test.support |
| ? urllib.quote imported from send2trash.plat_other, xlwings.mistune.util |
| ? win32com.gen_py imported from win32com |
| Building 'dist\hoge.exe'. |
| Building shared code archive 'dist\lib\libs.zip'. |
| Copy DLL C:\Users\ore\AppData\Local\Programs\Python\Python311\DLLs\tcl86t.dll to dist |
| Copy DLL C:\Users\ore\AppData\Local\Programs\Python\Python311\DLLs\libcrypto-1_1.dll to dist |
| Copy DLL C:\Users\ore\AppData\Local\Programs\Python\Python311\DLLs\libffi-8.dll to dist |
| Copy DLL C:\Users\ore\AppData\Local\Programs\Python\Python311\DLLs\libssl-1_1.dll to dist |
| Copy DLL C:\Users\ore\AppData\Local\Programs\Python\Python311\DLLs\tk86t.dll to dist |
| PS C:\Users\ore> |
あなたの回答
tips
プレビュー