Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

julia

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?

like image 481
Rita de Cassia Souza Paz Avatar asked Oct 29 '20 01:10

Rita de Cassia Souza Paz


People also ask

How do I use Python package in Julia?

To force Julia to use its own Python distribution, via Conda, simply set ENV["PYTHON"] to the empty string "" and re-run Pkg. build("PyCall") . The current Python version being used is stored in the pyversion global variable of the PyCall module. You can also look at PyCall.

Can I use Python library in Julia?

Julia is a high-level, high-performance, dynamic programming language for numerical computing. Users can import arbitrary Python modules and libraries into Julia.

Where are Julia packages stored?

By default, packages will be installed to ~/. julia/packages . To exit package mode, enter the Backspace key on an empty line.

Can I use NumPy in Julia?

You can call Python as needed, but you'll probably find that almost everything in NumPy and SciPy can be done natively with Julia packages. Definitely this. NumPy and SciPy are necessary in Python to make numerical computing fast, but Julia arrays are far nicer to work with (and I assume just as fast).


Video Answer


1 Answers

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.

like image 79
Przemyslaw Szufel Avatar answered Oct 21 '22 09:10

Przemyslaw Szufel