TranscryptOrg / Transcrypt

Python 3.9 to JavaScript compiler - Lean, fast, open!
https://www.transcrypt.org
Apache License 2.0
2.85k stars 213 forks source link

list index out of range error when compiling jquery demo #604

Open metaperl opened 5 years ago

metaperl commented 5 years ago

In the source code located here I issued the compilation command python -m transcrypt -b -m -n hello.py and I got the following error about which you should note two things:

  1. The error message list index out of range is not separated from the word Traceback. I.e. they are squished together as list index out of rangeTraceback (most recent call last):
  2. for some reason the Error object was unprintable and I have no idea why the program is failing.
    
    (venv-transcrypt) c:\prg\transcrypt-play\2-jquery>python -m transcrypt -b -m -n hello.py
    python -m transcrypt -b -m -n hello.py

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

Saving target code in: c:/prg/transcrypt-play/2-jquery/target/org.transcrypt.runtime.js

list index out of rangeTraceback (most recent call last): File "c:/prg/venv-transcrypt/lib/site-packages/transcrypt/modules\org\transcrypt\compiler.py", line 104, in init self.provide (self.mainModuleName, 'main') File "c:/prg/venv-transcrypt/lib/site-packages/transcrypt/modules\org\transcrypt\compiler.py", line 118, in provide return Module (self, moduleName, moduleName, filter) File "c:/prg/venv-transcrypt/lib/site-packages/transcrypt/modules\org\transcrypt\compiler.py", line 127, in init self.findPaths (filter) File "c:/prg/venv-transcrypt/lib/site-packages/transcrypt/modules\org\transcrypt\compiler.py", line 312, in findPaths message = '\n\tImport error, can\'t find any of:\n\t\t{}\n'.format ('\n\t\t'. join (self.program.searchedModulePaths)) org.transcrypt.utils.Error:

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "c:\prg\venv-transcrypt\lib\site-packages\transcrypt__main.py", line 171, in main compiler.Program (transpilationDirs, symbols, envir) File "c:/prg/venv-transcrypt/lib/site-packages/transcrypt/modules\org\transcrypt\compiler.py", line 108, in init message = f'\n\t{exception}' File "c:/prg/venv-transcrypt/lib/site-packages/transcrypt/modules\org\transcrypt\utils.py", line 211, in str__ result += '\n\tFile \'{}\', line {}, namely:'.format (str (program.importStack [-1][0] .name), self.lineNr) IndexError: list index out of range

Aborted

(venv-transcrypt) c:\prg\transcrypt-play\2-jquery>

JdeH commented 5 years ago

Thanks, will take a look at that.

wiltonmaddams commented 5 years ago

Hi, +1 on this - tried to run the default test command from docs after installing (transcrypt -b -c -da autotest) and received the same errors as @metaperl. Environment is OSX 10.14.2 w/ Python: 3.7.1 and Transcrypt 3.7.16.

I ran this to test my installation after a test program I wrote wouldn't compile because importing the json module failed (using the npm json module does not error - so made me wonder if there is a list published somewhere in the official documentation other than the link to Dan Stromberg's feature matrix indicating what Python standard library modules are included in Transcrypt?) :

line 2, at import of:
    File '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py', line 108, at import of:
    File 'codecs', line 44, namely:

    Can't import module 'codecs'"

Thanks for all your work on this package!!

notEvil commented 5 years ago

Hi,

I got the same error message and by adding a couple of print statements where the exception is raised I found that the problem in my case was a directory with exactly the same name as the python script. Transcrypt got graph.py as argument, looked for graph/__init__.py (which doesn't exist) and decided that the python script doesn't exist. After renaming the python script, everything was fine. Hope it might help!

ZhengyiLuo commented 5 years ago

Still fails at import json. Any solutions?

h1771t commented 4 years ago

Is there a workaround, fails for me on fresh install against a file with just one print statement in it.

charlysotelo commented 4 years ago

I too have this issue

dayvudev commented 3 years ago

Hi. Forgive me if this is too cliche answer, but I can see that this topic is still open and I was also struggling with this problem (using webpack) Maybe it's an old topic, but I ran into a similar problem by accident. I've added python file to webpack compilation (using py-loader). After running th command npm run watch I saw the error. U ran python script compilation manually and I saw the same error as in the content of the topic.

I edited the file: PYTHON_PATH\Lib\site-packages\transcrypt\modules\org\transcrypt\utils.py and commented line 212 result += '\n\tFile \'{}\', line {}, namely:'.format (str (program.importStack [-1][0] .name), self.lineNr)

After restarting the command, I saw another error saying that the path to my file is invalid, more precisely missing slashes (have been removed from the path).

I ran the command manually: transcrypt -b -n -m PATH_TO_FILE - it did not work. I added double quotes to path and ran the command again: transcrypt -b -n -m "PATH_TO_FILE" - it worked. The slashes in my file path were in the wrong direction, so I got an error and the path was solved badly.

Maybe it will be helpful for someone. Regards

eevleevs commented 3 years ago

I had a similar problem, apparently because I tried to compile a file with an extension different than py.

bishoymaurice commented 3 years ago

I am facing same issue, should we expect fixing this soon or any workaround could be possible for the time being?

dewball345 commented 3 years ago

I think it could be that there are a bunch of syntax errors in the python example code, especially when it comes to spacing? Try fixing those and see if it works.