簡體   English   中英

AttributeError:'模塊'對象沒有運行可執行文件的屬性'__version__'

[英]AttributeError: 'module' object has no attribute '__version__' running the executable

我創建了一個腳本,該腳本可以通過Python正常運行,然后創建了一個可執行文件,並收到錯誤消息:

File "site-packages\pandas\compat\numpy\__init__.py", line 11, in <module>
AttributeError: 'module' object has no attribute '__version__'

我發現的所有其他問題都與通過Python運行的腳本有關。

這似乎是一個import問題,但是我不知道如何在可執行文件中解決它。

這是我的.spec文件:

# -*- mode: python -*-

block_cipher = None

a = Analysis(['test.py'],
             pathex=['D:\\Projects\\Test'],
             binaries=[],
             datas=[],
             hiddenimports=['numpy', 'pandas', 'pandas.compat', 'xml', 'xml.etree', 'xml.etree.ElementTree'],
             hookspath=[],
             runtime_hooks=['.\\pyi_rth_arcpy.py'],
             excludes=['arcpy'],
             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='test',
          debug=False,
          strip=False,
          upx=True,
          console=True)
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='test')

你有什么主意嗎?

我發現了問題。

為了使用arcpy模塊,我創建了名為pyi_rth_arcpy.pyruntime_hook (我從另一個問題中復制了)。 在此腳本中,我向sys.path添加了一個虛假的site-packagesnumpy模塊,這造成了import問題。

我只是將numpy更改為pyi_rth_arcpy.py ,將其改為numpy ,我選擇了scipy

這是pyi_rth_arcpy.py

import sys

# Add arcpy's directories to sys.path
from archook import get_arcpy
get_arcpy()

# Additional tweaks to placate arcpy
from types import ModuleType
sys.path.append('./site-packages')  # Add a dummy site-packages folder to sys.path
sys.modules['scipy'] = ModuleType('scipy')  # Add a fake scipy module to sys.modules

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM