-
Notifications
You must be signed in to change notification settings - Fork 1.5k
-
Hi I am using pyscript along with an html page I am creating.
In the html page I inserted the pyscirpt with src="./py/xx.py".
It tells me it can't find the pandas package even though the module is installed.
I saw that you have to use py-config:
"numpy", "pandas"
and I try
{ "packages": ["numpy", "matplotlib"] }
as stated in the documentation, but honestly I tried it several ways but it always gives me error. From the documentation I couldn't figure out how I solve it, also because all the examples are inside the same html file.
Could you guys tell me where I'm going wrong?
Thank you for your help
Error:
pyscript.js:1933 (PY1000): The config supplied: { "packages": ["numpy", "matplotlib"] } is an invalid TOML and cannot be parsed: UserError: (PY1000): The config supplied: { "packages": ["numpy", "matplotlib"] } is an invalid TOML and cannot be parsed
PS
Please put some examples by calling libraries from external files.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 9 replies
-
Hello @A13cx thank you for raising this issue. py-config
is using toml by default, you have two options:
Use toml format:
<py-config> packages = ["numpy", "matplotlib"] </py-config>
Specify json format:
<py-config type="json"> { "packages": ["numpy", "matplotlib"] } </py-config>
Here's the link to the py-config docs for reference https://docs.pyscript.net/latest/reference/elements/py-config.html
Please let us know if this solves your problem 😄
Beta Was this translation helpful? Give feedback.
All reactions
-
logger.ts:39 [pyscript/pyodide] PythonError: Traceback (most recent call last):
File "/lib/python3.10/asyncio/futures.py", line 201, in result
raise self._exception
File "/lib/python3.10/asyncio/tasks.py", line 234, in __step
result = coro.throw(exc)
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 548, in install
await transaction.gather_requirements(requirements)
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 305, in gather_requirements
await gather(*requirement_promises)
File "/lib/python3.10/asyncio/futures.py", line 284, in await
yield self # This tells Task to wait for completion.
File "/lib/python3.10/asyncio/tasks.py", line 304, in __wakeup
future.result()
File "/lib/python3.10/asyncio/futures.py", line 201, in result
raise self._exception
File "/lib/python3.10/asyncio/tasks.py", line 232, in __step
result = coro.send(None)
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 312, in add_requirement
return await self.add_requirement_inner(Requirement(req))
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 407, in add_requirement_inner
wheel = find_wheel(metadata, req)
File "/lib/python3.10/site-packages/micropip/_micropip.py", line 275, in find_wheel
raise ValueError(
ValueError: Can't find a pure Python 3 wheel for 'metatrader5'.
See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel
You can use micropip.install(..., keep_going=True)
to get a list of all packages with missing wheels.
fn @ logger.ts:39
installPackage @ pyodide.ts:87
await in installPackage (asinc)
setupVirtualEnv @ main.ts:192
await in setupVirtualEnv (asinc)
afterRuntimeLoad @ main.ts:147
await in afterRuntimeLoad (asinc)
(anonimo) @ main.ts:130
load (asinc)
loadRuntime @ main.ts:129
_realMain @ main.ts:89
main @ main.ts:68
(anonimo) @ main.ts:289
(anonimo) @ main.ts:291
exceptions.ts:51 (PY1001): Unable to install package(s) 'numpy,matplotlib,MetaTrader5'. Reason: Can't find a pure Python 3 Wheel for package(s) 'numpy,matplotlib,MetaTrader5'. See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel for more information.
Beta Was this translation helpful? Give feedback.
All reactions
-
This is a different problem now 😄
The library MetaTrader5
needs to have either a pure python 3 wheel available in pypi or it needs to be converted to be able to run in wasm.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi, look I tried even without the Metratder and it doesn't work
Beta Was this translation helpful? Give feedback.
All reactions
-
besides if you see, in my initial request I had inserted the json, in the same way as you wrote it and it doesn't work
Beta Was this translation helpful? Give feedback.
All reactions
-
this is the error it gives with the following configuration:
<py-config type="json"> { "packages": ["numpy", "matplotlib"] } </py-config>
<py-script output="dv_info" src="./py/codice.py"></py-script>
<div id="dv_info"></div>
pyscript.js:1826 [pyexec] Python exception:
Traceback (most recent call last):
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 435, in eval_code
.run(globals, locals)
File "/lib/python3.10/site-packages/_pyodide/_base.py", line 304, in run
coroutine = eval(self.code, globals, locals)
File "", line 1, in
ModuleNotFoundError: No module named 'pandas'
Beta Was this translation helpful? Give feedback.
All reactions
-
<py-config type="json"> { "packages": ["numpy", "matplotlib"] } </py-config> <py-script output="dv_info" src="./py/codice.py"></py-script> <div id="dv_info"></div>
What happens if you add pandas
to the list of packages in the py-config?
Beta Was this translation helpful? Give feedback.
All reactions
-
if I knew, I wouldn't be here
Beta Was this translation helpful? Give feedback.
All reactions
-
I should have worded my response more clearly better. The error message specifies "No module named pandas", so I'd recommend adding pandas
to this list of installed packages by using { "packages": ["numpy", "matplotlib", "pandas"] }
Beta Was this translation helpful? Give feedback.
All reactions
-
all the libreiries are installed I've been working there for a long time, so I don't know what to say
Beta Was this translation helpful? Give feedback.
All reactions
-
Hello again, I just tested this locally, here's a full working code example for both json and toml format using numpy and matplotlib.
JSON
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <title>Config</title> <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" /> <script defer src="https://pyscript.net/latest/pyscript.js"></script> </head> <body> <py-config type="json"> { "packages": ["numpy", "matplotlib"] } </py-config> <py-script> import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 20, 100) plt.plot(x, np.sin(x)) display(plt) </py-script> </body> </html>
TOML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width,initial-scale=1" /> <title>Config</title> <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 = ["numpy", "matplotlib"] </py-config> <py-script> import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 20, 100) plt.plot(x, np.sin(x)) display(plt) </py-script> </body> </html>
Now, from the extra piece of code that you shared, I noticed that you are passing a python file to py-script
tag.
Since you are getting a ModuleNotFound error, its likely that you are trying to import other libraries other than numpy and matplotlib. You will have to specify any extra dependencies that you may be using on your file.
Beta Was this translation helpful? Give feedback.
All reactions
-
OK, guys, thanks for the help but it gives me more problems.
I think I will give up pyscript.... especially that if for every thing I have to ask means wasting a lot of time, I'll see if I can solve it some other way.
Thanks and bye
Beta Was this translation helpful? Give feedback.