正在加载中……
最新消息:欢迎大家访问,导航分类不完善,如果找不到自己想要的文章,可以通过【关键词】来进行搜索,^_^!

[解决方法]pyinstaller3.2打包openpyxl2.4出现__version__错误

python REKFAN.COM 813浏览 0评论

更多


openpyxl_test.py 部分代码
 
from openpyxl.reader.excel  import  load_workbook
from openpyxl.workbook  import  Workbook    

def createExcel(excel_file_name="rekfan.xlsx",excel_table_name="rekfan_sheet"):
'''创建Excel表格'''
try:
wb = Workbook()
ws = wb.active
ws.title = excel_table_name
header = ["列1","列2","列3"]
ws.append(self.header)
wb.save(excel_file_name)
except Exception as e:
print(e)

createExcel()
 
编译过程:
D:\Desktop\rekfan\openpyxl_test>pyinstaller -F openpyxl_test.py
1294 INFO: PyInstaller: 3.2
1297 INFO: Python: 3.5.2
1301 INFO: Platform: Windows-10-10.0.10586-SP0
1307 INFO: wrote D:\Desktop\rekfan\openpyxl_test\openpyxl_test.spec
1588 INFO: UPX is available.
1598 INFO: Extending PYTHONPATH with paths
['D:\\Desktop\\rekfan\\openpyxl_test', 'D:\\Desktop\\rekfan\\openpyxl_test']
1615 INFO: checking Analysis
2061 INFO: Building because d:\python35-32\lib\site-packages\openpyxl\packaging\extended.py changed
2076 INFO: Initializing module dependency graph...
2095 INFO: Initializing module graph hooks...
2166 INFO: Analyzing base_library.zip ...
11406 INFO: running Analysis out00-Analysis.toc
11925 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of d:\python35-32\python.exe
12144 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\python.exe
12419 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\python.exe
12677 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\python.exe
12902 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of d:\python35-32\python.exe
14759 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of d:\python35-32\python35.dll
14981 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of d:\python35-32\python35.dll
15205 WARNING: lib not found: api-ms-win-crt-process-l1-1-0.dll dependency of d:\python35-32\python35.dll
15458 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of d:\python35-32\python35.dll
15696 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of d:\python35-32\python35.dll
15970 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of d:\python35-32\python35.dll
16200 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\python35.dll
16444 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of d:\python35-32\python35.dll
16666 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\python35.dll
16894 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\python35.dll
17177 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\python35.dll
17491 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of d:\python35-32\python35.dll
17914 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\VCRUNTIME140.dll
18140 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of d:\python35-32\VCRUNTIME140.dll
18370 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\VCRUNTIME140.dll
18602 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\VCRUNTIME140.dll
18857 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\VCRUNTIME140.dll
18869 INFO: Caching module hooks...
19022 INFO: Analyzing D:\Desktop\rekfan\openpyxl_test\openpyxl_test.py
29032 INFO: Loading module hooks...
29039 INFO: Loading module hook "hook-xml.py"...
29279 INFO: Loading module hook "hook-encodings.py"...
29365 INFO: Loading module hook "hook-PIL.Image.py"...
30114 INFO: Processing pre-find module path hook   distutils
31237 INFO: Loading module hook "hook-pydoc.py"...
31265 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
31300 INFO: Loading module hook "hook-PIL.py"...
31320 INFO: Import to be excluded not found: 'FixTk'
31324 INFO: Excluding import 'PyQt5'
31347 WARNING:   Removing import PIL.ImageQt from module PyQt5.QImage
31354 WARNING:   Removing import PIL.ImageQt from module PyQt5.QPixmap
31369 WARNING:   Removing import PIL.ImageQt from module PyQt5.qRgba
31377 WARNING:   Removing import PIL.ImageQt from module PyQt5
31391 INFO: Excluding import 'tkinter'
31411 WARNING:   Removing import PIL.ImageTk from module tkinter
31419 INFO: Excluding import 'PyQt4'
31439 WARNING:   Removing import PIL.ImageQt from module PyQt4.QPixmap
31445 WARNING:   Removing import PIL.ImageQt from module PyQt4.QImage
31455 WARNING:   Removing import PIL.ImageQt from module PyQt4
31470 WARNING:   Removing import PIL.ImageQt from module PyQt4.qRgba
31478 INFO: Excluding import 'PySide'
31497 WARNING:   Removing import PIL.ImageQt from module PySide.QPixmap
31503 WARNING:   Removing import PIL.ImageQt from module PySide.qRgba
31511 WARNING:   Removing import PIL.ImageQt from module PySide.QImage
31517 WARNING:   Removing import PIL.ImageQt from module PySide
31531 INFO: Loading module hook "hook-_tkinter.py"...
32162 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_tkinter.pyd
32503 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\_tkinter.pyd
33520 INFO: checking Tree
33995 INFO: checking Tree
34119 INFO: Loading module hook "hook-distutils.py"...
34155 INFO: Loading module hook "hook-PIL.SpiderImagePlugin.py"...
34166 INFO: Import to be excluded not found: 'FixTk'
34171 INFO: Excluding import 'tkinter'
34315 INFO: Looking for ctypes DLLs
34369 INFO: Analyzing run-time hooks ...
34457 INFO: Looking for dynamic libraries
35144 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
35413 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
35636 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
40684 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
40933 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
41168 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
41414 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
41646 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
41875 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
42171 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\DLLs\_ssl.pyd
42875 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_ctypes.pyd
43117 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\DLLs\_ctypes.pyd
43349 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\_ctypes.pyd
43818 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of d:\python35-32\DLLs\pyexpat.pyd
44070 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of d:\python35-32\DLLs\pyexpat.pyd
44324 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\pyexpat.pyd
44556 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\pyexpat.pyd
44783 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\DLLs\pyexpat.pyd
50048 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
50159 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
50237 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
50325 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
50397 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
50468 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
50684 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
50948 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
51398 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\DLLs\_hashlib.pyd
51843 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_lzma.pyd
52091 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\DLLs\_lzma.pyd
52626 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_socket.pyd
53126 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of d:\python35-32\DLLs\_bz2.pyd
53388 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_bz2.pyd
53606 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\DLLs\_bz2.pyd
53835 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\_bz2.pyd
54086 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\DLLs\_bz2.pyd
54539 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\unicodedata.pyd
54802 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\DLLs\unicodedata.pyd
55028 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\unicodedata.pyd
55413 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\select.pyd
56069 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of d:\python35-32\DLLs\_elementtree.pyd
56362 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of d:\python35-32\DLLs\_elementtree.pyd
56593 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_elementtree.pyd
56852 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\DLLs\_elementtree.pyd
57075 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\DLLs\_elementtree.pyd
57494 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_webp.cp35-win32.pyd
57758 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_webp.cp35-win32.pyd
58018 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_webp.cp35-win32.pyd
58266 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_webp.cp35-win32.pyd
58674 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imagingtk.cp35-win32.pyd
58917 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imagingtk.cp35-win32.pyd
59308 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imagingtk.cp35-win32.pyd
59574 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imagingtk.cp35-win32.pyd
60089 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of d:\python35-32\DLLs\_decimal.pyd
60338 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\DLLs\_decimal.pyd
60573 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of d:\python35-32\DLLs\_decimal.pyd
60825 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\DLLs\_decimal.pyd
61089 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\DLLs\_decimal.pyd
61340 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\DLLs\_decimal.pyd
61573 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of d:\python35-32\DLLs\_decimal.pyd
62319 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
62599 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
62830 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
63109 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
63348 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
63586 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
63916 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
64262 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of d:\python35-32\lib\site-packages\PIL\_imaging.cp35-win32.pyd
64296 WARNING: Attempted to add Python module twice with different upper/lowercases: PIL._webp
64307 WARNING: Attempted to add Python module twice with different upper/lowercases: PIL._imagingtk
64315 WARNING: Attempted to add Python module twice with different upper/lowercases: PIL._imaging
64326 INFO: Looking for eggs
64331 INFO: Using Python library d:\python35-32\python35.dll
64339 INFO: Found binding redirects:
[]
64399 INFO: Warnings written to D:\Desktop\rekfan\openpyxl_test\build\openpyxl_test\warnopenpyxl_test.txt
64582 INFO: checking PYZ
64618 INFO: Building because toc changed
64624 INFO: Building PYZ (ZlibArchive) D:\Desktop\rekfan\openpyxl_test\build\openpyxl_test\out00-PYZ.pyz
68137 INFO: checking PKG
68159 INFO: Building because toc changed
68163 INFO: Building PKG (CArchive) out00-PKG.pkg
72150 INFO: Bootloader d:\python35-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
72153 INFO: checking EXE
72186 INFO: Building because manifest changed
72187 INFO: Building EXE from out00-EXE.toc
72196 INFO: Appending archive to EXE D:\Desktop\rekfan\openpyxl_test\dist\openpyxl_test.exe
 
