You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`byte`, `short`, `int` , `long`|`int`, any object that has an `__int__` method |
71
-
|`float`, `double`|`float`, any object that has a `__float__` method |
72
-
|`char`|`str` of length 1 |
73
-
|`java.lang.String`|`str`|
74
-
|`byte[]`|`bytes`, `bytearray`, wrapped Java array, Python list with only the appropriate types |
75
-
| Java arrays | Wrapped Java array or Python list with only the appropriate types |
76
-
| Java objects | Wrapped Java object of the appropriate type |
77
-
|`java.lang.Object`| Any object |
78
-
79
-
### Special Jython Modules
80
-
Any of the special Jython modules are not available. For example, the `jarray`
81
-
module on Jython allows construction of primitive Java arrays. This can be
82
-
achieved as follows on GraalPython:
57
+
## Java-to-Python Types: Automatic Conversion
58
+
59
+
Method overloads are resolved by matching the Python arguments in a best-effort manner to the available parameter types.
60
+
This also happens during when data conversion.
61
+
The goal here is to make using Java from Python as smooth as possible.
62
+
The matching allowed here is similar to Jython, but GraalVM's Python implementation uses a more dynamic approach to matching — Python types emulating `int` or `float` are also converted to the appropriate Java types.
63
+
This allows, for example, to use Pandas frames as `double[][]` or NumPy array elements as `int[]` when the elements fit into those Java primitive types.
The other way to use Jython is to embed it into Java applications. Where above,
177
-
Graal Python offered some measure of compatibility with existing Jython code, we
178
-
do not offer any in this case. Existing code using Jython depends directly on
179
-
the Jython package (for example, in the Maven configuration), because the Java
180
-
code has references to Jython internal classes such as `PythonInterpreter`.
181
-
182
-
For Graal Python, no dependency other than on the [GraalVM SDK](https://mvnrepository.com/artifact/org.graalvm.sdk/graal-sdk) is
183
-
required. There are no APIs particular to Python that are exposed, and
184
-
everything is done through the GraalVM API. Important to know is that as long as
185
-
your application is executed on a GraalVM with the Python language installed,
186
-
you can embed Python in your programs. For more detail, refer to the [Embed Languages](https://www.graalvm.org/reference-manual/embed-languages/) reference.
172
+
The other way to use Jython is to embed it into Java applications.
173
+
Where above GraalVM's Python runtime offered some measure of compatibility with existing Jython code, nothing is offered in this case.
174
+
Existing code using Jython depends directly on the Jython package (for example, in the Maven configuration), because the Java code has references to Jython internal classes such as `PythonInterpreter`.
175
+
176
+
For GraalVM's Python runtime, no dependency other than on the [GraalVM SDK](https://mvnrepository.com/artifact/org.graalvm.sdk/graal-sdk) is required.
177
+
There are no APIs particular to Python that are exposed, and everything is done through the GraalVM API.
178
+
179
+
It is important to note that as long as your application is executed on GraalVM with the Python language installed,
180
+
you can embed Python in your programs.
181
+
For more details, refer to the [Embed Languages](https://www.graalvm.org/docs/reference-manual/embed-languages/#Function_Python) guide.
The best way of using the GraalVM implementation of Python is out of a virtual
5
-
environment. This generates wrapper scripts and makes the implementation usable
6
-
from shell as standard Python interpreter. To do so execute the following from a
7
-
GraalVM installation:
3
+
## Create a Virtual Environment
8
4
5
+
The best way of using GraalVM's Python runtime is from a virtual environment.
6
+
This generates wrapper scripts and makes the implementation usable from shell as the standard Python interpreter.
7
+
To create the virtual environment with GraalVM:
9
8
```shell
10
9
graalpython -m venv <venv-dir>
11
10
```
12
11
13
12
To activate the environment in your shell session call:
14
-
15
13
```shell
16
14
source<venv-dir>/bin/activate
17
15
```
18
16
19
-
### Using ginstall
20
-
At the moment not enough of the standard library is implemented to run the
21
-
standard package installers for many packages. As a convenience, a
22
-
simple module to install packages is provided (including
23
-
potential patches required for those packages). Try the following to find out
24
-
more:
25
-
17
+
### Using `ginstall`
18
+
At the moment, there are not enough standard libraries implemented to run the standard package installers for many packages.
19
+
As a convenience, a simple module to install packages is provided (including potential patches required for those packages).
20
+
Try the following to find out more:
26
21
```shell
27
22
graalpython -m ginstall --help
28
23
```
29
24
30
25
As a slightly more exciting example, try:
31
-
32
-
```shell
26
+
```sehll
33
27
graalpython -m ginstall install numpy
34
28
```
35
29
36
-
If all goes well (also consider native dependencies of NumPy), you should be
37
-
able to `import numpy` afterwards.
30
+
If all goes well (also consider native dependencies of NumPy), you should be able to `import numpy` afterwards.
31
+
32
+
The support for more extensions is a high priority.
33
+
The GraalVM team is actively working to enable support for the Python C API, as well as to make extensions such as NumPy, SciPy, Scikit-learn, Pandas, Tensorflow, and alike, work.
34
+
Other extensions might currently work, but they are not actively tested.
35
+
Note that to try extensions on GraalVM's Python runtime, you have to download, build, and install them manually for now.
38
36
39
-
Support for more extensions is a high priority. The work is actively done
40
-
to enable support for the Python C API, to make extensions such as NumPy, SciPy,
41
-
Scikit-learn, Pandas, Tensorflow and the like work. Some other extensions might
42
-
also already work, but they are not actively tested. Note that to try extensions
43
-
with GraalVM Python implementation, you have to download, build and install them manually
44
-
for now.
37
+
### Using `pip`
45
38
46
-
### Using PIP
47
-
The pip package installer is available and working in a `venv`, but there is no
48
-
support for SSL yet. That means you can install packages from PyPI if you use an
49
-
HTTP mirror and you can install local packages.
39
+
The `pip` package installer is available and working in a `venv`, but there is no support for SSL yet.
40
+
This means you can install packages from PyPI if you use an HTTP mirror, and you can install local packages.
0 commit comments