julia-vscode icon indicating copy to clipboard operation
julia-vscode copied to clipboard

Unable to set/change Julia environment in vscode

Open amrit-poudel opened this issue 2 years ago • 12 comments

vs code (v 1.63) in macosx 11.6 does not seem to recognize Julia (v 1.6.4) environment despite setting the environment everywhere in settings.json file (bother user and workspace), launch.json file under the project dir which contains the Julia file I am trying to run. Also tried changing/setting the Julia environment by clicking on the 'Julia env:' at the bottom of the vscode GUI to no avail. I have tried closing/opening, julia, vscode and my computer multiple times but nothing seems to work. I am just not sure why simply defining julia.executablePath and julia.environmentPath in settings.josn and launch.json files are not enough for vscode to use the right Julia environment. (The same approach seems to work perfectly with Python in vscode).

I created two julia environments: ~/.julia and ~/.julia_dev, of course for the purpose of testing. I did so by first defining JULIA_DEPOT_PATH environment variable in the terminal (in bash shell : export JULIA_DEPOT_PATH=/path/to/.julia or export JULIA_DEPOT_PATH=path/to/.julia_dev)

Then I added' MyAlgebra' package to both of them switching to pkg mode and all that. Confirm that package is added. Activated the env to create project and manifest toml files.

Then tried running a simple one-liner test.jl file in vscode:

test.jl

using MyAlgebra

println(pathof(MyAlgebra))

This always returns the ~/.julia/... instead of ~/.julia_dev, even when I specify julia.environmentPath = "/path/to/.julia_dev/environments/v1.6"

Thanks for any help in resolving this issue!

amrit-poudel avatar Dec 15 '21 23:12 amrit-poudel

Would really appreciate any comment/feedback on this. Setting julia.environmentPath in launch.json file or settings.json file does not seem to be using the environment pointed by julia.environmentPath. Thanks for building this great extension. It is super useful!

amrit-poudel avatar Dec 20 '21 20:12 amrit-poudel

Pretty sure you need to set the active environment manually in the REPL (or with Pkg.activate(...)).

pfitzseb avatar Dec 22 '21 14:12 pfitzseb

Thanks for that note. If that is the case, what exactly is the purpose of julia.environmentPath variable in vscode? Am I misunderstanding the usage of this flag in vscode? My understanding was that in order to run a julia code/notebook, we need two things: (1) julia binary (set in PATH, along with dynamic libraries set in LD_LIBRARY_PATH) and (2) environment (characterized by toml and manifest files), which define all necessary libraries needed to run the julia notebook. I'd really appreciate if you could clarify the purpose of this flag in vscode. Thanks for your help!

amrit-poudel avatar Dec 22 '21 17:12 amrit-poudel

@pfitzseb, julia.environmentPath does not seem to do anything. What is the purpose of this flag?

amrit-poudel avatar Dec 28 '21 22:12 amrit-poudel

No idea. Just ignore it :P

pfitzseb avatar Jan 03 '22 07:01 pfitzseb

This is the setting where the active Julia project (that one can select in the UI) is stored. It determines what environment LS is using, plus pretty much every other part of the extension. If you start a new REPL, it will auto-active the env in that setting. The normal way to change this setting is via the env selection UI, and the setting then gets stored in a workspace setting.

davidanthoff avatar Jan 03 '22 08:01 davidanthoff

Would it be feasible / there be interest to add two UI settings to effectively set JULIA_DEPOT_PATH and JULIA_PKG_DEVDIR, and use that when launching Julia/juliaup? It's questionable to change those after loading Julia, and while locally I can set them before launching VSCode that doesn't work for remote sessions. Furthermore, juliaup uses JULIA_DEPOT_PATH so that would require a way to set it before Julia is even launched.

It would be nice if VSCode supported workspace environment variables, but that's not being worked on: https://github.com/microsoft/vscode/issues/69233

maleadt avatar Jul 27 '22 20:07 maleadt

It's questionable to change those after loading Julia, and while locally I can set them before launching VSCode that doesn't work for remote sessions.

You can set that for remote sessions, just need to switch to the right settings tab.

pfitzseb avatar Jul 27 '22 20:07 pfitzseb

You can set that for remote sessions, just need to switch to the right settings tab.

Which setting do you mean?

maleadt avatar Jul 27 '22 21:07 maleadt

terminal.integrated.env.linux

pfitzseb avatar Jul 27 '22 21:07 pfitzseb

terminal.integrated.env.linux

Ah, interesting! That seems to work fine for e.g. a Bash terminal in a remote VSCode session, but somehow doesn't apply for the Julia REPLs spawned there. Also, the environment drop-down is still looking in ~/.julia, not in my custom depot.

To have this work both remotely and locally, would it work to add this in the same way that the extension e.g. allows setting JULIA_PKG_SERVER? Or are there reasons not to do this?

maleadt avatar Jul 27 '22 21:07 maleadt