How to run a Julia file with PyJulia

I have a Julia file called ‘func1.jl’ with two defined functions that uses the ‘LowRankApprox’ package. Julia, it is working well. But I need it to work in Python. When I import to Python, with PyJulia, it doesn’t work. It gives the following error message:

Traceback (most recent call last):
  File "C:/Tese/problinearpristrunc0201.py", line 10, in <module>
    j.include('func1.jl')
ImportError: <PyCall.jlwrap (in a Julia function called from Python)
JULIA: LoadError: ArgumentError: Package LowRankApprox not found in current path:
- Run `import Pkg; Pkg.add("LowRankApprox")` to install the LowRankApprox package.

The LowRankApprox package is installed on Julia, although the error message says no. In fact, this is the problem that I don’t know how to solve. If I run another Julia file, without a package installed, with PyJulia it works fine. So the problem is the LowRankApprox package.

I use PyCharm Community 2020.2 and JuliaPro 1.5.2-1. I noticed that this version of Julia has neither Main nor Base. I tried to install it, but it doesn’t work either. : confused

Try func2.jl with something trivial like

function func2(x)
   return 2*x
end

This way you may localize the problem.

Base module is the Julia language, so to say, it’s always present

1 Like

Thank you for responding!
I’ve already created a Julia func2.jl file with any function that doesn’t use a Julia package and works well in PyJulia. In other words, the problem is the use of Julia’s LowRankApprox package that I need to work with in Python. Is it because of using PyCharm?

Did you instantiate the Julia environment in the directory where the func1.jl file is? You need to open Julia, and then in package manager mode you can

  1. activate the environment in the current folder ] activate .
  2. instantiate (or install the dependencies) ] instantiate
1 Like

It worked! thank you!
It looks like I was installing the package in the wrong folder. :grinning: :sweat_smile:

3 Likes