```Pythoncall.jl – Python 与 Julia 的和谐共处```
Pythoncall.jl – Python and Julia in Harmony

原始链接: https://github.com/JuliaPy/PythonCall.jl

**PythonCall/JuliaCall** 为 Python 和 Julia 之间的双向通信提供了一个无缝、对称的接口。它允许开发者在保持原生语法的同时调用对方语言的代码,确保 Python 代码用起来像 Python,Julia 代码用起来像 Julia。 主要功能包括: * **高效互操作性:** 支持灵活的零拷贝数据转换。可变对象通过包装而非复制来处理,从而确保高性能以及两个环境间的实时同步。 * **无缝集成:** 将常用结构(如 DataFrames、数组、字典、IO 流)包装为目标语言中的对应结构。 * **隔离的依赖项:** 利用 `CondaPkg` 管理 Python 依赖,确保每个项目都能维护独立的运行环境。 * **现代支持:** 完全兼容当前版本的 Windows、macOS 和 Linux,支持 Julia 1.10+ 和 Python 3.10+。 与旧版的 `PyCall` 相比,该工具提供了更出色的扩展性、通过保留对象原始格式提升了类型稳定性,并具备更健壮的转换机制。对于希望将 Python 丰富的生态系统(如 Pandas、Seaborn)与 Julia 的高性能计算能力(如 Flux)相结合的开发者来说,这是理想的解决方案。

抱歉。
相关文章

原文

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Stable Documentation Dev Documentation Tests Codecov PkgEval

Bringing Python® and Julia together in seamless harmony:

  • Call Python code from Julia and Julia code from Python via a symmetric interface.
  • Simple syntax, so the Python code looks like Python and the Julia code looks like Julia.
  • Intuitive and flexible conversions between Julia and Python: anything can be converted, you are in control.
  • Fast non-copying conversion of numeric arrays in either direction: modify Python arrays (e.g. bytes, array.array, numpy.ndarray) from Julia or Julia arrays from Python.
  • Helpful wrappers: interpret Python sequences, dictionaries, arrays, dataframes and IO streams as their Julia counterparts, and vice versa.
  • Beautiful stack-traces.
  • Supports modern systems: tested on Windows, MacOS and Linux; 64-bit; Julia 1.10 upwards and Python 3.10 upwards.

⭐ If you like this, a GitHub star would be lovely thank you. ⭐

To get started, read the documentation.

Example 1: Calling Python from Julia

In this example, we use the Julia module PythonCall from a Pluto notebook to inspect the Iris dataset:

  • We load the Iris dataset as a Julia DataFrame using RDatasets.
  • We use pytable(df) to convert it to a Python Pandas DataFrame.
  • We use the Python package Seaborn to produce a pair-plot, which is automatically displayed.

Seaborn example screenshot

Example 2: Calling Julia from Python

In this example we use the Python module JuliaCall from an IPython notebook to train a simple neural network:

  • We generate some random training data using Python's Numpy.
  • We construct and train a neural network model using Julia's Flux.
  • We plot some sample output from the model using Python's MatPlotLib.

Flux example screenshot

The existing package PyCall is another similar interface to Python. Here we note some key differences:.

  • PythonCall supports a wider range of conversions between Julia and Python, and the conversion mechanism is extensible.
  • PythonCall by default never copies mutable objects when converting, but instead directly wraps the mutable object. This means that modifying the converted object modifies the original, and conversion is faster.
  • PythonCall does not usually automatically convert results to Julia values, but leaves them as Python objects. This makes it easier to do Pythonic things with these objects (e.g. accessing methods) and is type-stable.
  • PythonCall installs dependencies into a separate Conda environment for each Julia project using CondaPkg. This means each Julia project can have an isolated set of Python dependencies.
联系我们 contact @ memedata.com