# Segmentation fault when using a package, but same code in REPL works fine

**URL:** <https://discourse.julialang.org/t/segmentation-fault-when-using-a-package-but-same-code-in-repl-works-fine/9557>\
**Category:** General Usage\
**Created:** [March 7, 2018, 1:21am UTC](https://discourse.julialang.org/t/segmentation-fault-when-using-a-package-but-same-code-in-repl-works-fine/9557 "2018-03-07T01:21:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![safnuk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/safnuk/32/3771_2.png) [@safnuk](https://discourse.julialang.org/u/safnuk)\
**Post date:** [March 7, 2018, 1:21am UTC](https://discourse.julialang.org/t/segmentation-fault-when-using-a-package-but-same-code-in-repl-works-fine/9557/1 "2018-03-07T01:21:58Z")

</div>

Hello everyone,

I am relatively new to julia, and really not sure how to handle a problem with a package I am developing. When I call a function defined in it, I get a segmentation fault. However, if I paste the exact same code into the REPL, it works just fine. Previously, after importing the package I was getting many copies of the error:

```julia
jl_uv_writecb() ERROR: operation canceled ECANCELED

```

but now it loads the package without error, and segfaults after calling one of the package’s functions.

I suspect there is something cached for the package that has been corrupted, but have no idea where to look or how to start fresh.

The code itself can be found at  
[github.com/safnuk/DIDSON.jl](http://github.com/safnuk/DIDSON.jl)  
but I don’t think it is a code issue, as it runs fine on another computer.

Thanks,  
Brad

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 7, 2018, 2:10am UTC](https://discourse.julialang.org/t/segmentation-fault-when-using-a-package-but-same-code-in-repl-works-fine/9557/2 "2018-03-07T02:10:16Z")

</div>

Is precompilation enabled? If so, look for compiled pointers, like a constant bigfloat/bigint in the global scope.

---

<div class="post-metadata">

**Author:** ![safnuk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/safnuk/32/3771_2.png) [@safnuk](https://discourse.julialang.org/u/safnuk)\
**Post date:** [March 7, 2018, 3:28am UTC](https://discourse.julialang.org/t/segmentation-fault-when-using-a-package-but-same-code-in-repl-works-fine/9557/3 "2018-03-07T03:28:39Z")

</div>

> [@ChrisRackauckas](#):
>
> Is precompilation enabled?

It was enabled, but I took it out to see if it would help resolve the problem (it didn’t). I’m not sure what you mean by compiled pointers. Where do I look for them?

Thanks!

---

<div class="post-metadata">

**Author:** ![safnuk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/safnuk/32/3771_2.png) [@safnuk](https://discourse.julialang.org/u/safnuk)\
**Post date:** [March 7, 2018, 3:28am UTC](https://discourse.julialang.org/t/segmentation-fault-when-using-a-package-but-same-code-in-repl-works-fine/9557/4 "2018-03-07T03:28:41Z")

</div>

Thanks @ChrisRackauckas - precompilation was the culprit, with the offending pointer coming from

```julia
@pyimport numpy as np

```

Erasing the cache file in `~/.julia/v0.6/pkg.jl` and moving the pyimport line into a function fixed the error.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 7, 2018, 3:35am UTC](https://discourse.julialang.org/t/segmentation-fault-when-using-a-package-but-same-code-in-repl-works-fine/9557/5 "2018-03-07T03:35:46Z")

</div>

By the way, there’s a suggested solution to this problem in the PyCall.jl readme here: [https://github.com/JuliaPy/PyCall.jl#using-pycall-from-julia-modules](https://github.com/JuliaPy/PyCall.jl#using-pycall-from-julia-modules) which will allow you to still have a `const` global reference to `numpy` without the danger of segfaulting.
