11# GraalPy Troubleshooting
22
3- [[ TOC]]
4-
53## GraalPy Embedding
64
7- #### VirtualFileSystem cannot load a file
5+ ### VirtualFileSystem cannot load a file
6+
87There are situations where a file cannot be loaded even though it is part of the Virtual Filesystem resources.
9- GraalPy tries to prevent such situations by automatically [ extracting] ( Embedding-Build-Tools.md#extracting-files-from-virtual-filesystem )
8+ GraalPy tries to prevent such situations by automatically [ extracting] ( Embedding-Build-Tools.md#extracting-files-from-virtual-filesystem )
109some well known files to the real filesystem, but if you see an error like:
10+
11+ ``` bash
12+ ImportError: cannot load /graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so:
13+ NFIUnsatisfiedLinkError: dlopen(/graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so, 0x0002):
1114```
12- ImportError: cannot load /graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so:
13- NFIUnsatisfiedLinkError: dlopen(/graalpy_vfs/venv/lib/python3.11/site-packages/_cffi_backend.graalpy250dev09433ef706-311-native-aarch64-darwin.so, 0x0002):
14- ```
15+
1516then the default behavior did not work as intended.
1617
1718Depending on how you [ deploy Python resources] ( Embedding-Build-Tools.md#deployment ) in your application, you can try one of the following:
1819- if you need to package resources within your Jar or Native Image executable:
19- - if the problematic file is not one of the following types: ` .so ` , ` .dylib ` , ` .pyd ` , ` .dll ` , or ` .ttf ` , which are extracted to
20- the real filesystem by default, you can simply attempt to add it to the extraction filter using:
21- ``` java
20+ - if the problematic file is not one of the following types: ` .so ` , ` .dylib ` , ` .pyd ` , ` .dll ` , or ` .ttf ` , which are extracted to
21+ the real filesystem by default, you can simply attempt to add it to the extraction filter using:
22+
23+ ``` java
2224 VirtualFileSystem . Builder . extractFilter(filter);
2325 ```
26+
2427 - if the previous does not help, it is also possible to extract all Python resources into a user-defined directory before creating a GraalPy
2528 context, and then configure the context to use that directory:
29+
2630 ``` java
2731 // extract the Python resources from the jar or native image into a given directory
2832 GraalPyResources . extractVirtualFileSystemResources(VirtualFileSystem . create(), externalResourceDirectoryPath);
2933 // create a GraalPy context configured with an external Python resource directory
3034 Context context = GraalPyResources . contextBuilder(externalResourceDirectoryPath). build();
3135 ```
32- - or if you're able to ship resources in a separate directory, you have to set the ` externalDirectory ` tag in
33- [ Maven] ( Embedding-Build-Tools.md#graalpy-maven-plugin ) or ` externalDirectory ` field in [ Gradle] ( Embedding-Build-Tools.md#graalpy-gradle-plugin )
34- and also configure the GraalPy context to use that directory as well:
36+ - or if you're able to ship resources in a separate directory, you have to set the ` externalDirectory ` tag in
37+ [ Maven] ( Embedding-Build-Tools.md#graalpy-maven-plugin ) or ` externalDirectory ` field in [ Gradle] ( Embedding-Build-Tools.md#graalpy-gradle-plugin )
38+ and also configure the GraalPy context to use that directory as well:
39+
3540 ``` java
3641 // create a Context configured with an external Python resource directory
3742 Context context = GraalPyResources . contextBuilder(externalResourceDirectoryPath). build();
3843 ```
44+
3945 Please ** note** , that if switching from Virtual FileSystem to an external directory, also all ** user files** from the previous
4046 Virtual FileSystem resource root have to be moved into that directory as well.
4147
@@ -44,35 +50,36 @@ For more details about the Python resources in GraalPy Embedding please refer to
4450For more details about GraalPy context and Virtual FileSystem configuration please refer to [ GraalPyResources] ( https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java ) and
4551[ VirtualFileSystem] ( https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/VirtualFileSystem.java ) javadoc.
4652
47- #### Issues with GraalPy 'java' posix backend
48- The Virtual FileSystem is built on the Truffle filesystem and relies on the GraalPy Java POSIX backend.
49- Unfortunately, certain Python packages bypass Python's I/O and directly access files through their
53+ ### Issues with GraalPy 'java' posix backend
54+
55+ The Virtual FileSystem is built on the Truffle filesystem and relies on the GraalPy Java POSIX backend.
56+ Unfortunately, certain Python packages bypass Python's I/O and directly access files through their
5057native extensions. If you encounter an error like:
5158```
5259NotImplementedError: 'PyObject_AsFileDescriptor' not supported when using 'java' posix backend
5360```
5461then you have to override the default ` java ` GraalPy backend option byt setting the ` native ` POSIX backend
55- and completely omit the Virtual FileSystem at runtime.
62+ and completely omit the Virtual FileSystem at runtime.
5663
57- Depending on how you [ deploy Python resources] ( Embedding-Build-Tools.md#deployment ) in your application,
64+ Depending on how you [ deploy Python resources] ( Embedding-Build-Tools.md#deployment ) in your application,
5865you can do one of the following:
5966
6067- if you need to package Python resources within your Jar or Native Image executable, then:
6168 ``` java
6269 // extract the Python resources from the jar or native image into a given directory
6370 GraalPyResources . extractVirtualFileSystemResources(VirtualFileSystem . create(), externalResourceDirectoryPath);
64- // create a Context.Builder configured with an external python resource directory
71+ // create a Context.Builder configured with an external python resource directory
6572 Builder builder = GraalPyResources . contextBuilder(externalResourceDirectoryPath);
6673 // override the python.PosixModuleBackend option with "native"
6774 builder. option(" python.PosixModuleBackend" , " native" );
6875 // create a context
6976 Context context = builder. build();
7077 ```
71- - or if you're able to ship Python resources in a separate directory, you have to set the ` externalDirectory ` tag in
78+ - or if you're able to ship Python resources in a separate directory, you have to set the ` externalDirectory ` tag in
7279 [ Maven] ( Embedding-Build-Tools.md#graalpy-maven-plugin ) or ` externalDirectory ` field in [ Gradle] ( Embedding-Build-Tools.md#graalpy-gradle-plugin )
7380 and configure the GraalPy context accordingly:
7481 ``` java
75- // create a Context.Builder configured with an external python resource directory
82+ // create a Context.Builder configured with an external python resource directory
7683 Builder builder = GraalPyResources . contextBuilder(externalResourceDirectoryPath);
7784 // override the python.PosixModuleBackend option with "native"
7885 builder. option(" python.PosixModuleBackend" , " native" );
@@ -87,55 +94,65 @@ For more details about the Python resources in GraalPy Embedding please refer to
8794For more details about GraalPy context and Virtual FileSystem configuration please refer to [ GraalPyResources] ( https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/GraalPyResources.java ) and
8895[ VirtualFileSystem] ( https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/VirtualFileSystem.java ) javadoc.
8996
90- ### Maven and Gradle applications
97+ ### ImportError reports "unknown location"
9198
92- #### ImportError reports "unknown location"
93- A possible cause of an ` ImportError ` ending with ` (unknown location) ` when running a GraalPy Java Embedding project might be
99+ A possible cause of an ` ImportError ` ending with ` (unknown location) ` when running a GraalPy Java Embedding project might be
94100that an embedded Python package was built for a different operating system. If you see an error like the following:
95- ```
101+
102+ ``` bash
96103ImportError: cannot import name ' exceptions' from ' cryptography.hazmat.bindings._rust' (unknown location)
97- ```
104+ ```
105+
98106You probably need to rebuild your project on the correct operating system before running it.
99107
100- #### GraalVM JDK Compatibility
101- To enable runtime compilation when running GraalPy from a Maven or Gradle application,
102- you must use versions of GraalPy and the Polyglot API dependencies that are compatible
108+ ### GraalVM JDK Compatibility
109+
110+ To enable runtime compilation when running GraalPy from a Maven or Gradle application,
111+ you must use versions of GraalPy and the Polyglot API dependencies that are compatible
103112with the specified GraalVM JDK version. If you see errors like the following:
104113
105- ```
114+ ``` bash
106115Your Java runtime ' 23.0.1+11-jvmci-b01' with compiler version ' 24.1.1' is incompatible with polyglot version ' 24.1.0' .
107116```
108- You need to keep the versions of your GraalPy and Polyglot dependencies according to the error message,
109- so either upgrade the version of your JDK or your polyglot and GraalPy dependencies.
110117
111- Note, this can also apply to cases when your dependencies are transitively pulled in by another artifact,
118+ You need to keep the versions of your GraalPy and Polyglot dependencies according to the error message,
119+ so either upgrade the version of your JDK or your polyglot and GraalPy dependencies.
120+
121+ Note, this can also apply to cases when your dependencies are transitively pulled in by another artifact,
112122e.g. micronaut-graalpy.
113123
114- #### The following artifacts could not be resolved: org.graalvm.python: python-language-enterprise
124+ ### The following artifacts could not be resolved: org.graalvm.python: python-language-enterprise
125+
115126` python-language-enterprise ` was discontinued, use ` org.graalvm.polyglot:python ` instead.
116127
117- #### Issues with Meson build system when installing Python packages on OSX with Maven or Gradle GraalPy plugin
128+ ### Issues with Meson build system when installing Python packages on OSX with Maven or Gradle GraalPy plugin
129+
118130Errors like the following:
119- ```
131+
132+ ``` bash
120133../meson.build:1:0: ERROR: Failed running ' cython' , binary or interpreter not executable.
121134```
122135
123- could be caused by the GraalPy launcher used internally by the Maven or Gradle GraalPy plugin
124- for installing Python packages. Currently, there is no straightforward solution. However,
125- a workaround is to set the Java system property graalpy.vfs.venvLauncher to a launcher from
136+ could be caused by the GraalPy launcher used internally by the Maven or Gradle GraalPy plugin
137+ for installing Python packages. Currently, there is no straightforward solution. However,
138+ a workaround is to set the Java system property graalpy.vfs.venvLauncher to a launcher from
126139a downloaded [ GraalPy] ( https://github.com/oracle/graalpython/releases/ ) distribution with a version
127140matching the GraalPy Maven artifacts version.
128141
129142e.g.
130- ```
143+
144+ ``` bash
131145mvn package -Dgraalpy.vfs.venvLauncher={graalpy_directroy}/Contents/Home/bin/graalpy
132146```
133147
134- #### No language and polyglot implementation was found on the module-path.
148+ ### No language and polyglot implementation was found on the module-path.
149+
135150If you see an error like:
151+
152+ ``` bash
153+ java.lang.IllegalStateException: No language and polyglot implementation was found on the module-path. Make sure at last one language is added to the module-path.
136154```
137- java.lang.IllegalStateException: No language and polyglot implementation was found on the module-path. Make sure at last one language is added to the module-path.
138- ```
139- you are probably missing the python langauge dependency in your Maven of Gradle configuration file.
155+
156+ you are probably missing the python langauge dependency in your Maven of Gradle configuration file.
140157You need to add either ` org.graalvm.polyglot:python ` or ` org.graalvm.polyglot:python-community ` to your dependencies.
141158
0 commit comments