Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Can't import file via pyscript_config.toml using [files], ModuleNotFoundError #1869

Open
1 task done
TheRealSamChaney opened this issue Sep 16, 2024 · 0 comments
Open
1 task done
Labels
bug Something isn't working

Comments

@TheRealSamChaney
Copy link

What happened?

I'm trying to configure pyscript-react using a pyscript_config.toml file which imports a python library file (geometry_generator.py) using [files]. It seems to load the config file but when I try to import from geometry_generator I get "ModuleNotFoundError: No module named 'geometry_generator'"

I have tried every different combination of file location and paths I can think of but I have not been able to load the geometry_generator file successfully. Currently it's located in public.

Below is the contents of my pyscript_config.toml file:

packages = ["svgwrite"]

[files]
"../geometry_generator.py" = "./geometry_generator.py"

Here is the relevant content of the page.tsx file where I use pyscript-react:

<PyScriptProvider>
      <PyConfig
        source="/pyscript_config.toml"
      />
       <PyScript>
          {`
          from geometry_generator import *
          `}
      </PyScript>  
</PyScriptProvider>

Version

0.0.4

Relevant log output

[pyexec] Python exception:
Traceback (most recent call last):
  File "/home/pyodide/pyscript/_internal.py", line 104, in run_pyscript
    result = eval_code(code, globals=__main__.__dict__)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python311.zip/_pyodide/_base.py", line 468, in eval_code
    .run(globals, locals)
     ^^^^^^^^^^^^^^^^^^^^
  File "/lib/python311.zip/_pyodide/_base.py", line 310, in run
    coroutine = eval(self.code, globals, locals)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<exec>", line 1, in <module>
ModuleNotFoundError: No module named 'geometry_generator'
app-index.tsx:25:19
    error app-index.tsx:25
    error hydration-error-info.ts:72
    fn logger.ts:50
    displayPyException pyexec.ts:64
    pyExec pyexec.ts:36
    init pyscript.ts:37
    connectedCallback pyscript.ts:81
    executeScripts main.ts:430
    afterInterpreterLoad main.ts:279
    loadInterpreter main.ts:254
    _realMain main.ts:142
    main main.ts:105
    pyscript main.ts:457
    <anonymous> pyscript.js:29204

How to reproduce?

Create Next.js project (using TypeScript), install pyscript-react and its dependencies, create a pyscript_config.toml file and include a python library file using [files] in the config file and try to import from that python library file in the python script within PyScript tags

Code of Conduct

  • I agree to follow this project's Code of Conduct
@TheRealSamChaney TheRealSamChaney added the bug Something isn't working label Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant