Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

"Attempt to import module: builtins"

Open octogenary opened this issue 9 years ago • 3 comments

I followed all the instructions at http://sterlicht.alwaysdata.net/transcrypt.org/docs/html/installation_use.html up to 2.2; attempted to transcrypt prob-break.py (my own program), and received this error:

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


Error while compiling (offending file last):
	File '/home/chair/Documents/Top/ibreak-calc/prob-break.py', line 1, at import of:
	File '/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/operator.py', line 22, namely:
	
	Attempt to import module: builtins
	Can't find any of:
		/home/chair/Documents/Top/ibreak-calc/builtins.py
		/home/chair/Documents/Top/ibreak-calc/__javascript__/builtins.mod.js
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/site-packages/transcrypt/modules/builtins.py
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/site-packages/transcrypt/modules/__javascript__/builtins.mod.js
		/home/chair/Documents/Top/ibreak-calc/env/bin/builtins.py
		/home/chair/Documents/Top/ibreak-calc/env/bin/__javascript__/builtins.mod.js
		/home/chair/Documents/Top/ibreak-calc/env/lib/python35.zip/builtins.py
		/home/chair/Documents/Top/ibreak-calc/env/lib/python35.zip/__javascript__/builtins.mod.js
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/builtins.py
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/__javascript__/builtins.mod.js
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/plat-x86_64-linux-gnu/builtins.py
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/plat-x86_64-linux-gnu/__javascript__/builtins.mod.js
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/lib-dynload/builtins.py
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/lib-dynload/__javascript__/builtins.mod.js
		/usr/lib/python3.5/builtins.py
		/usr/lib/python3.5/__javascript__/builtins.mod.js
		/usr/lib/python3.5/plat-x86_64-linux-gnu/builtins.py
		/usr/lib/python3.5/plat-x86_64-linux-gnu/__javascript__/builtins.mod.js
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/site-packages/builtins.py
		/home/chair/Documents/Top/ibreak-calc/env/lib/python3.5/site-packages/__javascript__/builtins.mod.js


Aborted

octogenary avatar Feb 12 '17 19:02 octogenary

I've been trying to understand what's happening here.

It seems like module prob-break.py tries to import a CPyhton module called operator.py, which in turn tries to import builtins.py. However, builtins isn't an ordinary module that can be imported from a .py file.

The point where it starts to go wrong is importing operator.py in the first place. Transcrypt mainly relies on JS libraries. Only 'pure Python' modules that only (recursively) depend on other 'pure Python' modules can be imported, with some limitations like % formatting. Transcrypt will compile all imported pure Python modules to JavaScript. Many modules in the CPython distro rely on compiled C-code, which doesn't run in the browser without use of e.g. emscrypten.

KR Jacques

JdeH avatar Feb 21 '17 08:02 JdeH

I've got same problem trying to compile sympy library. Just an idea: pypy could have all these modules written in rpython (I did not check it), so they might be compilable by transcrypt.

AlekseyCherepanov avatar Aug 31 '17 11:08 AlekseyCherepanov

RPython is not directly compatible with the subset of Python TC uses tho.

pmukherjeee avatar Aug 31 '17 11:08 pmukherjeee