1

我有一个名为的 Python 文件hello.py

import openpyxl

def operate_excel():
    file = 'dummy.xlsx'
    new_row = ['data1', 'data2', 'data3', 'data4']

    wb = openpyxl.load_workbook(filename=file)
    ws = wb['Sheet1']     # Older method was  .get_sheet_by_name('Sheet1')
    row = ws.max_row + 1

    for col, entry in enumerate(new_row, start=1):
        ws.cell(row=row, column=col, value=entry)

    wb.save(file)

当我直接从 Python 运行它时,它可以工作。但是,当我尝试使用以下命令对其进行转码时,它失败了:

python3 -m transcrypt -b ./Codes/js_excel_operations/hello.py

此命令生成以下输出行:

Transcrypt (TM) Python to JavaScript Small Sane Subset Transpiler Version 3.7.16
Copyright (C) Geatec Engineering. License: Apache 2.0


Saving target code in: /Users/stuck/Codes/js_excel_operations/__target__/org.transcrypt.__runtime__.js
Saving minified target code in: /Users/stuck/Codes/js_excel_operations/__target__/org.transcrypt.__runtime__.js
Saving target code in: /Users/stuck/Codes/js_excel_operations/__target__/openpyxl._constants.js
Saving minified target code in: /Users/stuck/Codes/js_excel_operations/__target__/openpyxl._constants.js

Error while compiling (offending file last):
File './Codes/js_excel_operations/hello.py', line 1, at import of:
File '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/openpyxl/__init__.py', line 8, at import of:
File 'openpyxl.reader.excel', line 62, namely:

Import error, can't find any of:
    ./Codes/js_excel_operations/drawings/find_images.py
    ./Codes/js_excel_operations/drawings/find_images.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transcrypt/modules/drawings/find_images.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transcrypt/modules/drawings/find_images.js
    /Users/stuck/drawings/find_images.py
    /Users/stuck/drawings/find_images.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/drawings/find_images.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/drawings/find_images.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/drawings/find_images.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/drawings/find_images.js
    /Users/stuck/Library/Python/3.7/lib/python/site-packages/drawings/find_images.py
    /Users/stuck/Library/Python/3.7/lib/python/site-packages/drawings/find_images.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/drawings/find_images.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/drawings/find_images.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyradio-0.8.8-py3.7.egg/drawings/find_images.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyradio-0.8.8-py3.7.egg/drawings/find_images.js
    ./Codes/js_excel_operations/drawings.py
    ./Codes/js_excel_operations/drawings.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transcrypt/modules/drawings.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/transcrypt/modules/drawings.js
    /Users/stuck/drawings.py
    /Users/stuck/drawings.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/drawings.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/drawings.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/drawings.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/drawings.js
    /Users/stuck/Library/Python/3.7/lib/python/site-packages/drawings.py
    /Users/stuck/Library/Python/3.7/lib/python/site-packages/drawings.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/drawings.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/drawings.js
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyradio-0.8.8-py3.7.egg/drawings.py
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyradio-0.8.8-py3.7.egg/drawings.js

Aborted

那么,可能是什么问题?我错过了什么吗?

4

1 回答 1

3

请参阅Transcrypt 文档中的第 1.3 节。简而言之,您通常会想要使用 JS 第三方库。

根本原因是 Transcrypt 无法将带有已编译组件的库转换为 JS。此外,在Transcrypt中,所有的标准库都没有实现,只有一些Essentials 。对于其他一切,请使用 JS 库。

于 2020-12-23T01:08:09.780 回答