import os
import tkinter.filedialog
import tkinter.messagebox
import pandas as pd
import openpyxl
# 初始画面
root = tkinter.Tk()
root.withdraw()
fTyp = [("所有的文件", "*.*"), ("csv文件", "*.csv"), ("dat文件", "*.dat"), ("txt文件", "*.txt")]
iDir = os.path.abspath(os.path.dirname(__file__))
tkinter.messagebox.showinfo('Data Processing', '请选择处理的订单数据文件')
file1 = tkinter.filedialog.askopenfilename(filetypes=fTyp, initialdir=iDir)
file2 = file1[:-3] + 'xlsx'
file3 = file1[:-3] + 'xlsx'
# 交换处理
try:
df = pd.read_csv(file1, encoding='UTF-8', usecols=[0, 2, 8, 23], header=None, dtype="object")
except:
df = pd.read_csv(file1, encoding='UTF-8', header=0, dtype="object")
file1a = file1 + '_data.txt'
df.to_csv(file1a, encoding='UTF-8', header=False)
df = pd.read_csv(file1a, encoding='UTF-8', header=None, dtype="object")
# 临时文件删除
os.remove(file1)
# excel文件写入
df.to_excel(file2, encoding='UTF-8', index=None, header=None)
# 首行插入
wb = openpyxl.load_workbook(file2)
# ws = wb.active
ws = wb.worksheets[0]
ws.insert_rows(1)
ws['A1'].value = len(df)
wb.save(file2)
else:
# excel文件写入
df.to_excel(file2, encoding='UTF-8', index=None, header=1)
# read input xlsx
wb1 = openpyxl.load_workbook(file2)
ws1 = wb1.worksheets[0]
# set font
ws1['A1'] = '型号'
ws1['B1'] = '订单数量'
ws1['C1'] = '订单日期'
ws1['D1'] = '提货日期'
# save xlsx file
wb1.save(file2)
data = pd.read_excel(file2)
df = pd.DataFrame(data)
df_utility = df.pivot_table(values='订单日期', columns=['提货日期', '订单数量'], index='型号', margins=False)
print(df_utility)
df_utility.to_excel(file3, encoding='UTF-8')
# 输出处理的文件名及位置
files = '数据源 ' + file1 + '\n输出数据 ' + file3
tkinter.messagebox.showinfo('', files)
报错信息:
PS D:\Users\jcc_s2011449\Desktop\ystt> pyinstaller -F -w ystt.py
68 INFO: PyInstaller: 4.3
68 INFO: Python: 3.9.0
68 INFO: Platform: Windows-10-10.0.19041-SP0
68 INFO: wrote D:\Users\jcc_s2011449\Desktop\ystt\ystt.spec
84 INFO: UPX is not available.
84 INFO: Extending PYTHONPATH with paths
['D:\\Users\\jcc_s2011449\\Desktop\\ystt',
'D:\\Users\\jcc_s2011449\\Desktop\\ystt']
130 INFO: checking Analysis
130 INFO: Building Analysis because Analysis-00.toc is non existent
130 INFO: Initializing module dependency graph...
130 INFO: Caching module graph hooks...
130 WARNING: Several hooks defined for module 'win32ctypes.core'. Please take care they do not conflict.
145 INFO: Analyzing base_library.zip ...
3050 INFO: Processing pre-find module path hook distutils from 'd:\\users\\jcc_s2011449\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
3058 INFO: distutils: retargeting to non-venv dir 'd:\\users\\jcc_s2011449\\appdata\\local\\programs\\python\\python39\\lib'
6884 INFO: Caching module dependency graph...
7063 INFO: running Analysis Analysis-00.toc
7085 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by d:\users\jcc_s2011449\appdata\local\programs\python\python39\python.exe
7201 WARNING: lib not found: api-ms-win-core-path-l1-1-0.dll dependency of d:\users\jcc_s2011449\appdata\local\programs\python\python39\python39.dll
7201 INFO: Analyzing D:\Users\jcc_s2011449\Desktop\ystt\ystt.py
8906 INFO: Processing pre-find module path hook site from 'd:\\users\\jcc_s2011449\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
8906 INFO: site: retargeting to fake-dir 'd:\\users\\jcc_s2011449\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\fake-modules'
17778 INFO: Processing pre-safe import module hook six.moves from 'd:\\users\\jcc_s2011449\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:361: SyntaxWarning: "is" with a literal. Did you mean "=="?
if token is '':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:2441: SyntaxWarning: "is" with a literal. Did you mean "=="?
if options['min_type'] is 'min' and options['min_value'] == 0:
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:2444: SyntaxWarning: "is" with a literal. Did you mean "=="?
if options['max_type'] is 'max' and options['max_value'] == 0:
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:5009: SyntaxWarning: "is" with a literal. Did you mean "=="?
if props[i]['type'] is 'number':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:6837: SyntaxWarning: "is not" with a literal. Did you mean "!="?
if data_bar['bar_axis_position'] is not 'none':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:6872: SyntaxWarning: "is" with a literal. Did you mean "=="?
if data_bar['bar_direction'] is 'left':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:6875: SyntaxWarning: "is" with a literal. Did you mean "=="?
if data_bar['bar_direction'] is 'right':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:6885: SyntaxWarning: "is" with a literal. Did you mean "=="?
if data_bar['bar_axis_position'] is 'middle':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\worksheet.py:6888: SyntaxWarning: "is" with a literal. Did you mean "=="?
if data_bar['bar_axis_position'] is 'none':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\chart.py:2497: SyntaxWarning: "is" with a literal. Did you mean "=="?
if val is 'right':
d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\xlsxwriter\chart.py:2500: SyntaxWarning: "is" with a literal. Did you mean "=="?
if val is 'left':
36778 INFO: Processing module hooks...
36778 INFO: Loading module hook 'hook-certifi.py' from 'd:\\users\\jcc_s2011449\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
36778 INFO: Loading module hook 'hook-IPython.py' from 'd:\\users\\jcc_s2011449\\appdata\\local\\programs\\python\\python39\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\__init__.py", line 55, in <module>
from .core.application import Application
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\ultratb.py", line 112, in <module>
from IPython.core import debugger
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\debugger.py", line 38, in <module>
from IPython.utils import PyColorize
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\utils\PyColorize.py", line 47, in <module>
from .colorable import Colorable
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\utils\colorable.py", line 12, in <module>
import pygments
ModuleNotFoundError: No module named 'pygments'
Traceback (most recent call last):
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\pkgutil.py", line 494, in find_loader
spec = importlib.util.find_spec(fullname)
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\importlib\util.py", line 94, in find_spec
parent = __import__(parent_name, fromlist=['__path__'])
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\__init__.py", line 55, in <module>
from .core.application import Application
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\application.py", line 25, in <module>
from IPython.core import release, crashhandler
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\ultratb.py", line 112, in <module>
from IPython.core import debugger
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\core\debugger.py", line 38, in <module>
from IPython.utils import PyColorize
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\utils\PyColorize.py", line 47, in <module>
from .colorable import Colorable
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\IPython\utils\colorable.py", line 12, in <module>
import pygments
ModuleNotFoundError: No module named 'pygments'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 357, in get_module_file_attribute
loader = pkgutil.find_loader(package)
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\pkgutil.py", line 500, in find_loader
raise ImportError(msg.format(fullname, type(ex), ex)) from ex
ImportError: Error while finding loader for 'IPython.extensions' (<class 'ModuleNotFoundError'>: No module named 'pygments')
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\depend\imphook.py", line 408, in _load_hook_module
self._hook_module = importlib_load_source(
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\compat.py", line 605, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 469, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 969, in load_module
File "<frozen importlib._bootstrap_external>", line 794, in load_module
File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py", line 34, in <module>
datas += collect_data_files('IPython.extensions', include_py_files=True)
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 791, in collect_data_files
pkg_base, pkg_dir = get_package_paths(package)
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 574, in get_package_paths
file_attr = get_module_file_attribute(package)
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 376, in get_module_file_attribute
raise ImportError('Unable to load module attribute') from e
ImportError: Unable to load module attribute
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\Users\jcc_s2011449\AppData\Local\Programs\Python\Python39\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 737, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 684, in build
exec(code, spec_namespace)
File "D:\Users\jcc_s2011449\Desktop\ystt\ystt.spec", line 7, in <module>
a = Analysis(['ystt.py'],
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
self.__postinit__()
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\building\build_main.py", line 420, in assemble
self.graph.process_post_graph_hooks()
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\depend\analysis.py", line 367, in process_post_graph_hooks
module_hook.post_graph()
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\depend\imphook.py", line 447, in post_graph
self._load_hook_module()
File "d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\PyInstaller\depend\imphook.py", line 412, in _load_hook_module
raise ImportErrorWhenRunningHook(
PyInstaller.exceptions.ImportErrorWhenRunningHook: Failed to import module __PyInstaller_hooks_0_IPython required by hook for module d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py. Please check whether module __PyInstaller_hooks_0_IPython actually exists and whether the hook is compatible with your version of d:\users\jcc_s2011449\appdata\local\programs\python\python39\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks\hook-IPython.py: You might want to read more about hooks in the manual and provide a pull-request to improve PyInstaller.
请问如何解决?
Failed to import module __PyInstaller_hook
模块没有正确加载
might want to read more about hooks in the manual and provide a pull-request to improve PyInstaller.
https://blog.csdn.net/wskzgz/article/details/88912027
你看下这篇文章希望对你有帮助pyinstaller使用遇到错误Error: import module hook setuptools.extern.six.moves, No module named _vendor.six_li123_123_的博客-CSDN博客
您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632