Skip to content

PyCall.jl setting incorrect libpython on Julia 1.9 #522

@MilesCranmer

Description

@MilesCranmer

I can't seem to get PyJulia working on Julia 1.9 (beta 4), although it works fine on 1.8.5. It seems to be some issue with the Python interpreter and libpython set by PyCall.jl. It could be interference from Conda.jl's installed copy of Python and libpython?

First, I set up a completely fresh Julia install with juliaup (note that this code will delete your ~/.julia folder, only saving startup.jl):

mv ~/.julia/config/startup.jl ~/startup.jl && \
    rm -rf ~/.julia && \
    mkdir -p ~/.julia/config && \
    mv ~/startup.jl ~/.julia/config/startup.jl && \
    juliaup add 1.9 && \
    juliaup default 1.9 && \
    julia --startup-file=no -e 'using Pkg; Pkg.add(["OhMyREPL", "Revise"])'

Then, I run:

python -c 'import julia; julia.install()'

Which succeeds. However, when I try to start Julia via PyJulia:

python -c 'from julia import Main'
despite the exact same set of environment variables as used in the `install`, this fails:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 632, in _load_backward_compatible
  File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 247, in load_module
    JuliaMainModule(self, fullname))
  File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 149, in __init__
    self._julia = loader.julia
  File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 239, in julia
    self.__class__.julia = julia = Julia()
  File "/Users/mcranmer/venvs/main/lib/python3.10/site-packages/julia/core.py", line 489, in __init__
    raise UnsupportedPythonError(jlinfo)
julia.core.UnsupportedPythonError: It seems your Julia and PyJulia setup are not supported.

Julia executable:
    julia
Python interpreter and libpython used by PyCall.jl:
    /Users/mcranmer/.julia/conda/3/aarch64/bin/python
    /Users/mcranmer/.julia/conda/3/aarch64/lib/libpython3.10.dylib
Python interpreter used to import PyJulia and its libpython.
    /Users/mcranmer/venvs/main/bin/python
    /opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/Python

In Julia >= 0.7, above two paths to `libpython` have to match exactly
in order for PyJulia to work out-of-the-box.  To configure PyCall.jl to use
Python interpreter "/Users/mcranmer/venvs/main/bin/python",
run the following code in the Python REPL:

    >>> import julia
    >>> julia.install()

For more information, see:

    https://pyjulia.readthedocs.io/en/latest/troubleshooting.html

In particular, the Python interpreter and libpython seem to be set incorrectly:

Python interpreter and libpython used by PyCall.jl:
    /Users/mcranmer/.julia/conda/3/aarch64/bin/python
    /Users/mcranmer/.julia/conda/3/aarch64/lib/libpython3.10.dylib
Python interpreter used to import PyJulia and its libpython.
    /Users/mcranmer/venvs/main/bin/python
    /opt/homebrew/Cellar/python@3.10/3.10.9/Frameworks/Python.framework/Versions/3.10/Python

I'm assuming these new python and libpython are packaged by the PyCall.jl install. But I think ideally we would want them to be set by the user from their Python/libpython, for compatibility with Python libraries, right?

I can run this entire workflow with juliaup add 1.8 && juliaup default 1.8 instead, and it works fine.

cc @mkitti @ngam @stevengj @marius311


edit: I should mention I'm not using conda at all. This is a homebrew-installed version of Python running in a virtualenv.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions