# How to run Julia project in VS Code?

**URL:** <https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213>\
**Category:** New to Julia\
**Created:** [April 8, 2022, 7:45am UTC](https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213 "2022-04-08T07:45:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![derakhshani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derakhshani/32/35316_2.png) [@derakhshani](https://discourse.julialang.org/u/derakhshani)\
**Post date:** [April 8, 2022, 7:45am UTC](https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213/1 "2022-04-08T07:45:17Z")

</div>

Hey all,

Sorry for the simple question. I’m pretty new to Julia and I’m struggling with opening a project in VS Code. The project in question is:  
[https://github.com/qojulia/QuantumOptics.jl](https://github.com/qojulia/QuantumOptics.jl)

I downloaded the project, installed Julia and its extension on VS Code, opened the master folder, tried to run master.jl via “Execute File in REPL” but I keep getting errors like:

```julia
UndefVarError: Operator not defined
Stacktrace:
 [1] top-level scope

```

Could someone help me please? Thank you

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [April 8, 2022, 8:30am UTC](https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213/2 "2022-04-08T08:30:01Z")

</div>

Hey! Sorry if I am misunderstanding your intentions.

`QuantumOptics.jl` is a so called package. It is meant to be installed via the package manager. In particular, a package defines its external dependencies and the package manager will resolve them for you.

I would highly recommend to read about Julia’s package manager here  
[https://pkgdocs.julialang.org](https://pkgdocs.julialang.org)

Since the package is filed in Julia’s package registry, issuing  
`] add QuantumOptics` from the REPL is enough to install it. Note that there is no need to manually clone or download the files from GitHub.

After installation has finished, `using QuantumOptics` will make the functionality available in the running Julia session. This will essentially load the package by executing the file `src/QuantumOptics.jl` – not `master.jl` like you tried. When trying to run `master.jl` first, a lot of code that should have been loaded first hasn’t, and hence the error you got.

If you are looking to use the functionality the package offers e.g as demonstrated in the docs [Tutorial · QuantumOptics.jl](https://docs.qojulia.org/tutorial/), there is nothing more to do.

If you want to dig into the source and potentially make changes or extend it, I would recommend using the package manager to “develope” the package: `] dev QuantumOptics` will clone from GitHub, resolve dependencies and make the source files available under `~/.julia/dev/QuantumOptics`, although you are free to change that path.  
So you could now open that folder in VSCode, start a Julia REPL, and load the package as above with `using QuantumOptics` while browsing around the source and changing things.

In all of this, it is usually wise to keep separate environments for different projects. It helps to reduce potential dependency clashes massively. Maybe you are familiar with virtual environments in Python. Julia has a similar mechanism. It is detailed in the Pkg manual linked above and a very recommended read.

---

<div class="post-metadata">

**Author:** ![derakhshani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derakhshani/32/35316_2.png) [@derakhshani](https://discourse.julialang.org/u/derakhshani)\
**Post date:** [April 8, 2022, 9:02am UTC](https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213/3 "2022-04-08T09:02:02Z")

</div>

Thank you so much for the quick reply. I followed your steps and got through the installation. After installation I hit delete (on Mac) to go back to julia\> and executed `using QuantumOptics` but when I type in `src/QuantumOptics.jl` afterwards, I get the following error:

```julia
ERROR: UndefVarError: jl not defined
Stacktrace:
 [1] getproperty(x::Module, f::Symbol)
   @ Base ./Base.jl:35
 [2] top-level scope
   @ REPL[11]:1

```

Thank you for the reply once again.

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [April 8, 2022, 9:18am UTC](https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213/4 "2022-04-08T09:18:09Z")

</div>

Why are you doing `src/QuantumOptics.jl` in the first place? After `using ...` the code is loaded, the file has been executed. You can use the package now as it is described in the manual.

You may want to open the file in e.g. VSCode to inspect what it is doing.

Can you explain what it is you are trying to achieve?

---

<div class="post-metadata">

**Author:** ![derakhshani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/derakhshani/32/35316_2.png) [@derakhshani](https://discourse.julialang.org/u/derakhshani)\
**Post date:** [April 8, 2022, 9:24am UTC](https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213/5 "2022-04-08T09:24:15Z")

</div>

> [@skleinbo](#):
>
> src/QuantumOptics.jl

I’m trying to open some of their examples to test them out myself. I ended up installing a dozen packages (as they were suggested in the errors), so after all that, trying to run QuantumOptics.jl I get the following error:

```julia
WARNING: replacing module QuantumOptics.
Main.QuantumOptics

```

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [April 8, 2022, 9:33am UTC](https://discourse.julialang.org/t/how-to-run-julia-project-in-vs-code/79213/6 "2022-04-08T09:33:58Z")

</div>

```julia
WARNING: replacing module QuantumOptics.
Main.QuantumOptics

```

this comes about because the module was already defined after `using QuantumOptics`.

But you want something else. The example are not defined anywhere in the package source. The package defines the functions used in the examples, e.g. [Pumped cavity · QuantumOptics.jl](https://docs.qojulia.org/examples/pumped-cavity/)

You should copy-paste from there, or look at [https://github.com/qojulia/QuantumOptics.jl-examples](https://github.com/qojulia/QuantumOptics.jl-examples) Clone that repo and run those notebooks. For that you will need to install the Julia kernel for Jupyter called [`IJulia`](https://github.com/JuliaLang/IJulia.jl). Ignore the statements in the README about converting the notebooks to markdown. You can use them interactively.
