# First steps: Start Julia in a certain folder in VSCode

**URL:** <https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822>\
**Category:** New to Julia\
**Tags:** vscode\
**Created:** [May 10, 2022, 3:13pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822 "2022-05-10T15:13:48Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 10, 2022, 3:13pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/1 "2022-05-10T15:13:48Z")

</div>

Hi (sorry, first day here),

I open a folder and get in the terminal just: PS D\andSoOn\_theFolderPath \>  
To get to Julia (if one can say it like that) I have to run a lin of code of a program in my folder, what am I doing wrong?

If I set my Julia environment in the left corner of VSCode to anything else than my current folder I get the error (That occurs in many other questions as well): Julia package not part of your current environment. Is that bad? It seems to run that way, kind of.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 10, 2022, 9:36pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/2 "2022-05-10T21:36:26Z")

</div>

What is the structure of your code tree?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [May 10, 2022, 11:28pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/3 "2022-05-10T23:28:52Z")

</div>

Some past posts that might help:

> [@Having installed several versions of Julia on machine. How to open a specific version of julia from PowerShell?](https://discourse.julialang.org/t/having-installed-several-versions-of-julia-on-machine-how-to-open-a-specific-version-of-julia-from-powershell/78134/7):
>
> You can also use juliaup for this scenario, see [Julia in the Windows Store | David Anthoff | JuliaCon2021 - YouTube](https://youtu.be/rFlbjWC6zYA). Just make sure you uninstall your other Julia versions before you switch over to using juliaup.

> [@Running .jl file from PowerShell](https://discourse.julialang.org/t/running-jl-file-from-powershell/63462):
>
> Hello, I am having the below error when I am trying to open .jl file from the PowerShell" Any recommendation to solve it? Thanks!

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [May 10, 2022, 11:42pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/4 "2022-05-10T23:42:32Z")

</div>

Hi, welcome!

Have you checked the manual to use Julia in VS Code?  
[https://www.julia-vscode.org/docs/stable/](https://www.julia-vscode.org/docs/stable/)

If I got it right, you are stuck in the very first action: how to open a Julia REPL to run commands. You have the specific instructions for that in this page:  
[https://www.julia-vscode.org/docs/stable/userguide/runningcode/](https://www.julia-vscode.org/docs/stable/userguide/runningcode/)

Shortcut: Alt+J, Alt+O normally starts a Julia REPL, unless you have a particular configuration that changes such keybinding.

---

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 11, 2022, 11:19am UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/5 "2022-05-11T11:19:06Z")

</div>

Hi,

my Path is for example this folder saved somewhere

> **[GitHub - JuliaPackageMirrors/PowerModels.jl: Julia package mirror.](https://github.com/JuliaPackageMirrors/PowerModels.jl)**
>
> Julia package mirror.

From the question:

> [@WARNING: using x.x in module Main conflicts with an existing identifier](https://discourse.julialang.org/t/warning-using-x-x-in-module-main-conflicts-with-an-existing-identifier/80819):
>
> Hi, this is basically my first day with Julia. I know that this question came up a few times in different context, but I did not really think the answers there where helpful. I tried to get random program and run it. I tried this with two different programs and got a similar error. My plan was to get code and learn from it. My choice (but the topic of the code doesnt matter, this one is just one I should understand and the README is super easy… so I thought): I startet with “] activate .” a…

All I wanted is to run a Julia file, thats it. The example I tried is the link (PowerModels, but any would work for me, I just need an example), it does have a Project and Manifest file. I am in the right path, I guess, and I did activate and instantiated (what I think is the current folder with those files).

So to back up to the absolut beginning in VS Code: “File” → “Open Folder” and my Terminal Commant line shows PS D:\Daten\Julia\PowerModels.jl-master\>  
(… the cd(“D:\Daten\Julia\PowerModels.jl-master”) command then does nothing, right? But I should be in the working directory) I can change the environment in the left corner of VSCode and chose “C:\users\myName.julia\environments\v1.7”, but that doesnt help … and typing in “using Pkg” doesnt work in any case.  
Runing one line of Code by Ctrl+enter in a file in that folder starts Julia and I can type in using Pkg and then activate and so on…

That cant be the way, right?  
But that is also another problem due to inexperience, I hope.

I just want to run the Code, shown in the read me:

## Basic Usage

Once PowerModels is installed, Ipopt is installed, and a network data file (e.g. “nesta\_case3\_lmbd.m”) has been acquired, an AC Optimal Power Flow can be executed with,

**using PowerModels**  
**using Ipopt**  
**run\_ac\_opf(“nesta\_case3\_lmbd.m”, IpoptSolver())**

---

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 11, 2022, 11:22am UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/6 "2022-05-11T11:22:22Z")

</div>

Hello,

I have, but I will dig deeper, my specific Problem is posted as an answer to PetrKrysIUCSD here in this discussion, maybe thet helps to clarify. But I will dig deeper.  
The way I try it seems just too hard for just running code.

---

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 11, 2022, 11:23am UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/7 "2022-05-11T11:23:41Z")

</div>

Hi,

thank you, I will look into it.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [May 11, 2022, 11:25am UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/8 "2022-05-11T11:25:39Z")

</div>

Is there any reason to be using a six year old package that probably doesn’t work on recent Julia versions anways? I’d try [GitHub - lanl-ansi/PowerModels.jl: A Julia/JuMP Package for Power Network Optimization](https://github.com/lanl-ansi/PowerModels.jl) instead if I were you.

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [May 11, 2022, 12:04pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/9 "2022-05-11T12:04:22Z")

</div>

> [@BrianOConner](#):
>
> So to back up to the absolut beginning in VS Code: “File” → “Open Folder” and my Terminal Commant line shows PS D:\Daten\Julia\PowerModels.jl-master\>

That is the PowerShell terminal, nothing to do with Julia. What you are looking for is the REPL (which shows the `julia>` prompt), and you have to start it manually. That can be done in (at least) three ways:  
a. Run the command “Julia: Start REPL” (from the command palette: Ctrl+Shift+P).  
b. Default keybinding: Alt+J, Alt+O.  
c. Run some code in the editor (the way you actually did it).

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 11, 2022, 12:35pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/10 "2022-05-11T12:35:46Z")

</div>

Well, I open a normal terminal in vscode and start julia from that terminal… Faster and easier for me than using the Julia REPL from vscode…  
And to run an example I just use the command

```julia
include "src/my_code.jl" 

```

or whatever…

---

<div class="post-metadata">

**Author:** ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Post date:** [May 11, 2022, 12:50pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/11 "2022-05-11T12:50:21Z")

</div>

Yes, that works, but other components of the VS Code Julia extension (inline execution, variable explorer, plot panel, automatic recognition of sysimage…) won’t be linked to what you do in that terminal. That’s ok if you like it like that, but may be confusing for new users who have read about those features.

---

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 11, 2022, 1:17pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/12 "2022-05-11T13:17:07Z")

</div>

Hello,

there is not. Nice that you looked that up, but it was just an example and does therefore not tackle the main problem.  
The new Version does look very interesting though, thx.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 11, 2022, 1:42pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/13 "2022-05-11T13:42:32Z")

</div>

How about giving [GitHub - PetrKryslUCSD/VSCode\_Julia\_portable: Portable Julia running in VSCode](https://github.com/PetrKryslUCSD/VSCode_Julia_portable) a shot?

---

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 11, 2022, 1:50pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/14 "2022-05-11T13:50:23Z")

</div>

Well, I do have a set file folder, structure  
Folder(Project,Manifest,src(file1,file2),examples(example1,example2)).  
I cannot just klick in examples, in example1 and go to “Run”.

include(“examples/example1.jl”) does not work, e.g. this and a 100 other Errors occur:  
ERROR: LoadError: UndefVarError: VariablesContainer not defined

I am kind of confused.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 11, 2022, 6:33pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/15 "2022-05-11T18:33:07Z")

</div>

Does it work if you just use the REPL without VSCode?  
Can you share your file example1.jl?

---

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 24, 2022, 10:03am UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/16 "2022-05-24T10:03:53Z")

