# Pyimport crashes VSCode Julia REPL

**URL:** <https://discourse.julialang.org/t/pyimport-crashes-vscode-julia-repl/107172>\
**Category:** VS Code\
**Tags:** question\
**Created:** [December 5, 2023, 2:43pm UTC](https://discourse.julialang.org/t/pyimport-crashes-vscode-julia-repl/107172 "2023-12-05T14:43:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gast](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gast/32/206425_2.png) [@Gast](https://discourse.julialang.org/u/Gast)\
**Post date:** [December 5, 2023, 2:43pm UTC](https://discourse.julialang.org/t/pyimport-crashes-vscode-julia-repl/107172/1 "2023-12-05T14:43:12Z")

</div>

Importing the Python module `Scipy` instantly crashes and closes VSCode Julia REPL before I can see the error message.

For instance, the following code crashes my REPL every time:

```julia
julia> using PyCall
julia> mv = pyimport("scipy.stats.mvn") 

```

Interestingly, importing the module `Math` does not crash my REPL:

```julia
julia> using PyCall
julia> math= pyimport("math")
PyObject <module 'math' from '/Users/gaston/.julia/conda/3/lib/python3.10/lib-dynload/math.cpython-310-darwin.so'>

```

In VSCode, I am using:

```julia
Version: 1.84.2 (Universal)
Commit: 1a5daa3a0231a0fbba4f14db7ec463cf99d7768e
Date: 2023-11-09T10:52:33.687Z
Electron: 25.9.2
ElectronBuildId: 24603566
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 20.6.0

```

And I have `v1.60.2` of the Julia language extension. This is all on MacOS Big Sur 11.6 (M1, 16GB)

---

<div class="post-metadata">

**Author:** ![tamasgal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamasgal/32/27946_2.png) [@tamasgal](https://discourse.julialang.org/u/tamasgal)\
**Post date:** [December 5, 2023, 3:20pm UTC](https://discourse.julialang.org/t/pyimport-crashes-vscode-julia-repl/107172/2 "2023-12-05T15:20:32Z")

</div>

Does that happen in the terminal too (just trying to get VSCode out of the equation)?

---

<div class="post-metadata">

**Author:** ![Gast](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gast/32/206425_2.png) [@Gast](https://discourse.julialang.org/u/Gast)\
**Post date:** [December 5, 2023, 4:41pm UTC](https://discourse.julialang.org/t/pyimport-crashes-vscode-julia-repl/107172/3 "2023-12-05T16:41:56Z")

</div>

It does.

Calling `Scipy` it crashes:

```julia
julia> using PyCall
julia> pyimport("scipy")
zsh: killed /Applications/Julia-1.9.app/Contents/Resources/julia/bin/julia
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...none found.

[Process completed]

```

while calling the module `Math` it does not crash:

```julia
julia> pyimport("math")
PyObject <module 'math' from '/Users/gaston/.julia/conda/3/lib/python3.10/lib-dynload/math.cpython-310-darwin.so'>

```

Julia Version 1.9.4

---

<div class="post-metadata">

**Author:** ![mihalybaci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mihalybaci/32/13528_2.png) [@mihalybaci](https://discourse.julialang.org/u/mihalybaci)\
**Post date:** [December 5, 2023, 4:52pm UTC](https://discourse.julialang.org/t/pyimport-crashes-vscode-julia-repl/107172/4 "2023-12-05T16:52:05Z")

</div>

It is probably worth checking that you are using the right Python version with scipy installed. Try typing `ENV["PYTHON"]` at the Julia REPL command line and see what Python it’s pointing too and make sure it’s the one you want.

Side note: I think it is generally recommended to use the [`PythonCall.jl`](https://juliapy.github.io/PythonCall.jl/stable/) package these days rather than `PyCall.jl`.

---

<div class="post-metadata">

**Author:** ![Gast](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gast/32/206425_2.png) [@Gast](https://discourse.julialang.org/u/Gast)\
**Post date:** [December 5, 2023, 9:55pm UTC](https://discourse.julialang.org/t/pyimport-crashes-vscode-julia-repl/107172/5 "2023-12-05T21:55:41Z")

</div>

Making use of the `PythonCall` package instead of `PyCall` solved the issue!

I am not sure why but now the Julia REPL does not crash (nor in the terminal).

Thanks for hinting this out.
