# How to properly create, activate, and resume, an environment in VSCode

**URL:** <https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289>\
**Category:** VS Code\
**Tags:** question\
**Created:** [October 13, 2020, 11:12am UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289 "2020-10-13T11:12:46Z")\
**Posts on this page:** 9\
**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:** [October 13, 2020, 11:12am UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/1 "2020-10-13T11:12:46Z")

</div>

I am trying to create a new Julia environment in VSCode, and run some stuff from it. However, I have a feeling that I might not have really grasped how to do this properly. It would be good if someone could have a look at my workflow.

- First I create a new folder on my desktop; “My\_New\_Project”.
- Next, I open VSCode. It opens with a terminal open. Checking with `ls` there, it seems to be in my home directory. I write `cd Desktop/My_New_Project` to change the folder to where I want my new environment.
- Next, I open a Julia REPL. Checking with `pwd()` it seems to be in my home folder. I run `; cd Desktop/My_New_Project` to move Julia to my desired project folder.
- I then run `] activate .` to activate the folder as a new Julia project.
- I run `] add DifferentialEquations, ModelingToolkit, Catalyst, Plots` to add the packages I require for my project.
- I check with `] status` that indeed only these packages are active in my environment.
- I run `] dev ModelingToolkit`, because I require the master of the ModelingToolkit package (I have the latest version pulled to my “.julia/dev” folder.
- I now close VSCode (reasons unknown, but sometimes you require to close it, and I initially had some trouble with resuming stuff).
- I now repeat the steps 2-4. Here, running `] activate .` again allows me to resume the previous environment? Running `] status` seems to confirm that.

Is this the proper/correct way of doing things? Is there some smoother way of doing things?

---

<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:** [October 13, 2020, 1:02pm UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/2 "2020-10-13T13:02:59Z")

</div>

Also, a follow-up. Part of the project I would like to do in jupyter notebooks. Here I open a jupyter notebook, navigate to “Desktop/My\_New\_Project”, and create a new notebook there. Checking with

```julia
using Pkg
Pkg.status()

```

this notebook seems to be in this new environment. It seems jupyter notebooks automatically detect it, but VSCode requires you to specifically activate each time?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 13, 2020, 3:28pm UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/3 "2020-10-13T15:28:39Z")

</div>

I believe there is a project setting (workspace setting? not sure about the terminology) that remembers the active project in VS code.

---

<div class="post-metadata">

**Author:** ![lyonsquark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lyonsquark/32/4483_2.png) [@lyonsquark](https://discourse.julialang.org/u/lyonsquark)\
**Post date:** [October 13, 2020, 3:45pm UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/4 "2020-10-13T15:45:56Z")

</div>

From my experience, the environment that VSCode’s Julia extension (I’ll just call this VSCode) knows about is independent of the environment that the Julia REPL knows about. The steps you describe are you establishing and maintaining an environment with the Julia REPL (e.g. manipulating the Project.toml and Manifest.toml files for your directory). What you write looks good to me for selecting the environment and adding packages from the REPL.

If you want VSCode to use that environment for its Intellisense, then you must tell VSCode that. If you have a Julia file loaded in VSCode, you’ll see a “Julia env: …” thing in the status bar (bottom of the window). That’s the environment that VSCode is using. I’ve noticed that VSCode can figure out to use the environment for a project - but not always (I haven’t looked at this carefully enough to learn when it does and doesn’t). But you can always tell it … just click on that “Julia env:…” thing on the status bar and it will ask you to select the directory with the environment you want. It’ll then run the language server indexing and will set up Intellisense. This works well. Note that if you change the environment (e.g. add packages), VSCode will not notice the new packages. Follow the procedure here and select the directory again. That will trigger a re-indexing by the language server and then Intellisense will work for the new packages you added.

This may seem a little clunky - but I’ve gotten used to it and it works well. Keeping your eye on “Julia env:…” in the status bar and clicking on it when necessary is the key to making VSCode understand the environment you want. Hope this helps. – Adam

---

<div class="post-metadata">

**Author:** ![lyonsquark](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lyonsquark/32/4483_2.png) [@lyonsquark](https://discourse.julialang.org/u/lyonsquark)\
**Post date:** [October 13, 2020, 3:48pm UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/5 "2020-10-13T15:48:49Z")

</div>

… and I forgot to mention that VSCode will remember the environment you selected for that project.

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [October 13, 2020, 7:42pm UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/6 "2020-10-13T19:42:13Z")

</div>

My standard workflow looks like this (I’m on Windows):

Open PowerShell then:

- `cd wherever/I/want/my/project`

- `mkdir ProjectName`

- `cd ProjectName`

- `code .`

Now, VS Code will be open in the directory that I just created. I open a Julia REPL from the VS Code menu and then

- ] to enter the package manager

- `activate .`

- `add Whatever Packages Are Needed`

After adding packages I have a Project.toml so I click in the lower left:

![image](https://global.discourse-cdn.com/julialang/original/3X/6/4/64019137290204bbd65d70441b6b55547621b3f4.png)

and select the environment ProjectName. Now, every time I want to go back to this project and continue working on it I simply `cd` into it via PowerShell and type the `code .` command and it will open in VSCode and the correct environment will be automatically loaded since there is a Project.toml.

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [August 5, 2021, 2:06pm UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/7 "2021-08-05T14:06:22Z")

</div>

UPDATE: I wrote [a simple little command line utility](https://github.com/mthelm85/jeeves) with Rust to take care of this for me. My new work flow looks like this:

Open PowerShell, then:

- `cd wherever/I/want/my/project`
- `jeeves ProjectName`
- `cd ProjectName`
- `code .`

Done!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [August 6, 2021, 10:56pm UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/8 "2021-08-06T22:56:07Z")

</div>

@mthelm85, jeeves simplicity looks pretty cool. Thank you.

As an alternative to edit the Windows PATH, found useful to copy `jeeves.exe` to `Program Files` folder and to define in the PowerShell:

```nohighlight
Set-Alias -Name jeeves -Value "C:\Program Files\jeeves.exe"

```

This alias can be made permanent by saving it to a PowerShell **profile.ps1** startup [file](https://stackoverflow.com/questions/24914589/how-to-create-permanent-powershell-aliases).

Also, it is handy to set PowerShell’s default starting directory as explained [here](https://stackoverflow.com/a/38375707/14071775).

---

<div class="post-metadata">

**Author:** ![mthelm85](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mthelm85/32/224164_2.png) [@mthelm85](https://discourse.julialang.org/u/mthelm85)\
**Post date:** [August 7, 2021, 12:21am UTC](https://discourse.julialang.org/t/how-to-properly-create-activate-and-resume-an-environment-in-vscode/48289/9 "2021-08-07T00:21:15Z")

</div>

I did not know about `Set-Alias`, that’s awesome! Thank you! 🙂