编译成功后运行: 
D:\Desktop\rekfan\openpyxl_test>D:\Desktop\rekfan\openpyxl_test\dist\openpyxl_test.exe
Traceback (most recent call last):
  File "openpyxl_test.py", line 17, in <module>
    from openpyxl.reader.excel  import  load_workbook
  File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\openpyxl\__init__.py", line 29, in <module>
  File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\openpyxl\workbook\__init__.py", line 5, in <module>
  File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\openpyxl\workbook\workbook.py", line 16, in <module>
  File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\openpyxl\writer\write_only.py", line 23, in <module>
  File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\openpyxl\writer\excel.py", line 36, in <module>
  File "d:\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
    exec(bytecode, module.__dict__)
  File "site-packages\openpyxl\packaging\extended.py", line 4, in <module>
ImportError: cannot import name '__version__'
Failed to execute script openpyxl_test
 
 
cannot import name '__version__' 解决方法:
 
注:以下目录D:\Python35-32 为作者python安装根目录,自己根据安装目录查找
 
将D:\Python35-32\Lib\site-packages\openpyxl\__init__.py文件下的如下代码注释 
try:
    here = os.path.abspath(os.path.dirname(__file__))
    src_file = os.path.join(here, ".constants.json")
    with open(src_file) as src:
        constants = json.load(src)
        __author__ = constants['__author__']
        __author_email__ = constants["__author_email__"]
        __license__ = constants["__license__"]
        __maintainer_email__ = constants["__maintainer_email__"]
        __url__ = constants["__url__"]
        __version__ = constants["__version__"]
