Giter Club home page Giter Club logo

juliapythonadaptor.jl's Introduction

JuliaPythonAdaptor

JuliaPythonAdaptor is a small Julia/Python package that helps you to create relocatable applications integrated with Julia and Python together.

The Julia programs using JuliaPythonAdaptor can be compiled by PackageCompiler into sysimages or executables that will work on another machine, if binary-compatible.

Note that your Python binaries are NOT bundled in the compiled julia files. You should also provide a proper Python environment for the target machines.

Motivation

At the current stage, a Julia programmer suffers from the following tasks:

  1. Setting up a Python environment to work with Julia.

  2. Reusing an existing Python/Julia environment from another language.

  3. Distributing compiled Julia binaries that interoperate with Python packages.

This project aims at providing a user-friendly approach to address all above issues.

Target Uses

  1. Software Integration

    If you want to make software that bundle Julia and Python together and make a separated environment, you might consider using this package or refer to the implementation.

  2. Simple Python-Julia Interoperability

    If your activating environment contains julia and python, you don't need to consider details.

Installation

  1. Install a julia (>= 1.6.1) distribution. Add it to $PATH if you want to avoid manual configurations.

  2. Install a Python (3.7+) distribution. Add it to $PATH if you want to avoid manual configurations.

  3. For the Python distribution: pip install git+https://github.com/thautwarm/JuliaPythonAdaptor.jl or pip install JuliaPythonAdaptor

    For the Julia distribution: julia -e "using Pkg; Pkg.add(\"JSON\", \"JuliaPythonAdaptor\")"

Usage

For relocatability, you might add the following environment variables:

Environment Variable Description Default Value
JP_ADAPTOR_PY_EXE the Python executable path python found in $PATH
JP_ADAPTOR_JL_EXE the Julia executable path julia found in $PATH
JP_ADAPTOR_JL_PROJ the Julia project that will be activated the global Julia project
JP_ADAPTOR_JL_IMAGE the Julia Sysimage that will be used decided by the julia program
JP_ADAPTOR_JL_DEPOT_PATH deciding JULIA_DEPOT_PATH decided by the julia program

REPL

Then, if you call Python from Julia, import JuliaPythonAdaptor before you import PythonCall. If you call Julia from Python, import JuliaPythonAdaptor before you import juliacall.

P.S: Due to this issue, tentatively you have to import JuliaPythonAdaptor in .julia/config/startup.jl for loading precompiled packages that use PythonCall:

# $JULIA_DEPOT_PATH/config/startup.jl
try
   @eval import JuliaPythonAdaptor
catch e
   @warn "Error initializing JuliaPythonAdaptor" exception=(e, catch_backtrace())
end

Sysimages or Apps

Tentatively, the package JuliaPythonAdaptor.jl does not work due to some julia internals. You can use pip to install the Python package JuliaPythonAdaptor to setup correct environment and call your sysimage or app:

# sysimage
python -c "import JuliaPythonAdaptor;import os;del os.environ['JULIA_PYTHONCALL_LIBPTR'];os.system('app-with-pythoncall.exe')"
# app
python -c "import JuliaPythonAdaptor;import os;del os.environ['JULIA_PYTHONCALL_LIBPTR'];os.system('julia -Jsys-with-pythoncall.dll')"

I use PyCall, how to use this package?

PyCall is a great package for Julia to call Python, but it so far does not consider much about relocatability and environment separation.

Please refer to these detailed instructions from PyCall to PythonCall. They will help you with migrating your codebase.

Contributions

PRs and issues are welcome.

Besides, this project leverages the mechanism provided by PythonCall.jl, CondaPkg.jl, MicroMamba.jl and pyjuliapkg. You might also consider contributing to them.

juliapythonadaptor.jl's People

Contributors

thautwarm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.