Import PSAW brython

牧云@^-^@ 提交于 2019-12-02 07:36:06

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/58460131/import-psaw-brython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!