|
1 |
| -# The Python module *juliacall* |
| 1 | +# The Python module JuliaCall |
2 | 2 |
|
3 | 3 | ## Installation
|
4 | 4 |
|
5 |
| -In the future, the package will be available on PyPI and conda. |
6 |
| -For now, you can pip install this package directly from github as follows: |
7 |
| - |
| 5 | +It's as simple as |
8 | 6 | ```bash
|
9 |
| -pip install git+https://github.com/cjdoris/PythonCall.jl |
| 7 | +pip install juliacall |
10 | 8 | ```
|
11 | 9 |
|
12 |
| -Developers may wish to clone the repo directly and pip install the module in editable mode. |
13 |
| -This guarantees you are using the latest version of PythonCall in conjunction with juliacall. |
14 |
| - |
15 |
| -Note also that regardless of installing `juliacall`, a module called `juliacall` will |
16 |
| -always be loaded into the interpreter by `PythonCall`. This means that other Python |
17 |
| -packages can always `import juliacall`. |
| 10 | +Developers may wish to clone the repo (https://github.com/cjdoris/PythonCall.jl) directly |
| 11 | +and pip install the module in editable mode. This guarantees you are using the latest |
| 12 | +version of PythonCall in conjunction with JuliaCall. |
18 | 13 |
|
19 | 14 | ## Getting started
|
20 | 15 |
|
21 | 16 | For interactive or scripting use, the simplest way to get started is:
|
22 |
| - |
23 | 17 | ```python
|
24 | 18 | from juliacall import Main as jl
|
25 | 19 | ```
|
26 | 20 |
|
27 |
| -This loads a single variable `jl` (a [`ModuleValue`](#juliacall.ModuleValue)) which represents the `Main` module in Julia, from which all of Julia's functionality is available. |
| 21 | +This loads a single variable `jl` which represents the `Main` module in Julia, |
| 22 | +from which all of Julia's functionality is available: |
| 23 | +```python |
| 24 | +jl.println("Hello from Julia!") |
| 25 | +# Hello from Julia! |
| 26 | +x = jl.rand(range(10), 3, 5) |
| 27 | +x._jl_display() |
| 28 | +# 3×5 Matrix{Int64}: |
| 29 | +# 8 1 7 0 6 |
| 30 | +# 9 2 1 4 0 |
| 31 | +# 1 8 5 4 0 |
| 32 | +import numpy |
| 33 | +numpy.sum(x, axis=0) |
| 34 | +# array([18, 11, 13, 8, 6], dtype=int64) |
| 35 | +``` |
28 | 36 |
|
29 |
| -If you are writing a package which uses Julia, then to avoid polluting the global `Main` namespace you should do: |
| 37 | +In this example: |
| 38 | +- We called the `jl.println` function to print a message. |
| 39 | +- We called the `jl.rand` function to generate an array of random integers. Note that the |
| 40 | + first argument is `range(10)` which is converted to `0:9` in Julia. |
| 41 | +- We called its special `_jl_display()` to show it using Julia's display mechanism. |
| 42 | +- We called the `numpy.sum` function to sum each column of `x`. This automatically converted |
| 43 | + `x` to a NumPy array. (We could have done `jl.sum(x, dims=1)` too.) |
30 | 44 |
|
| 45 | +If you are writing a package which uses Julia, then to avoid polluting the global `Main` |
| 46 | +namespace you instead should start with: |
31 | 47 | ```python
|
32 | 48 | import juliacall; jl = juliacall.newmodule("SomeName");
|
33 | 49 | ```
|
34 | 50 |
|
35 |
| -Now you can do `jl.rand(jl.Bool, 5, 5)`, which is equivalent to `rand(Bool, 5, 5)` in Julia. |
36 |
| - |
37 |
| -When a Python value is passed to Julia, then typically it will be converted according to [this table](@ref py2jl) with `T=Any`. |
38 |
| -Sometimes a more specific type will be used, such as when assigning to an array whose element type is known. |
39 |
| - |
40 |
| -When a Julia value is returned to Python, it will normally be converted according to [this table](@ref jl2py). |
| 51 | +What to read next: |
| 52 | +- The main functionality of this package is in `AnyValue` objects, which represent Julia |
| 53 | + objects, [documented here](@ref julia-wrappers). |
| 54 | +- If you need to install Julia packages, [read here](@ref julia-deps). |
| 55 | +- When you call a Julia function, such as `jl.rand(...)` in the above example, its |
| 56 | + arguments are converted to Julia according to [this table](@ref py2jl-conversion) and |
| 57 | + its return value is converted to Python according to [this table](@ref jl2py-conversion). |
41 | 58 |
|
42 |
| -## Managing Julia dependencies |
| 59 | +## [Managing Julia dependencies](@id julia-deps) |
43 | 60 |
|
44 |
| -juliacall manages its Julia dependencies using [Pkg](https://pkgdocs.julialang.org/v1) for |
| 61 | +JuliaCall manages its Julia dependencies using [Pkg](https://pkgdocs.julialang.org/v1) for |
45 | 62 | packages and [jill](https://pypi.org/project/jill/) for Julia itself.
|
46 |
| -If a suitable version of julia is not found on your system, it will automatically be |
| 63 | +If a suitable version of Julia is not found on your system, it will automatically be |
47 | 64 | downloaded and installed into `~/.julia/pythoncall`.
|
48 |
| -A Julia environment is automatically created when juliacall is loaded, is activated, and is |
| 65 | +A Julia environment is automatically created when JuliaCall is loaded, is activated, and is |
49 | 66 | initialised with at least PythonCall. If you are using a virtual or conda environment then
|
50 | 67 | the Julia environment is created there, otherwise a global environment is created at
|
51 | 68 | `~/.julia/environments/PythonCall`.
|
@@ -74,9 +91,10 @@ Here is an example:
|
74 | 91 | }
|
75 | 92 | }
|
76 | 93 | ```
|
77 |
| -All parts are optional, except that the UUID of each package is required. |
| 94 | +All parts are optional, except that the UUID of each package is required. Typically you |
| 95 | +will just include the UUID and compat fields. |
78 | 96 |
|
79 |
| -When juliacall starts, it will ensure the latest compatible version of julia is installed, |
| 97 | +When JuliaCall starts, it will ensure the latest compatible version of Julia is installed, |
80 | 98 | and will ensure the given packages are installed.
|
81 | 99 |
|
82 | 100 | ## Utilities
|
|
0 commit comments