# Make Julia VSCode use Manifest.toml and Project.toml files from the folder of script being run

**URL:** <https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046>\
**Category:** VS Code\
**Tags:** pkg, package-manager\
**Created:** [June 1, 2022, 10:36am UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046 "2022-06-01T10:36:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [June 1, 2022, 10:36am UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/1 "2022-06-01T10:36:06Z")

</div>

I have a folder with a “Manifest.toml” and a “Project.toml” file. I also have a script, “my\_julia\_script.jl”. I open the script and run some stuff. However, it seems to use the general julia environment. I want it to use the one define by the local “Manifest.toml” and a “Project.toml” files. Is there some setting to make this default?  
(or some way to manually make this happen?)

---

<div class="post-metadata">

**Author:** ![trilobit](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@trilobit](https://discourse.julialang.org/u/trilobit)\
**Post date:** [June 1, 2022, 12:01pm UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/2 "2022-06-01T12:01:44Z")

</div>

You have to activate your project.

```julia
using Pkg
cd(Base.source_dir()) # Changes into the directory , where your "my_julia.jl" is.
Pkg.activate(".") # active the project, with a static environment
# Pkg.activate(; temp=true) # activate the project with a temporary environment
Pkg.update() # update the ..tom-files

# [here starts your code]

```

If you need an individual sysimage(it can be faster), you can create a sysimage in the VSC

1. active in the settings of VSC the checkbox of:  
“Julia: Use Custom Sysimage”

2. in the left side of the status line in the VSC choose the environment of your project  
i.e.  
julia env: v1.7…to your folder, where you “my\_julia\_script.jl”, is  
Needed for the PackageCompiler, that he can generate the sysimage in your specific  
project-directory.

3. Press: [Ctrl]+[Shift]+[B] and let VSC build your sysimage.  
(An installation of the PackageCompiler is NOT needed).

To start your “my\_julia\_script.jl” with your individual project sysimage  
press the usual [Alt]+[J]+[Alt]+[O]

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [June 1, 2022, 12:22pm UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/3 "2022-06-01T12:22:02Z")

</div>

You can run the command “Julia: Activate this environment” by pressing “Shift+Ctrl+p” and entering that string. This will activate any existing environment in the current folder open in vscode. There is also “Julia: Change current environment” where you can set which environment you want at some location on disk.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [June 1, 2022, 1:06pm UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/4 "2022-06-01T13:06:07Z")

</div>

> [@trilobit](#):
>
> ```julia
> using Pkg
> cd(Base.source_dir()) # Changes into the directory , where your "my_julia.jl" is.
> Pkg.activate(".") # active the project, with a static environment
> 
> ```

The normal invocation if you want a script to activate its local environment (independently of VSCode functionality) is

```julia
using Pkg
Pkg.activate(@ __DIR__ )

```

This has the advantage of not using a non-exported and undocumented internal function, as well as not changing the current directory.

> [@trilobit](#):
>
> ```julia
> # Pkg.activate(; temp=true) # activate the project with a temporary environment
> 
> ```

That comment is strange. It would activate a temporary environment, period, with no relation to the local project files.

> [@trilobit](#):
>
> ```julia
> Pkg.update() # update the ..tom-files
> 
> ```

Notice that this loses the reproducibility advantage of the Manifest file. If you prefer reproducibility over updated packages you can do `Pkg.instantiate()` to make sure that you, or someone else running the script, have the necessary packages available.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [June 1, 2022, 3:49pm UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/5 "2022-06-01T15:49:18Z")

</div>

I talked to someone who mentioned there was some VSCode setting where one could have scripts automatically use the local environment if there is any (thus avoiding having to run a command at the beginning of every session). Is there such a setting?

---

<div class="post-metadata">

**Author:** ![trilobit](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@trilobit](https://discourse.julialang.org/u/trilobit)\
**Post date:** [June 1, 2022, 3:53pm UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/6 "2022-06-01T15:53:13Z")

</div>

```julia
using Pkg
Pkg.activate(@ __DIR__ )

```

I dont know that, but many thanks for that tip.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [June 2, 2022, 1:25pm UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/7 "2022-06-02T13:25:34Z")

</div>

I got a summary from Sebastian Pfitzner on slack.

Basically, VSCode will automatically use the environment of the (top) folder you opened in it. In my case, the top folder doesn’t contain an environment, and by script is in a subfolder, so the default environment is used. However, by right-clicking on that folder, I can select to use that environment instead.

---

<div class="post-metadata">

**Author:** ![benz0li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benz0li/32/37040_2.png) [@benz0li](https://discourse.julialang.org/u/benz0li)\
**Post date:** [June 17, 2022, 7:46am UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/8 "2022-06-17T07:46:39Z")

</div>

I have the following `~/.julia/config/startup.jl` in place, which also works when using the command line interface (CLI) or Jupyter Notebooks:

```julia
println("Executing user-specific startup file (", @ __FILE__ , ")...")

try
    using Revise
    println("Revise started")
catch e
    @warn "Error initializing Revise" exception=(e, catch_backtrace())
end

if isfile("Project.toml") && isfile("Manifest.toml")
    Pkg.activate(".")
else
    Pkg.activate("$(ENV["HOME"])/.julia/environments/v$(VERSION.major).$(VERSION.minor)")
end

```

 ![JupyterLab-CLI](https://global.discourse-cdn.com/julialang/original/3X/c/1/c1684da591c75ee7abcf858521b6baac5750a8b3.png)

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [June 17, 2022, 8:41am UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/9 "2022-06-17T08:41:01Z")

</div>

That looks really neat! Thanks!

---

<div class="post-metadata">

**Author:** ![benz0li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benz0li/32/37040_2.png) [@benz0li](https://discourse.julialang.org/u/benz0li)\
**Post date:** [June 17, 2022, 1:32pm UTC](https://discourse.julialang.org/t/make-julia-vscode-use-manifest-toml-and-project-toml-files-from-the-folder-of-script-being-run/82046/10 "2022-06-17T13:32:25Z")

</div>

P.S.: `/opt/julia/etc/julia/startup.jl` containing the following:

```julia
# This file should contain site-specific commands to be executed on Julia startup;
# Users may store their own personal commands in `~/.julia/config/startup.jl`.

println("Executing site-specific startup file (", @ __FILE__ , ")...")

push!(LOAD_PATH, "$(ENV["JULIA_PATH"])/local/share/julia/environments/v$(VERSION.major).$(VERSION.minor)")

using Pkg

```

Some packages (`IJulia`, `LanguageServer`, `Revise`, etc.) being pre-installed in a shared system directory at `/opt/julia/local/share/julia`.
