6

Following the instructions on the PyCall.jl readme, I am tying to use a pipenv python when using PyCall for my julia project (in it's own environment).

In a terminal, I have activated the python environment using pipenv shell, and then located the pathfile of the pipenv version of python. PyCall has already been added to the manifest in my julia environment. In the source-activated terminal, I started Julia and entered: ENV["PYCALL_JL_RUNTIME_PYTHON"] = pipenv python environmentand then proceeded to run Pkg.build("PyCall"), which installs conda. When importing PyCall - using PyCall - I get the following error.

ERROR: InitError: Incompatible `libpython` detected.
`libpython` for C:\Users\me\.virtualenvs\iap\Scripts\python.exe is:
    C:\Users\me\.virtualenvs\iap\Scripts\python37.dll
`libpython` for C:\Users\me\.julia\conda\3\python.exe is:
    C:\Users\me\.julia\conda\3\python36.dll
PyCall.jl only supports loading Python environment using the same `libpython`

I've tried re-installing PyCall, but the python environment libpython always throws this error. How can I override or otherwise work around the conda requirement for base julia?

I have a feeling that the Conda dependency of PyCall is causing some libpython issue, and that the ENV["PYCALL_JL_RUNTIME_PYTHON"] call doesn't override the libpython variable properly.

PeptideWitch
  • 2,239
  • 14
  • 30
  • You have installed different Python-versions on your computer. Maybe you should uninstall all of them, then install only one of them (perhaps the latest stable version). – Lorinczy Zsigmond Jan 24 '20 at 03:23
  • Thanks for replying; I'm not entirely convinced that's the case here. I only have 1 system python version installed, and it's python 3.7. The `libpython` version seems to want to point to `python3 exe` within the Julia directory (see the error in my post). I don't have conda installed on my system; this is one of the dependencies of PyCall (I believe). – PeptideWitch Jan 24 '20 at 03:35
  • In the quoted messages both python36.dll and python37.dll is mentioned. Maybe one of your programs came with a "built in Python" of version 3.6.x and that causes the version incompatibilty. – Lorinczy Zsigmond Jan 24 '20 at 04:09
  • There are indeed 2 dlls. One is from a conda directory that's automatically installed when `Pkg.build("PyCall")` [is run, as shown here](https://imgur.com/a/4Arr6KT). If I get rid of this conda directory in the .julia home folder, Julia provides a non-specific error, then crashes. – PeptideWitch Jan 24 '20 at 04:16
  • Note that I ran `Pkg.build("PyCall")` after doing the python environment export; the error still persists. I'll update my original post to reflect that – PeptideWitch Jan 24 '20 at 04:19

1 Answers1

3

According to the documentation PyCall supports venv and virtualenv environments, but you are using pipenv. I recommend you try with either of the supported alternatives, if you want to use the PYCALL_JL_RUNTIME_PYTHON variable.

If you want to use continue using the pipenv environment instead, you probably have to specify the PYTHON variable instead in your startup.jl configuration file, like this:

ENV["PYTHON"] = "C:\\path\\to\\your\\pipenv\\python.exe"

Then run:

julia> using Pkg; Pkg.build("PyCall"); using PyCall
HarmonicaMuse
  • 7,633
  • 37
  • 52
  • 2
    Thanks for your answer! I managed to get it working. It seems that the part of the readme that I was following - the change to `ENV["PYCALL_JL_RUNTIME_PYTHON"]` - was more about switching virtual environments after a build instead of setting up the python environment to begin with. – PeptideWitch Jan 29 '20 at 23:25