简体   繁体   中英

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

I have created a script that works fine through Python, then I created an executable and I obtain the error:

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

All the other questions I found are related to scripts running through Python.

It seems to be a import problem but I don't know how to solve it in the executable.

This is my .spec file:

# -*- 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')

Do you have any idea?

I found the problem.

To use the module arcpy I created the runtime_hook named pyi_rth_arcpy.py (I copied from another question). In this script I added a fake site-packages and numpy module to sys.path and this created the import problem.

I just changed, into pyi_rth_arcpy.py , numpy to a module that I don't use, I chose scipy .

This is 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM