2

I want to run a Julia file inside a Python Script. The Julia file is

func1.jl

using LowRankApprox

using LinearAlgebra

function f(A)

    F = pqrfact(A)

    M = A * F[:P]

    return M

end

function k(A)

    F = pqrfact(A)

    k = F[:k]

    return k

end

This code is working perfectly in Atom. But I need it to work inside a Python Script. My Python Script is:

import numpy as np

import julia

j = julia.Julia()

j.include("func1.jl")

A = np.array([[1, 3, 1], [1, 1, 1], [2, 1, 1]])

print(j.k(A))

Gives the following error:

FileNotFoundError

I've tried to put the Julia file in several folders but it always gives the same message. If anyone can help me I will be very grateful.

2 Answers 2

2

Your python interpreter is probably not looking for files in the place you expect. Try running the following in python.

import os
print(os.getcwd())

This will tell you where python starts looking for files. If you put your julia file there, your code should work. You can also run os.chdir(os.path.join('path', 'to', 'directory', 'containing', 'julia', 'file')), or j.include(os.path.join('absolute', 'path', 'to', 'func1.jl')).

If you're using Hydrogen to run Python code in Atom, you might want to check out how to change where the Python interpreter starts.

Sign up to request clarification or add additional context in comments.

2 Comments

@emersonDid not work. It keeps giving the same error message.
@RitadeCassiaSouzaPaz I can only suggest that you check the output of os.getcwd() very carefully and make sure that everything is spelled correctly. If you think you know the path to the directory containing func1.jl, you can use os.listdir('path/to/dir') to make sure the file is really there. Good luck!
0

I was able to solve this problem by placing the path in the system variable and with the following code in Python:

import julia from julia.api import Julia

julia.install()

jl = Julia(compiled_modules=False)

j = julia.Julia() j.include('func1.jl')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.