So whenever i click run this REPL seems to be the default and it runs a bit a too slow and when i have something that requires input then it just gets stuck. On top of that the other way which is run “Run file in new Process”, this works but in every loop i need to specify local and global but if i run julia and run same code in terminal it will work without the need of all that so what is that doing differently and also it feels like it’s compiling or something because it also take longer to start than just copy pasting code in terminal. What i want to know and couldnt figure out is there a way to just make the run button run it in vscode same as when am running a python code for example? i tried removing this REPL option totally but i didn’t manage to do that.
Well, the REPL is very nice and powerful. If you come from Python, you need to change your workflow anyways. One reason is that loading packages in Julia can take some time, and it is better to keep the REPL open and then just type:
include("src/myscript.jl")
to run a script. And if you want to run it again <UP ARROW><ENTER> is sufficient due to the nice command line history. Furthermore you can use the <TAB> key to autocomplete the line that you are typing.
I am not using any of the fancy VSCode buttons to run Julia scripts. Instead, I use a Bash shell (Terminal->new Terminal in the menu), launch Julia with julia --project
or a custom Bash shortcut and then run my scripts as explained above.
See also: Working with Julia projects | Julia programming notes
Sorry for not answering your question but suggesting a different workflow instead. And welcome in the Julia community!
Thank you so much for the reply.
Is it normal when i first run the code in REPL that it keeps “Evaluating” for like a loong time?
I guess that depends on the code you are trying to run. Can you share it?
And if you share code, please do not share a screenshot, but instead copy-and-paste the code and include it in triple backticks, like ``` .
n = parse(Int, readline())
i = 0
while i < n
println("$(i^2)")
global i += 1
end
I first launched a terminal using the VSCode menu, and then typed:
ufechner@framework:~/repos $ julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.7 (2024-11-26)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
julia> n = parse(Int, readline())
2
2
julia> i = 0
0
julia> while i < n
println("$(i^2)")
global i += 1
end
0
1
There was no delay apart from the fact that readline()
waits for user input, so I typed 2 <ENTER>
.
Yes!! Same for me, but my problem is with the “Execute active file in REPL” in VSCode, when i do that then the Julia REPL terminal appears and the evaluating thing starts.
I never use this command, so someone else has to comment on that.
Okay, Thank you so much sir for replying and the for the help. I hope you have a lovely evening.
Hi @Elias_Al_Alam , welcome to the community! I’ve edited your title to be a bit less sharply worded — so that any contributors are more likely to focus on the content and not the title — I hope that’s ok.
Yes, thank you, sorry i was really frustrated. Apologies.
Have just checked and the readline()
seems to be the issue, i.e., the REPL starts just fine and then waits for your input (as you did not print a prompt this is hard to see and as your code is not done at that point the IDE shows evaluating).
Now, for some reason the input needs to be repeated twice … don’t know why, but could be a bug in the REPL confusing inputs.
In any case, I would also suggest a different workflow:
- Start a REPL using
Julia: Start REPL
from the command menu - Select and send code to the REPL via Shift+Enter
Seems the confusing behaviour of readline()
also occurs in this case though … typing the code into the REPL directly works as expected.
Thank you so much; Yes it worked!! If i open REPL Julia: Start REPL
and then in the new opened REPL i use the command ``ìnclude(“directory location”)``` sir @ufechner7 gave me then the code runs quick and without any problems at all. Thank you both.
It is a long known bug in the julia vscode extension that reading input like that doesn’t work correctly when running code blocks through the extension and not directly from the repl. It has something to do with asynchronous tasks that don’t interact well together