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
Copy file name to clipboardExpand all lines: docs/src/pycall.md
+17-8Lines changed: 17 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,25 @@
1
-
# Comparison with PyCall
1
+
# Coming from *PyCall*?
2
2
3
-
Another similar interface to Python is provided by [`PyCall`](https://github.com/JuliaPy/PyCall.jl). Here we note some key differences.
3
+
Another similar interface to Python is provided by [`PyCall`](https://github.com/JuliaPy/PyCall.jl).
4
4
5
-
## Flexibility of conversion
5
+
On this page, we give some tips for migrating between the two modules and a comparison.
6
+
7
+
## Tips
8
+
9
+
- You can use both PyCall and PythonCall in the same Julia session (this might be platform dependent).
10
+
- To force PythonCall to use the same Python interpreter as PyCall, set the environment variable `JULIA_PYTHONCALL_EXE` to `"@PyCall"`.
11
+
12
+
## Comparison
13
+
14
+
### Flexibility of conversion
6
15
7
16
In PyCall you do `convert(T, x)` to convert the Python object `x` to a Julia `T`. In PythonCall you similarly do `pyconvert(T, x)`.
8
17
9
18
PythonCall supports far more combinations of types of `T` and `x`. For example `convert(Vector, x)` in PyCall requires `x` to be a sequence, whereas in PythonCall `pyconvert(Vector, x)` works if `x` is an iterable, an object supporting the buffer protocol (such as `bytes`) or an object supporting the numpy array interface (such as `numpy.ndarray`).
10
19
11
20
Furthermore, `pyconvert` can be extended to support more types, whereas `convert(Vector, x)` cannot support more Python types.
12
21
13
-
## Lossiness of conversion
22
+
###Lossiness of conversion
14
23
15
24
Both packages allow conversion of Julia values to Python: `PyObject(x)` in PyCall, `Py(x)` in PythonCall.
16
25
@@ -31,7 +40,7 @@ Py(x).append("baz")
31
40
32
41
In fact, PythonCall has the policy that any mutable object will by default be wrapped in this way, which not only preserves mutability but makes conversion faster for large containers since it does not require taking a copy of all the data.
33
42
34
-
## Automatic conversion
43
+
###Automatic conversion
35
44
36
45
In PyCall, most function calls, attribute accesses, indexing, etc. of Python object by default automatically convert their result to a Julia object. This means that the following
In PythonCall, we don't do any such automatic conversion: we always return `Py`. This means that the first piece of code above does what you think.
46
55
47
-
## Which Python
56
+
###Which Python
48
57
49
58
PyCall uses some global installation of Python - typically the version of Python installed on the system or used by Conda.
50
59
51
60
PythonCall uses a separate Conda environment for each Julia environment/project/package and installs Python (and other Python packages) into that. This means that different Julia projects can maintain an isolated set of Python dependencies (including the Python version itself).
52
61
53
-
## Corresponding Python packages
62
+
###Corresponding Python packages
54
63
55
64
PyCall has the corresponding Python package [pyjulia](https://github.com/JuliaPy/pyjulia) for calling Julia from Python, and PythonCall similarly has juliacall.
56
65
57
66
One difference is between them is their code size: pyjulia is a large package, whereas juliacall is very small, with most of the implementation being in PythonCall itself. The practical up-shot is that PythonCall/juliacall have very symmetric interfaces; for example they use identical conversion policies and have the same set of wrapper types available.
58
67
59
68
Note also that juliacall will use a separate Julia project for each virtual/conda environment. This means that different Python environments can maintain an isolated set of Julia dependencies, including the versions of Julia and PythonCall themselves.
60
69
61
-
## Compatability
70
+
###Compatability
62
71
63
72
PyCall supports Julia 0.7+ and Python 2.7+, whereas PythonCall supports Julia 1.0+ and Python 3.5+. PyCall requires numpy to be installed, PythonCall doesn't (it provides the same fast array access through the buffer protocol and array interface).
0 commit comments