Using PyScript: How to use "pip install"?
P粉189606269
P粉189606269 2024-01-04 19:51:41
0
1
372

I'm trying to write an html file that can contact chat gpt.

This is the beginning of the code:

<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>

<py-script>
import openai
</py-script>

But when I run it it says:

ModuleNotFoundError: No module named 'openai'

Any idea how to install it on an html file?

I'm trying to figure out how to use:

pip install openai,

But I don't know how to run bash commands from python.

I also tried using but it didn't have any effect on the code.

It might be blocked by my proxy, I'm a beginner in Python, so please explain it briefly.

P粉189606269
P粉189606269

reply all(1)
P粉373596828

According to the Getting Started Document, use the tag to import external modules:

<py-config>
    packages = ["openai"]
</py-config>

But, even so, this code:

<html>
<head>
    <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
    <script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
    <py-config>
        packages = ["openai"]
    </py-config>
    <py-script>
        import openai
    </py-script>
</body>
</html>

gives the following error message:

The Pyodide link above is as follows:

openai requires requests, so until sockets are implemented in Pyodide (which PyScript uses) you won't be able to use openai module or many other modules in PyScript.

However, it is possible to make asynchronous HTTP requests using PyScript/Pyodide: see the

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!