How to run a Julia file, which uses a package, in Python?

I'm using PyJulia to run a Julia file in Python. The file I want to run uses a package, that is already installed on Julia. But it still gives the following error:

JULIA: LoadError: ArgumentError: Package LowRankApprox not found in current path: Run `import Pkg; Pkg.add("LowRankApprox")` to install the LowRankApprox package.

Why are you giving this error, if the package has already been installed on Julia?

Upvotes: 9

Views: 743

Answers (1)

Przemyslaw Szufel
Przemyslaw Szufel

Reputation: 42264

You need to make sure that the correct Julia environment got activated by pyjulia. Try running in Python:

from julia import Pkg
Pkg.activate("/home/user/.julia/environments/v1.5") #use the correct path

You need to use the directory path exactly the same that Julia is using (this is the folder where Project.toml is stored). To check what is the correct path run in Julia:

julia> using Pkg; Pkg.activate()
 Activating environment at `/home/user/.julia/environments/v1.5/Project.toml`

Last but not least, for the best results I recommend using the Python Anaconda that gets installed together with Julia (using Pkg; Pkg.add("PyCall");Pkg.add("Conda");using Conda;Conda.add("whateveranacondapackageyouneed")). It gets installed to your Julia folder and the Anaconda version that gets installed this way has been tested against integration issues.

Upvotes: 4

Related Questions