JuliaPy / PyCall.jl

Package to call Python functions from the Julia language
MIT License
1.45k stars 186 forks source link

Building PyCall Offline with Mamba #1050

Closed callous4567 closed 10 months ago

callous4567 commented 10 months ago

Hello;

This is a suggestion regarding making PyCall easier to use in an offline build under a very restrictive firewall using Conda.jl. Specifically, when carrying out its build.jl here the following lines

    if use_conda
        Conda.add("numpy"; satisfied_skip_solve=true)
    end

will result in an unsightly error as Conda fails to connect to the internet to check for any versioning and so forth on Numpy. Removing these lines allow full offline build/precompile of PyCall on a pre-filled distribution of Julia (with Conda having its set of pre-installed Python packages.)

I would think it satisfactory to verify Numpy's presence with a quick check similar to PyCall.pyimport("numpy") or similar?

stevengj commented 10 months ago

The problem is that we can't call PyCall functions (e.g. PyCall.pyexists("numpy")) in the build script.

I suppose we could check success(`$python -c "import numpy"`).

But in the circumstance you describe, shouldn't you just build PyCall with ENV["PYTHON"] = "/path/to/your/python" to tell it to use your manual offline Python installation rather than trying to install via Conda?

callous4567 commented 10 months ago

The problem is that we can't call PyCall functions (e.g. PyCall.pyexists("numpy")) in the build script.

I suppose we could check success(`$python -c "import numpy"`).

But in the circumstance you describe, shouldn't you just build PyCall with ENV["PYTHON"] = "/path/to/your/python" to tell it to use your manual offline Python installation rather than trying to install via Conda?

I do actually have to set ENV["PYTHON"]=... when I transfer to the work VM- otherwise Julia defaults to trying to use the one in /usr/bin/... (despite being tarballed with the ENV set to the Conda interpreter.) The issue still occurred when doing this. After looking at the build.jl file, I've found the reason that this is a problem- the Python I'm using is the one that Conda comes with- this line

use_conda = dirname(python) == abspath(Conda.PYTHONDIR)

triggers the check for numpy that ruins the build process in the offline build. The manual offline Python installation I'm using is actually just the one that Conda builds up (``/home/username/.julia/conda/3/x86_64/bin) and this triggers the statement above to be true, ruining the build as Conda tries to connect to internet it has no access to.

So, to sum up- the issue here is that the manual offline installation I'm using is one that I made using Conda when it was connected to the net- taking it offline and then trying to build it will result in a fail, as Conda can no longer do all the online versioning it normally does when you call a Conda.add().

It's a very niche issue for sure- I doubt there's many people building environments to later use offline without network access, nevermind with the default Conda interpreter, so I can understand if there's nothing to be done about it- I just hope if someone else encounters it they somehow find this post.

stevengj commented 10 months ago

Changing if use_conda to if use_conda && !success(`$python -c "import numpy"`) seems reasonable enough if you want to try it out and maybe submit a PR.

callous4567 commented 10 months ago

Aye- I'll take a look into doing this at some point in the near future :)