replit-archive / empythoned Goto Github PK
View Code? Open in Web Editor NEWCPython compiled to JS using emscripten
CPython compiled to JS using emscripten
First of all, I'd like to say how amazed I was when I saw this. Truly fantastic!
Unfortunately, I was not able to get empythoned working on my local machine as it did on repl.it. Running locally (via Django) produces the error:
XMLHttpRequest.responseType cannot be changed for synchronous HTTP(S) requests made from the window context.
python.opt.js:229 Uncaught Error: INVALID_ACCESS_ERR: DOM Exception 15
This seems to be the same issue that was fixed in Issue #6, which was fixed 24 days ago. However, I note that the source in the respository has not be updated in 8 months. Has the fix simply not been reflected in the repository? Or is there something else that I need to do?
I'd absolutely love to use this. :)
I tried the file IO, it seems that the files are kept temporarily in the browser end. How to read file from the server and how to save file to the server?
Thanks!
Hi, I'm trying to use empythoned along with the Python xlrd library to make a JavaScript Excel file reader.
However, I'm running into problems, and I'm hoping someone could help me with some advice.
My approach so far has been to copy all the xlrd files into the virtual files system by passing them into the python interpreter as strings. Is there a better way to add modules? I haven't been successful in figuring out how to create a file system image directly.
The main problem I'm running into is that the xlrd module is only partially imported.
My workspace is located here:
https://c9.io/nathanathan/empythoned
And you can use the execution environment with xlrd in the sandbox directory here:
https://c9.io/nathanathan/empythoned/workspace/index.html
Running the following it appears that only some of the xlrd module is imported.
import xlrd
print dir(xlrd)
(Also, the above script doesn't produce any output on the first execution for some reason.)
os.devnull
outputs /dev/null
, however it doesn't exists!
Redirecting stdout to /dev/null
doesn't work because of this.
See discussion on emscripten-core/emscripten#158
Results from running Python on repl.it, which I'm assuming reflect here:
pow(2,36,100000)
=> 69184L
2**36 % 100000
=> 76736L
76736 is the correct result. Also:
pow(2,40,100000)
=> 127776
which is greater than the passed modulus; it should be 27776.
Can you explain the process how the this code was generated? Is Cpython code converted using emscripten? if so can you please explain the steps.
In order to use empythoned in my project, is it enough to load dist/worker.js
in my html and which will load dist/python.opt.js
?
Hello,
I seem to be getting some errors when trying to build. I'm invoking the build script by running "./build". I've set the proper variables located at the top of both "build" and ccproxy.py. I am receiving the following error output after the build script runs for a little bit: (~10 seconds or so)
Potential incompatible plugin version. GCC: 4.6 (20120301). Expected: 4.6 (20120301)
Defines 'dragonegg_disable_version_check' as env variable to remove this warning
Please note that unexpected errors might occur.
../ccproxy.py -DNDEBUG -g -O3 -Wall -Wstrict-prototypes Parser/acceler.o Parser/grammar1.o Parser/listnode.o Parser/node.o Parser/parser.o Parser/parsetok.o Parser/bitset.o Parser/metagrammar.o Parser/firstsets.o Parser/grammar.o Parser/pgen.o Objects/obmalloc.o Python/mysnprintf.o Python/pyctype.o Parser/tokenizer_pgen.o Parser/printgrammar.o Parser/pgenmain.o -ldl -lutil -o Parser/pgen
/usr/bin/llvm-link: Parser/acceler.o:1:1: error: expected top-level entity
�ELFH4(U���(��E�E�E�E�H��U�M��!�E�$�M�L$�<�E���M�M�E�E�M�����E�M�}ˋE��@��(]Ív��'U���(�E
��M�E�E�M�M�E��M�Q�E�U��$�E�$�M�L$���E���M���E�M�E�M�U�9J
�M�E��ȃ�(]�f�U���8��E�E�E�E��@�H��U�M��f��M�Q�E�U��0�E�xt�E�H�
$������E��@�M܃����M�E�E�M�U�9J
�M܉E����E���M؉M�E�E�M�����E�M�}���8]Ð��&U��SWV���E
��M�E�E�M�E�M�E��U��B�4����M�|6�E�
���t�E�
��M���E܋E܉$������E���E؋E��E�uO���$�5�$�D$�D$�t$
�MЉU��������$�MȉE��������E���E��
��U��
^
/usr/bin/llvm-link: error loading file 'Parser/acceler.o'
/usr/bin/llc: Parser/pgen: Could not open input file: No such file or directory
gcc-4.6: error: Parser/pgen.tmp.o: No such file or directory
gcc-4.6: fatal error: no input files
compilation terminated.
Traceback (most recent call last):
File "../ccproxy.py", line 100, in
os.unlink(target + '.tmp.o')
OSError: [Errno 2] No such file or directory: 'Parser/pgen.tmp.o'
make: *** [Parser/pgen] Error 1
Any idea as to what might be occuring? I'm trying to compile Python in Javascript with the basic configuration for now. Once I get this working, I plan to add/enable the Python SSL module and hopefully compile/convert that too.
Thanks,
Acejam
I get an
Internal error: ReferenceError: _select is not defined
when trying to invoke
time.sleep(10)
import urllib
response = urllib.urlopen("http://python.org")
print response
Code was evaluated using this app yields
Uncaught ReferenceError: _getaddrinfo is not defined
in JS console.
While trying same code as chrome extension https://github.com/kracekumar/offline-python
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python2.7/urllib.py", line 26, in <module>
import socket
File "/lib/python2.7/socket.py", line 47, in <module>
import _socket
ImportError: Could not evaluate dynamic lib: //lib/python2.7/_socket.so
print 0xf8ef380d6/0x0710c7f29
print 0xf8ef380d/0x0710c7f2
I would expect both lines to print '35'
however, on repl.it with the empythoned engine, the first line prints '34'
In the compiled code the run
function is too big for iOS and should be split into several functions.
To recreate:
>>> import math
>>> math.log10(100)
Internal error: ReferenceError: _llvm_log10_f64 is not defined
All of the hashlib functions that I tried gave incorrect output.
For example, compare this stdlib example code:
>>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest()
'a4337bc45a8fc544c03f52dc550cd6e1e87021bc896588bd79e901e2'
against the result on repl.it:
>>> hashlib.sha224("Nobody inspects the spammish repetition").hexdigest()
'03143f9f164335fafd05051e0163df081007ba1208d6f9eb4fd3f6fe'
I'm running this example script on Empythoned Demo
import urllib
print urllib.urlopen("http://ipv4.icanhazip.com/").read()
I got an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python2.7/urllib.py", line 26, in <module>
import socket
File "/lib/python2.7/socket.py", line 47, in <module>
import _socket
ImportError: No module named _socket
So, I need to make a HTTP request inside python script. Is there any way?
It looks like only simple but not advanced opts are used. However advanced opts usually give a 50%-100% speedup (+smaller code).
Is there a reason for not using advanced opts? Do you need any help with something there?
Firefox and Chrome have disabled ArrayBuffer responses in sync XHRs in their nightly builds, example error:
[10:02:13.078] Use of XMLHttpRequest's responseType attribute is no longer supported in the synchronous mode in window context. @ http://repl.it/jsrepl/sandbox.html
[10:02:13.095] uncaught exception: [Exception... "A parameter or an operation is not supported by the underlying object" code: "15" nsresult: "0x8053000f (NS_ERROR_DOM_INVALID_ACCESS_ERR)" location: "http://repl.it/jsrepl/sandbox.js Line: 322"]
Sync XHRs work without ArrayBuffers, but the better solution is probably to put the compiled code in a worker, where ArrayBuffer still works.
Its not that hard, here is a complete guide ;)
import antigravity
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/lib/python2.7/antigravity.py", line 2, in <module>
import webbrowser
File "/lib/python2.7/webbrowser.py", line 9, in <module>
import subprocess
File "/lib/python2.7/subprocess.py", line 429, in <module>
import select
ImportError: No module named select
This happens because the module tries to import the webbrowser
module.
One way to go with it is to print http://xkcd.com/353/
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.