Using julia.environmentPath to configure environments in VSCode

Does setting julia.environmentPath in vscode allow us to use the correct julia environment? This flag just doesn’t work for me.

Simple test I performed was the following:

(1) I set that flag in launch configuration.json file as well as in settings.json file.

In a test.jl file

using somePackage

println(pathof(somePackage))

When I run test.jl file from vscode, I keep getting the path to package which is not part of the environment I have choosen.

I don’t understand the purpose of this flag if can’t set the environment. If someone could clarify how to set the environment in vscode, I’d appreciate it. Thanks.

1 Like

Until a more knowledgeable person chimes in here’s what I do. I haven’t set up any flags. I just run this code for every project:

dir = expanduser("~/Julia/workspace")
push!(LOAD_PATH, dir)
import Pkg
Pkg.activate(dir)
Base.active_project()

which activates the project that is located in the directory (you need Project.toml and Manifest.toml files).

I tried and it seems to work for me.
After restarting VSCode the set environment is activated and a package I use in the current path (the current didn’t change) is now not found, because it’s not part of the current environment.

Perhaps, the Pkg manager is quite clever, the package you are using is just part of both environments and is the same version, so the path don’t change. AFAIK the pkg manager avoids duplicated installations of the same code/version.

You can try what you have done so far in a plain REPL to check if the path to your package really should change.

1 Like

@ptoche Thanks for this suggestion. I was really hoping some usage of command line flag would work. If I were to run julia from the terminal, with julia_depot_path and julia_project set, everything works fine. I don’t quite understand why this feature of julia was taken away in vscode, which otherwise is an excellent IDE.

1 Like

@oheil I assume you tried the suggestion proposed by @ptoche and it works.

My only concern with the proposed solution is that we will need to create an extra julia file( if we don’t want to pollute the main julia file) to keep the environment and packages that it loads consistent. The job of this extra julia file must have been taken care by launch configuration in vscode in an ideal world. I always thought that was the whole purpose of a “launch configuration”.

Anyhow, thanks to @ptoche for the workaround.

No, I tried what you tried, and it works as expected for me.

@oheil Did you actually try setting julia.environmentPath in launch.json file in vscode and you saw it correctly loads the package defined in that environment? Do you have an example? Thanks.

Edit: I think you are right. It’s the version number that is at play here since I did not modify the version number of the package so it ended up loading the older package.

1 Like

In
C:\Users\Oli\AppData\Roaming\Code\User\settings.json

2 Likes