stuck
stuck

Reputation: 1570

Transcrypt with import statement

I have a Python file called hello.py which is:

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)

When I run it from Python directly, it works. However, when I tried to transcrypt it with following command it fails:

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

And this command generates following output lines:

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

So, what can be the problem? Am I missing something?

Upvotes: 1

Views: 643

Answers (1)

fzzylogic
fzzylogic

Reputation: 2283

See section 1.3 in the Transcrypt docs. In short, often you'll want to use JS third party libraries.

The underlying reason is that Transcrypt can't convert libraries with compiled components into JS. Also, within Transcrypt, all of the standard library hasn't been implemented, only some of the essentials. For everything else, use JS libs.

Upvotes: 3

Related Questions