oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.17k stars 101 forks source link

Simple Python "import csv" failed to executed #364

Open qidian99 opened 8 months ago

qidian99 commented 8 months ago

Describe GraalVM and your environment :

mac aarch64 jdk21 23.1.0

Have you verified this issue still happens when using the latest snapshot? Yes

Describe the issue ModuleNotFoundError: No module named 'csv' at (Unknown) at org.graalvm.polyglot/org.graalvm.polyglot.Context.eval(Context.java:428)

Code snippet or code repository that reproduces the issue

            String venvExePath = Paths.get("testenv", "bin", "graalpy").toString();

            Context context = Context.newBuilder().allowAllAccess(true).option("python.Executable", venvExePath).build();
            context.eval("python", "import site");
            context.eval("python", "import csv"); // <--- error here

Steps to reproduce the issue

Expected behavior No error should occur and in the python code it will have access to csv.Sniffer etc.

Additional context Add any other context about the problem here. Specially important are stack traces or log output. Feel free to link to gists or to screenshots if necesary

Details ``` ModuleNotFoundError: No module named 'csv' at (Unknown) at org.graalvm.polyglot/org.graalvm.polyglot.Context.eval(Context.java:428) ```
timfel commented 8 months ago

Do you use Python via the maven dependencies? csv is in the standard library and should be available when depending on org.graalvm.py/python-resources (either directly or indirectly via the org.graalvm.polyglot/python dependency). You will need file system access also, since the python-resources are automatically extracted to the user's cache folder on startup.