except IOError:
    # packaged
    pass
读取 D:\Python35-32\Lib\site-packages\openpyxl\.constants.json下的内容
放到D:\Python35-32\Lib\site-packages\openpyxl\__init__.py下,最终__init__.py内容
 
# Copyright (c) 2010-2016 openpyxl

# @license: http://www.opensource.org/licenses/mit-license.php
# @author: see AUTHORS file


import json
import os

#try:
#    here = os.path.abspath(os.path.dirname(__file__))
#    src_file = os.path.join(here, ".constants.json")
#    with open(src_file) as src:
#        constants = json.load(src)
#        __author__ = constants['__author__']
#        __author_email__ = constants["__author_email__"]
#        __license__ = constants["__license__"]
#        __maintainer_email__ = constants["__maintainer_email__"]
#        __url__ = constants["__url__"]
#        __version__ = constants["__version__"]
#except IOError:
#    # packaged
#    pass

__author__= "See AUTHORS"
__author_email__= "eric.gazoni@gmail.com"
__license__= "MIT/Expat"
__maintainer_email__= "openpyxl-users@googlegroups.com"
__url__= "http://openpyxl.readthedocs.org"
__version__= "2.4.0"

"""Imports for the openpyxl package."""
from openpyxl.compat.numbers import NUMPY, PANDAS
from openpyxl.xml import LXML

from openpyxl.workbook import Workbook
from openpyxl.reader.excel import load_workbook
 
然后重新编译 
D:\Desktop\rekfan\openpyxl_test>pyinstaller -F openpyxl_test.py
运行D:\Desktop\rekfan\openpyxl_test\dist\openpyxl_test.exe 一切正常!

转载请注明:|REKFAN|系统运维| » [解决方法]pyinstaller3.2打包openpyxl2.4出现__version__错误

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址