Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installing pyjulia #473

Open
00sapo opened this issue Oct 28, 2021 · 8 comments
Open

Installing pyjulia #473

00sapo opened this issue Oct 28, 2021 · 8 comments

Comments

@00sapo
Copy link

00sapo commented Oct 28, 2021

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
Copy link
Member

tkf commented Oct 29, 2021

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

@00sapo
Copy link
Author

00sapo commented Oct 29, 2021

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.

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

@tkf
Copy link
Member

tkf commented Oct 29, 2021

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
Copy link
Author

00sapo commented Oct 29, 2021 via email

@sibyjackgrove
Copy link

@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
Copy link

jlapeyre commented Dec 7, 2021

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
Copy link
Member

tkf commented Dec 8, 2021

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
Copy link

jlapeyre commented Mar 4, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants