1

I have been writing code in Python 3 on Windows 10 and need to call a function which was written in Julia, so I have installed Julia and PyJulia. I have encountered a very strange problem, however: while I can import and call Julia modules just fine in Python terminal (though importing them can take an unexpected few seconds), trying to import any Julia module in a Python script will give an error.

I can run a line

import julia

just fine, but something as simple as

from julia import Base 

will give the two dialog boxes and error in terminal screenshotted below. My question is simply, does anyone know what is going on here, or how to fix it? Thanks.

dialog1

dialog2

terminal output

  from julia import Base
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "C:\ProgramData\Anaconda3\lib\site-packages\julia\core.py", line 248, in load_module
  elif self.julia.isafunction(juliapath):
File "C:\ProgramData\Anaconda3\lib\site-packages\julia\core.py", line 239, in  julia
  self.__class__.julia = julia = Julia()
File "C:\ProgramData\Anaconda3\lib\site-packages\julia\core.py", line 472, in __init__
  self.api = LibJulia.from_juliainfo(jlinfo)
File "C:\ProgramData\Anaconda3\lib\site-packages\julia\libjulia.py", line 195, in from_juliainfo
  sysimage=juliainfo.sysimage,
File "C:\ProgramData\Anaconda3\lib\site-packages\julia\libjulia.py", line 215, in __init__
  self.libjulia = ctypes.PyDLL(libjulia_path, ctypes.RTLD_GLOBAL)
File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 364, in __init__
  self._handle = _dlopen(self._name, mode)
OSError: [WinError 127] The specified procedure could not be found
jkflowers
  • 81
  • 6

1 Answers1

1

Looks like you forgot to configure Python Julia module.

You should run:

import julia
julia.install()

In this way Python should be able to find paths.

Note also that julia.exe should be in your system PATH. You can run set PATH in command line console to see where it is. To test the configuration run in console where julia (I am showing here my output):

C:\Users\pszufe>where julia
C:\Julia-1.6.0-rc1\bin\julia.exe

Finally, please also have a look here: I have a high-performant function written in Julia, how can I use it from Python?

Przemyslaw Szufel
  • 40,002
  • 3
  • 32
  • 62
  • Thanks for replying; I will take a look at the link. I have previously tried import julia julia.install() It runs fine both in scripts and in Python terminal, but attempts to import modules from julia on the line below that still fail. You can see that Python does know where Julia (or at least Julia.exe) is located, as it correctly references the locations of several .dll's in the Julia directory. What I do not know is whether it knows where the Julia modules are installed, as while Julia.exe is under /AppData/Local/Programs/Julia 1.5.3, the modules are installed under /.julia – jkflowers Feb 10 '21 at 15:43
  • My original installation was in accordance with that guide. I will check if I can compile the packages into the Julia system image, and whether that makes a difference. – jkflowers Feb 10 '21 at 15:48
  • 1
    Do not start with compiling packages into system image! What happens when you try to load libraries using Python located at `%USERPROFILE%\.julia\conda\3\python.exe`? The point is that Python `julia` relies on PyCall configuration within the Julia installation and they might not match in your case. – Przemyslaw Szufel Feb 10 '21 at 16:28
  • Thank you, clicking python.exe in that location opens a python terminal, and that terminal cannot find the module julia. That sounds like a plausible hypothesis to me, but I do not know how to test or fix it. – jkflowers Feb 10 '21 at 21:03
  • try in Julia `ENV["PYTHON"]="";using Pkg;Pkg.build("PyCall")` than switch to `%USERPROFILE%\.julia\conda\3\python.exe` run `julia.install()` and see if now you can import packages. – Przemyslaw Szufel Feb 10 '21 at 21:09
  • Those lines in Julia run fine, but do not alter the output in `/.julia/conda/3/python.exe` – jkflowers Feb 10 '21 at 21:34
  • Does it still keep saying c:\ProgramData\Anaconda3 in the output? In that case something bad went with your multi-Python configuration. – Przemyslaw Szufel Feb 10 '21 at 21:42
  • I just get `File "", line 1, in `;`ModuleNotFoundError: No module named 'julia'`. The distribution of anaconda is clearly different from the one I normally use -- it does not even have numpy or scipy. Again, I can call Julia just fine from my normal anaconda terminal, but for some reason can not do the same if I am trying to import modules into a .py file. – jkflowers Feb 11 '21 at 08:23
  • I successfully installed this on another windows PC. I am willing to write it off as a fluke, and maybe try to install it on this computer for a 3rd time later. – jkflowers Feb 11 '21 at 11:58