Skip to content

Commit 15c858b

Browse files
author
Christopher Doris
committed
docs
1 parent 0116f7a commit 15c858b

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

docs/src/pycall.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
# Comparison with PyCall
1+
# Coming from *PyCall*?
22

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).
44

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
615

716
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)`.
817

918
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`).
1019

1120
Furthermore, `pyconvert` can be extended to support more types, whereas `convert(Vector, x)` cannot support more Python types.
1221

13-
## Lossiness of conversion
22+
### Lossiness of conversion
1423

1524
Both packages allow conversion of Julia values to Python: `PyObject(x)` in PyCall, `Py(x)` in PythonCall.
1625

@@ -31,7 +40,7 @@ Py(x).append("baz")
3140

3241
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.
3342

34-
## Automatic conversion
43+
### Automatic conversion
3544

3645
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
3746
```julia
@@ -44,20 +53,20 @@ set!(pyimport(os)."environ", "KEY", "VALUE")
4453

4554
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.
4655

47-
## Which Python
56+
### Which Python
4857

4958
PyCall uses some global installation of Python - typically the version of Python installed on the system or used by Conda.
5059

5160
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).
5261

53-
## Corresponding Python packages
62+
### Corresponding Python packages
5463

5564
PyCall has the corresponding Python package [pyjulia](https://github.com/JuliaPy/pyjulia) for calling Julia from Python, and PythonCall similarly has juliacall.
5665

5766
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.
5867

5968
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.
6069

61-
## Compatability
70+
### Compatability
6271

6372
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).

docs/src/pythoncall.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,20 @@ PythonCall.Deps.conda_env
279279
PythonCall.Deps.user_deps_file
280280
```
281281

282+
### The Python interpreter
283+
284+
By default, `python` is automatically installed into the Conda environment mentioned above.
285+
286+
To use a different interpreter, you can set the environment variable `JULIA_PYTHONCALL_EXE`
287+
to its path before importing PythonCall. You can set it to `python` if it is in your PATH.
288+
289+
You can also set it to the special value `"@PyCall"` which will use the same interpreter as
290+
PyCall.
291+
292+
Note that using a non-default interpreter will disable all dependency management: no Conda
293+
environment will be created and no packages will be automatically installed. It is up to the
294+
user to ensure any required packages are installed.
295+
282296
## Writing packages which depend on *PythonCall*
283297

284298
### Example

0 commit comments

Comments
 (0)