JuliaPy / pyjulia

python interface to julia
MIT License
885 stars 101 forks source link

Installing pyjulia #473

Open 00sapo opened 3 years ago

00sapo commented 3 years ago

Here is a little function that downloads julia if needed, set up an environmnt and instantiate the project.

I think something similar should be provided so that users can call it in setup.py

def setup_pyjulia_env(path_to_project="."):
    """
    A function that installs all dependencies for current environment.
    This should be the same as what `juliacall` does at every import time.
    * `path_to_project` is the path to the project that will be instantiated.
    If `None`, no project will be instantiated. Defaults: to the current
    working directory.
    """
    import jill.install  # noqa: autoimport
    import os  # noqa: autoimport
    import shutil  # noqa: autoimport
    if shutil.which('julia') is None:
        print(
            "No Julia executable found, installing the latest version using `jill`")
        jill.install.install_julia("stable", confirm=True)
        if shutil.which('julia') is None:
            print(f"Please add {os.environ['JILL_SYMLINK_DIR']} to your path")
    import julia  # noqa: autoimport
    # the following installs dependencies for pyjulia
    julia.install()
    from julia.api import LibJulia  # noqa: autoimport

    if path_to_project is not None:
        api = LibJulia.load()
        api.init_julia([f"--project={path_to_project}"])

        from julia import Main  # noqa: autoimport

        Main.eval('using Pkg')
        Main.eval('Pkg.instantiate()')

Example from: https://github.com/00sapo/pyjulia-vs-juliacall

tkf commented 3 years ago

We should use https://github.com/JuliaLang/juliaup for this. It's not great if every library handles its dependency on its way.

00sapo commented 3 years ago

I see your point. What are the benefits of juliaup over Jill?

  1. Juliaup is focused on Windows, while Jill is multiplatform

  2. if one is using pyjulia, it's already using python, so Jill would be the obvious way since it's a python module with python API.

    1. I don't see how juliaup ensures that what it installs is the same as the user will later use
tkf commented 3 years ago

I think juliaup eventually becomes cross-platform. Not using Python API is exactly the point; all use cases for pure-Julia, Python, R, etc. programs will use the same installation with a uniform end-user interface.

00sapo commented 3 years ago

I think this kind of discussion is premature: when an installer will be a de facto standard (like pyenv for instance) we'll be able to chose the best one. For now, the easiest (from API perspective) and the most used one could be a good choice.

The easiest one is probably Jill, the most used one is (looking at GitHub stars) Jill.

P.s. I was thinking that the most used one was juliavm, but according to GitHub stars, it's even less used than juliaup.

On October 30, 2021 12:13:24 AM GMT+02:00, Takafumi Arakaki @.***> wrote:

I think juliaup eventually becomes cross-platform. Not using Python API is exactly the point; all use cases for pure-Julia, Python, R, etc. programs will use the same installation with a uniform end-user interface.

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/JuliaPy/pyjulia/issues/473#issuecomment-955076894

-- Inviato dal mio dispositivo Android con K-9 Mail. Perdonate la brevità.

sibyjackgrove commented 2 years ago

@00sapo Thank you for this code. I tried it and it works well. Can I use it in one of my projects which uses diffeqpy? We want to provide a way for users to not have to worry about installing Julia if they want to use diffeqpy. We will provide acknowledgment for you in our project repository. Also, could you provide more clarification on what path_to_project is for? What is the advantage of instantiating a project?

jlapeyre commented 2 years ago

My current thoughts are that management task like installing Julia, making sure packages are available, compiling a Julia project, etc., would better be handled in another layer, not in pyjulia itself. Maybe some ideas could be migrated in if they are tested and seem appropriate.

tkf commented 2 years ago

Just to clarify: I think it's very unlikely that I will merge or review a patch that maintains Julia installations in a Python-specific way. There should be a language-agnostic user-facing interface (like juliaup CLI).

jlapeyre commented 2 years ago

I neglected to mention here that I wrote a python package find_julia. It is lightweight and should be easy to use. It is a bit featureful, has more than you would want to put in pyjulia.

It supports specifying the required Julia version in exactly the same syntax and semantics that Julia does with julia_semver.

By default it prefers looking in the juliaup directory first and returns the best match. If there is no match, it looks in jill-installed locations. This is because the latter is a bit slower; juliaup caches the julia versions.

It offers to install, if none is found. This is done via jill.py, which is loaded on demand because it takes >50ms to load. In the future, supporting juliaup for downloading would be a good idea. I would do it now, but juliaup is still developing and it does not yet have an API.