I am trying to import the PSAW library in python using Brython, I have the following code:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>
</head>
<body onload="brython()">
<script type="text/python">
from browser import document
document <= "Hello world !"
</script>
</body>
</html>
This works correctly, however when i add PSAW like so:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="brython.js"></script>
<script type="text/javascript" src="brython_stdlib.js"></script>
</head>
<body onload="brython()">
<script type="text/python">
from browser import document
import PushshiftAPI
document <= "Hello world !"
</script>
</body>
</html>
I get the following error in chrome:
GET http://localhost:8000/requests.py?v=1571453029466 404 (File not found)
Error 404 means that Python module requests was not found at url http://localhost:8000/requests.py
GET http://localhost:8000/requests/__init__.py?v=1571453029904 404 (File not found)
Error 404 means that Python module requests was not found at url http://localhost:8000/requests/__init__.py
GET http://localhost:8000/Lib/site-packages/requests.py?v=1571453030155 404 (File not found)
Error 404 means that Python module requests was not found at url http://localhost:8000/Lib/site-packages/requests.py
GET http://localhost:8000/Lib/site-packages/requests/__init__.py?v=1571453030212 404 (File not found)
Error 404 means that Python module requests was not found at url http://localhost:8000/Lib/site-packages/requests/__init__.py
Traceback (most recent call last):
ImportError: No module named requests
I think it means it requires other modules with Brython can't find but I'm not sure how to identify what modules are needed and how to correctly add them. Here is my file directory:
Update:
I have installed PSAW and PRAW in a virtual environment and copied all packages into the directory like so:
However I still receive the following issue when trying to import requests
Traceback (most recent call last):
AttributeError: 'NoneType' object has no attribute 'load_module'
Uncaught Error
at Object._b_.AttributeError.$factory (eval at $make_exc (brython.js:7609), <anonymous>:41:354)
at attr_error (brython.js:6587)
at Object.$B.$getattr (brython.js:6701)
at Object.import_hooks (brython.js:13361)
at Object.$B.$__import__ (brython.js:9097)
at __import__ (brython.js:6761)
at _import_module179 (eval at run_py (brython.js:8906), <anonymous>:238:45)
at _resolve183 (eval at run_py (brython.js:8906), <anonymous>:539:84)
at method (brython.js:5321)
at load_module195 (eval at run_py (brython.js:8906), <anonymous>:1377:148)
Any idea what's happening here?
A 404 error means "file not found." Your browser is trying to access a library located at "http://localhost:8000/requests/__init__.py?v=1571453029904" (and the other locations in your traceback) but can't find it. Try visiting the URL in your browser. Does it return a file? If you can't find a file there, Brython won't be able to either. Try rearranging your filesystem until your can visit the .py file in a browser