PyCall defaults to global python, despite ENV["PYTHON"] = ""

Hello everyone!

I am currently trying to get some CGAL bindings to work on Julia v1.9. Unfourtunately CGAL.jl does not work for Julia v1.9, so i have to resort to using PyCall and the python bindings!

I have used PyCall before, always with the ENV[“PYTHON”] = “” variable, because we need to share it across different users, and it always worked. However there seems to be something strange happening now.

I try to install and it works, and shows me that it is installed (via Conda.list() ), however it still raises a ModuleNotFoundError.

As a test i also install and load numpy, and to my surprise it loads from my global python version, despite the ENV var set directly before to the empty string!

This is the Code:

> using Conda
> using Pkg
> using PyCall
> ENV["PYTHON"] = ""
> Pkg.build("PyCall")
> println("pyversion: ", PyCall.pyversion)
> println("python path: ", PyCall.python)
> numpy = pyimport_conda("numpy", "numpy")
> println("numpy: ", numpy)
> Conda.pip_interop(true)
> Conda.pip("install", "cgal")
> cgal = pyimport("cgal")

and this is the output/stacktrace:

> 
> [ Info: Precompiling ConservativeInterpolation [4b752949-01d3-4fe2-bbf5-432805ea2d05]
>     Building Conda ─→ `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/51cab8e982c5b598eea9c8ceaced4b58d9dd37c9/build.log`
>     Building PyCall → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/9816a3826b0ebf49ab4926e2b18842ad8b5c8f04/build.log`
> pyversion: 3.10.14
> python path: /home/thk/.julia/conda/3/x86_64/bin/python
> numpy: PyObject <module 'numpy' from '/home/thk/.local/lib/python3.10/site-packages/numpy/__init__.py'>
> [ Info: Running `conda config --set pip_interop_enabled true --file /home/thk/.julia/conda/3/x86_64/condarc-julia.yml` in root environment
> [ Info: Running `pip install cgal` in root environment
> Requirement already satisfied: cgal in /home/thk/.julia/conda/3/x86_64/lib/python3.10/site-packages (5.6.1.post202406030950)
> Requirement already satisfied: numpy in /home/thk/.local/lib/python3.10/site-packages (from cgal) (1.25.2)
> ERROR: LoadError: PyError (PyImport_ImportModule
> 
> The Python package cgal could not be imported by pyimport. Usually this means
> that you did not install cgal in the Python version being used by PyCall.
> 
> PyCall is currently configured to use the Julia-specific Python distribution
> installed by the Conda.jl package.  To install the cgal module, you can
> use `pyimport_conda("cgal", PKG)`, where PKG is the Anaconda
> package that contains the module cgal, or alternatively you can use the
> Conda package directly (via `using Conda` followed by `Conda.add` etcetera).
> 
> Alternatively, if you want to use a different Python distribution on your
> system, such as a system-wide Python (as opposed to the Julia-specific Python),
> you can re-configure PyCall with that Python.   As explained in the PyCall
> documentation, set ENV["PYTHON"] to the path/name of the python executable
> you want to use, run Pkg.build("PyCall"), and re-launch Julia. /home/thk/.julia/conda/3/x86_64/bin/python
> 
> ) <class 'ModuleNotFoundError'>
> ModuleNotFoundError("No module named 'cgal'")
> 
> Stacktrace:
>  [1] pyimport(name::String)
>    @ PyCall ~/.julia/packages/PyCall/1gn3u/src/PyCall.jl:558
>  [2] top-level scope
>    @ ~/juliacfs/src/SpaceFilter/ConservativeInterpolation/src/ConservativeInterpolation.jl:21
>  [3] include
>    @ ./Base.jl:457 [inlined]
>  [4] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::String)
>    @ Base ./loading.jl:2049
>  [5] top-level scope
>    @ stdin:3
> in expression starting at /home/thk/juliacfs/src/SpaceFilter/ConservativeInterpolation/src/ConservativeInterpolation.jl:1
> in expression starting at stdin:3

As you can see, it even says that it is using the Conda.jl python distribution. However if you look at when i print the imported numpy module, it gives the path to my global version. I found similar threads discussing PYTHONPATH and PYTHONHOME variable interfering, however if i run ‘printenvs’ in my terminal, i have no such ENV variables set. I also tried it with pyimport_conda, and i had the same issues, and only a old version of the bindings is available on the conda-forge channel, so i want to use pip anyway.

I have CONDE_EXE and CONDA_PYTHON_EXE variables set pointing to the global conda installation, however i found threads saying that these should not be an issue and that Conda.jl would take care of them. I would like to keep those since i also use my global python/conda.

When i run Conda.list() it shows that cgal is installed:

> cgal 5.6.1.post202406030950 pypi_0 pypi

I use WSL with VSCode. I should mention that i try to load this packages from within a self created module, however i have done the same thing in the past and it has never been an issue.

Thank you ver much in advance,
Thomas