# Debugging julia code

**URL:** <https://discourse.julialang.org/t/debugging-julia-code/21246>\
**Category:** General Usage\
**Created:** [February 27, 2019, 5:05am UTC](https://discourse.julialang.org/t/debugging-julia-code/21246 "2019-02-27T05:05:03Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 1, 2019, 7:40pm UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/21 "2019-03-01T19:40:58Z")

</div>

Yes, for the near future it’s going to be slow (kind of like Python or Lisp 😉). You’re going to have to identify small test cases that can run quickly.

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 1, 2019, 9:08pm UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/22 "2019-03-01T21:08:56Z")

</div>

> [@cstjean](#):
>
> My scenario is: I do some development, then start some heavy computation. Five minutes later, there’s a MethodError. In Python or Common Lisp, I can directly step into the debugger and figure out what went wrong.

Wait. Can python do that? I’ve been working with python lately, but had the impression that you have to explicitly launch a debugging session. How do you accomplish this?

---

<div class="post-metadata">

**Author:** ![cortner](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cortner/32/204_2.png) [@cortner](https://discourse.julialang.org/u/cortner)\
**Post date:** [March 1, 2019, 10:37pm UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/23 "2019-03-01T22:37:12Z")

</div>

[https://docs.python.org/3/library/pdb.html](https://docs.python.org/3/library/pdb.html)

See pdb.post\_morten

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [March 1, 2019, 10:50pm UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/24 "2019-03-01T22:50:07Z")

</div>

Since you have to launch pdb before you run your code, how is that different from `@interpret mycode(args...)`?

---

<div class="post-metadata">

**Author:** ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)\
**Post date:** [March 1, 2019, 11:26pm UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/25 "2019-03-01T23:26:22Z")

</div>

So do you have to explicitly launch the debugger, or can you just do like Matlab, and set `dbstop if error` before running your code from the ordinary command line?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [March 2, 2019, 1:41am UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/26 "2019-03-02T01:41:04Z")

</div>

No need to launch it before. Just use `ipython`, and do `%debug` to debug the last exception. It works in Jupyter notebooks, too.

```julia
In [1]: "asidhaisfh".length(2)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-28f983e3c036> in <module>()
----> 1 "asidhaisfh".length(2)

AttributeError: 'str' object has no attribute 'length'

In [2]: %debug
> <ipython-input-1-28f983e3c036>(1)<module>()
----> 1 "asidhaisfh".length(2)

ipdb> 

```

If you don’t care about speed, then sure, `@interpret` would be just as convenient as Python.

---

<div class="post-metadata">

**Author:** ![MicPie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/micpie/32/12890_2.png) [@MicPie](https://discourse.julialang.org/u/MicPie)\
**Post date:** [February 27, 2020, 7:50pm UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/27 "2020-02-27T19:50:30Z")

</div>

> [@cstjean](#):
>
> `%debug` … works in Jupyter notebooks, too.

Sorry for reviving this topic, but when I call in Jupyter `%debug` I get the following message:  
`The Julia interactive debugger is provided by the Gallium package.`  
But the Gallium GitHub repo says it is deprecated and it seems that the other debuggers are not for Jupyter.

Am I missing something or is there a new recommendation for debugging in a Jupyter notebook?

---

<div class="post-metadata">

**Author:** ![lewis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lewis/32/5217_2.png) [@lewis](https://discourse.julialang.org/u/lewis)\
**Post date:** [June 8, 2022, 6:34pm UTC](https://discourse.julialang.org/t/debugging-julia-code/21246/28 "2022-06-08T18:34:27Z")

</div>

Unless the Julia Language Server integrates Debugger.jl then there is no way to debug in Jupyter. I am trying to figure this out.

Will report back.

[Previous page](https://discourse.julialang.org/t/debugging-julia-code/21246.md?page=1)
