1
1
# GraalPy Troubleshooting
2
2
3
- [[ TOC]]
4
-
5
3
## GraalPy Embedding
6
4
7
- #### VirtualFileSystem cannot load a file
5
+ ### VirtualFileSystem cannot load a file
6
+
8
7
There 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 )
10
9
some 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):
11
14
```
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
+
15
16
then the default behavior did not work as intended.
16
17
17
18
Depending on how you [ deploy Python resources] ( Embedding-Build-Tools.md#deployment ) in your application, you can try one of the following:
18
19
- 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
22
24
VirtualFileSystem . Builder . extractFilter(filter);
23
25
```
26
+
24
27
- if the previous does not help, it is also possible to extract all Python resources into a user-defined directory before creating a GraalPy
25
28
context, and then configure the context to use that directory:
29
+
26
30
``` java
27
31
// extract the Python resources from the jar or native image into a given directory
28
32
GraalPyResources . extractVirtualFileSystemResources(VirtualFileSystem . create(), externalResourceDirectoryPath);
29
33
// create a GraalPy context configured with an external Python resource directory
30
34
Context context = GraalPyResources . contextBuilder(externalResourceDirectoryPath). build();
31
35
```
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
+
35
40
``` java
36
41
// create a Context configured with an external Python resource directory
37
42
Context context = GraalPyResources . contextBuilder(externalResourceDirectoryPath). build();
38
43
```
44
+
39
45
Please ** note** , that if switching from Virtual FileSystem to an external directory, also all ** user files** from the previous
40
46
Virtual FileSystem resource root have to be moved into that directory as well.
41
47
@@ -44,35 +50,36 @@ For more details about the Python resources in GraalPy Embedding please refer to
44
50
For 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
45
51
[ VirtualFileSystem] ( https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/VirtualFileSystem.java ) javadoc.
46
52
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
50
57
native extensions. If you encounter an error like:
51
58
```
52
59
NotImplementedError: 'PyObject_AsFileDescriptor' not supported when using 'java' posix backend
53
60
```
54
61
then 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.
56
63
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,
58
65
you can do one of the following:
59
66
60
67
- if you need to package Python resources within your Jar or Native Image executable, then:
61
68
``` java
62
69
// extract the Python resources from the jar or native image into a given directory
63
70
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
65
72
Builder builder = GraalPyResources . contextBuilder(externalResourceDirectoryPath);
66
73
// override the python.PosixModuleBackend option with "native"
67
74
builder. option(" python.PosixModuleBackend" , " native" );
68
75
// create a context
69
76
Context context = builder. build();
70
77
```
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
72
79
[ Maven] ( Embedding-Build-Tools.md#graalpy-maven-plugin ) or ` externalDirectory ` field in [ Gradle] ( Embedding-Build-Tools.md#graalpy-gradle-plugin )
73
80
and configure the GraalPy context accordingly:
74
81
``` 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
76
83
Builder builder = GraalPyResources . contextBuilder(externalResourceDirectoryPath);
77
84
// override the python.PosixModuleBackend option with "native"
78
85
builder. option(" python.PosixModuleBackend" , " native" );
@@ -87,55 +94,65 @@ For more details about the Python resources in GraalPy Embedding please refer to
87
94
For 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
88
95
[ VirtualFileSystem] ( https://github.com/oracle/graalpython/blob/master/graalpython/org.graalvm.python.embedding/src/org/graalvm/python/embedding/VirtualFileSystem.java ) javadoc.
89
96
90
- ### Maven and Gradle applications
97
+ ### ImportError reports "unknown location"
91
98
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
94
100
that an embedded Python package was built for a different operating system. If you see an error like the following:
95
- ```
101
+
102
+ ``` bash
96
103
ImportError: cannot import name ' exceptions' from ' cryptography.hazmat.bindings._rust' (unknown location)
97
- ```
104
+ ```
105
+
98
106
You probably need to rebuild your project on the correct operating system before running it.
99
107
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
103
112
with the specified GraalVM JDK version. If you see errors like the following:
104
113
105
- ```
114
+ ``` bash
106
115
Your Java runtime ' 23.0.1+11-jvmci-b01' with compiler version ' 24.1.1' is incompatible with polyglot version ' 24.1.0' .
107
116
```
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.
110
117
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,
112
122
e.g. micronaut-graalpy.
113
123
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
+
115
126
` python-language-enterprise ` was discontinued, use ` org.graalvm.polyglot:python ` instead.
116
127
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
+
118
130
Errors like the following:
119
- ```
131
+
132
+ ``` bash
120
133
../meson.build:1:0: ERROR: Failed running ' cython' , binary or interpreter not executable.
121
134
```
122
135
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
126
139
a downloaded [ GraalPy] ( https://github.com/oracle/graalpython/releases/ ) distribution with a version
127
140
matching the GraalPy Maven artifacts version.
128
141
129
142
e.g.
130
- ```
143
+
144
+ ``` bash
131
145
mvn package -Dgraalpy.vfs.venvLauncher={graalpy_directroy}/Contents/Home/bin/graalpy
132
146
```
133
147
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
+
135
150
If 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.
136
154
```
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.
140
157
You need to add either ` org.graalvm.polyglot:python ` or ` org.graalvm.polyglot:python-community ` to your dependencies.
141
158
0 commit comments