2

Typically when opening and running a file in an IDE, the current path would be the residing path of the file, i.e. the location that file resides. For some reason, experience tells this is not the case in JUNO for Julia language (Edit: in Windows).

The consequence is that one receives a several errors due to unfound files unless they set the path manually.

How can one fix this?

Why is that?

2
  • 1
    What operating system? This used to occur in Windows but was fixed after some updates. I don't know if those updates are in the tagged version though. See the Juno Gitter for help. Jul 22, 2016 at 4:31
  • @Chris In Windows OS.
    – user25004
    Jul 22, 2016 at 20:36

2 Answers 2

5

Julia and Juno both work the same way in terms of the working directory. It's set when you start Julia and stays the same until you call cd – it's not determined by the running file at all.

How does it get chosen, then? The julia command inherits it from the terminal, so running:

julia script.jl

will work in script.jl's folder whereas

julia dir/script.jl

will work in the folder above that one. It's just the folder that you launched Julia from, and again the location of the script itself makes no difference.

When Juno boots Julia it has to choose what folder to launch it in, and it uses your "project folder" – that is, the folder that you currently have open. Simple enough, but might cause issues if you're relying on pwd() and your script is in a subdirectory of your project folder.

The simple solution to this is to avoid relying on pwd() at all and to use @__FILE__ instead, which will always refer to the currently executing file. For example,

readcsv(joinpath(dirname(@__FILE__), "data.csv"))

This is the most idiomatic way to load local files in Julia, but if you're really set on using pwd() then you can also easily change the working directory using the set of commands starting with Julia Client: Work in ....

1

Not sure if this was your first question or not, but you can use the pwd() function from within the julia terminal to examine your current directory.

As for starting julia in the correct directory you have several options. You could either alter the julia executable called by your IDE (or alternatively, create an alias for it in your .bashrc file) such that julia is called like so:

julia -P "cd(\"/path/to/my/desired/directory\")"

where -P tells julia to execute a command but continue in interpreter mode

Alternatively, you can edit your .juliarc.jl file to add your own custom cd("/my/directory") command in it.

As for JUNO specifically, I'm not aware of any special properties it might have to address this, but if what you're after is to double-click on a .jl file and have it open with juno at the right directory, you can always associate the .jl extension to a small bash script that creates the julia alias on the spot or overwrites your .juliarc.jl file or something along those lines, and then calls Juno on that file :)

4
  • 1
    I have to say I don't get that problem though. I just installed juno to check, and clicking on files starts julia in their current directory. (confirmed with pwd()). Where does your editor start instead? Jul 22, 2016 at 3:08
  • Thanks a lot fro trying this. For me it starts in the immediate parent directory instead of the directory itself. This happens for me in Windows.
    – user25004
    Jul 22, 2016 at 20:40
  • Does that also happen if you move the file somewhere else? It's not just that it starts at a fixed directory? Jul 22, 2016 at 20:46
  • It is not a fixed directory. Happens wherever I move the folder.
    – user25004
    Jul 23, 2016 at 20:35

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.