</div>

Thank you a lot, I will try it out, hopefully it helps.

---

<div class="post-metadata">

**Author:** ![BrianOConner](https://avatars.discourse-cdn.com/v4/letter/b/c2a13f/32.png) [@BrianOConner](https://discourse.julialang.org/u/BrianOConner)\
**Post date:** [May 24, 2022, 10:09am UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/17 "2022-05-24T10:09:20Z")

</div>

In [WARNING: using x.x in module Main conflicts with an existing identifier](https://discourse.julialang.org/t/warning-using-x-x-in-module-main-conflicts-with-an-existing-identifier/80819) my problem occurs. Basically, the problem seems to be, that I cnt really operate in Julia and I try to fix that. I just want any Code from Github with everythin included, e.g. Manifest, Projekt, a src-folder and maybe some other folders with example programs. I then want to run that without havin problems and I dont get there. Maybe its because the Code is wrong, but I dont think that. [PetrKryslUCSD] just send me an example and I will try that first.  
Sorry for asking so basic things!

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [May 24, 2022, 12:07pm UTC](https://discourse.julialang.org/t/first-steps-start-julia-in-a-certain-folder-in-vscode/80822/18 "2022-05-24T12:07:46Z")

</div>

Well, first of all do NOT checkout PowerModuls.jl or any other package you want to use from git. (Unless you want to modify it). Do NOT use the Project.toml file from any package, create your own instead.  
Example:

```julia
mkdir test
cd test
julia --project="."
using Pkg
pkg"add PowerModels"
pkg"add Ipopt"

```

Now you have a project folder with the package PowerModels and Ipopt installed (and with no other package, so no conflicts).

Now quit Julia (ctrl+d) and create a folder with your examples:

```julia
mkdir examples
cd examples
gedit first_example.jl

```

(Or use your favorite editor instead of gedit).  
Paste the following lines into the editor:

```julia
using PowerModels
using Ipopt

solve_ac_opf("matpower/case3.m", Ipopt.Optimizer)

```

Save the file.  
Go back to the project directory and have a look what is there:

```julia
cd ..
tree

```

The output should look like:

```julia
ufechner@tuxedi:~/repos/tmp$ tree
.
├── examples
│ └── first_example.jl
├── Manifest.toml
└── Project.toml

```

Now start Julia and run the example:

```julia
julia --project
include("examples/first_example.jl")

```

I suggest that beginners should learn to use the REPL first, when they know how to use it they can switch to vscode… vscode is more difficult to explain and has a lot of settings that you can set wrongly.

Another problem is that this example from the quickstart guide of the package PowerModels does not work. I created an issue in the package: [Example does not work · Issue #826 · lanl-ansi/PowerModels.jl · GitHub](https://github.com/lanl-ansi/PowerModels.jl/issues/826)

To fix the example, create a folder matpower, put the following file into it: [https://raw.githubusercontent.com/power-grid-lib/pglib-opf/master/pglib\_opf\_case5\_pjm.m](https://raw.githubusercontent.com/power-grid-lib/pglib-opf/master/pglib_opf_case5_pjm.m) and rename it to case3.m

The directory structure now looks like this:

```julia
ufechner@tuxedi:~/repos/tmp$ tree
.
├── examples
│ └── first_example.jl
├── Manifest.toml
├── matpower
│ └── case3.m
└── Project.toml

```

And Project.toml looks like this:

```julia
ufechner@tuxedi:~/repos/tmp$ cat Project.toml 
[deps]
Ipopt = "b6b21f68-93f8-5de0-b562-5493be1d77c9"
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"

```

Now I could run the example and get the output:

```julia
EXIT: Optimal Solution Found.
Dict{String, Any} with 8 entries:
  "solve_time" => 3.35954
  "optimizer" => "Ipopt"
  "termination_status" => LOCALLY_SOLVED
  "dual_status" => FEASIBLE_POINT
  "primal_status" => FEASIBLE_POINT
  "objective" => 17551.9
  "solution" => Dict{String, Any}("baseMVA"=>100.0, "branch"=>Dict{St…
  "objective_lb" => -Inf

```

Another source of confusion might be that you were linking to an old version of PowerModels from a mirror. Do NOT use outdated versions, always use the original.
