list index out of range error when compiling jquery demo
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:
- The error message
list index out of rangeis not separated from the wordTraceback. I.e. they are squished together aslist index out of rangeTraceback (most recent call last): - 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: <unprintable Error object>
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>
Thanks, will take a look at that.
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!!
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!
Still fails at import json. Any solutions?
Is there a workaround, fails for me on fresh install against a file with just one print statement in it.
I too have this issue
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
I had a similar problem, apparently because I tried to compile a file with an extension different than py.
I am facing same issue, should we expect fixing this soon or any workaround could be possible for the time being?
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.