# Juliacall / PythonCall array conversion error

**URL:** <https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-error/131311>\
**Category:** General Usage\
**Tags:** interoperability, array, python\
**Created:** [August 3, 2025, 3:06am UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-error/131311 "2025-08-03T03:06:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [August 3, 2025, 3:06am UTC](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-error/131311/1 "2025-08-03T03:06:57Z")

</div>

I’m using the Python package `juliacall` to call my Julia code. I encounter sporadic errors from lines that look like this:

```julia-auto
import numpy as np
from juliacall import Main as jl
jl.seval("import mypackage")
jl_mypackage = jl.seval("mypackage")
a0, b0 = jl_mypackage.somefunction(some_argument) # returns two arrays
a, b = np.asarray(a0), np.asarray(b0)

```

The last two lines are actually inside a loop, and I get sporadic errors every ~100K calls, with error messages like:

```
     13 a0, b0 = mypackage.somefunction(some_argument)
---> 14 a, b = np.asarray(a), np.asarray(b)

File ~/.julia/packages/PythonCall/L4cjh/src/JlWrap/array.jl:338, in __array__ (self, dtype)
    336 if not (hasattr(arr, " __array_interface__") or hasattr(arr, " __array_struct__")):
    337 # the first attempt collects into an Array
--> 338 arr = self._jl_callmethod($(pyjl_methodnum(pyjlarray_array__array)))
    339 if not (hasattr(arr, " __array_interface__") or hasattr(arr, " __array_struct__")):
    340 # the second attempt collects into a PyObjectArray

JuliaError: MethodError: no method matching pyjlarray_array__array(::Nothing)
The function `pyjlarray_array__array` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  pyjlarray_array__array(!Matched::AbstractArray)
   @ PythonCall ~/.julia/packages/PythonCall/L4cjh/src/JlWrap/array.jl:277

```

The same errors occur if I use `np.array`, instead of `np.asarray`, to wrap the Julia arrays while making a copy. My Julia code has type annotation to ensure that `jl_mypackage.somefunction(some_argument)` returns a tuple of two numerical arrays.

The only relevant result I found on Google is an unanswered github issue from another user. The same error message, `no method matching pyjlarray_array__array(::Nothing)`, appears near the end of his post:

> <https://github.com/JuliaPy/PythonCall.jl/issues/577>
>
> I am trying to train a RL agent using SB3, torch, and Gymnasium. I use a linux e…nvironment through wsl2 (Ubuntu-22.04), and VisualStudio Code. To speed up the step phase in my environment, I invoke Julia passing through juliacall to propagate the dynamics of my problem. I report here the main points of my implementation.
> 
> Problem dynamics in Julia: bcr4bp.jl
> \`\`\`
> \# Import dependencies
> using OrdinaryDiffEq
> 
> \# Struct for environment dynamical settings
> struct bcr4bpEnvJl
> 
> # Reference quantities
> mu::Float64
> mu3::Float64
> om3::Float64
> rho3::Float64
> tau0::Float64
> alpha0::Float64
> 
> # Propagator
> absTol::Float64
> relTol::Float64
> 
> end
> 
> \# Dynamical function for ODE propagation
> function bcr4bpRHS(dxx, xx, ENV::bcr4bpEnvJl, tau)
> 
> # Parameters extraction
> mu = ENV.mu
> mu3 = ENV.mu3
> om3 = ENV.om3
> rho3 = ENV.rho3
> tau0 = ENV.tau0
> alpha0 = ENV.alpha0
> 
> # Retrieve states
> x = xx\[1\]
> y = xx\[2\]
> z = xx\[3\]
> 
> xd = xx\[4\]
> yd = xx\[5\]
> zd = xx\[6\]
> 
> alpha = om3 \* (tau - tau0) + alpha0
> 
> # Compute distances from primaries
> r1 = sqrt((x+mu)^2 + y^2 + z^2);  
> r2 = sqrt((x+mu-1)^2 + y^2 + z^2);  
> r3 = sqrt((x-rho3\*cos(alpha))^2 + (y-rho3\*sin(alpha))^2 + z^2);
> 
> # Compute RHS
> ff3 = \[xd;
> yd;
> zd;
> 2\*yd + x - (1-mu)\*(x+mu)/r1^3 - mu\*(x+mu-1)/r2^3;
> -2\*xd + y - (1-mu)\*y/r1^3 - mu\*y/r2^3;
> -(1-mu)\*z/r1^3 - mu\*z/r2^3;;\]
> 
> ff4 = \[0;
> 0;
> 0;
> -mu3\*(x-rho3\*cos(alpha))/r3^3 - mu3/rho3^2\*cos(alpha);
> -mu3\*(y-rho3\*sin(alpha))/r3^3 - mu3/rho3^2\*sin(alpha);
> -mu3\*z/r3^3;;\]
> 
> # Return
> dyn = ff3 .+ ff4
> dxx\[1:6\] = dyn\[:\]
> 
> end
> 
> \# Propagation
> function bcr4bpPropagation(xx0, tSpan, ENV::bcr4bpEnvJl, is\_flow)
> 
> # Formulate ODE problem
> prob = ODEProblem(bcr4bpRHS, xx0, tSpan, ENV)
> 
> # Perform propagation
> sol = solve(prob, Vern9(), abstol=ENV.absTol, reltol=ENV.relTol)
> 
> # Check solution and return
> if sol.retcode == ReturnCode.Success
> 
> if is\_flow
> return sol\[:, end\]
> else
> return sol
> end
> 
> else
> 
> return 0
>     
> end
> 
> end
> \`\`\`
> 
> RL Gymnasium environment mission\_env.py
> \`\`\`
> import gymnasium as gym
> import numpy as np
> from copy import deepcopy
> from gymnasium import spaces
> from src.astro.bcr4bp.bcr4bp import Bcr4bp
> from src.utils.mission\_settings import MissionSettings
> from src.utils.propagator import Propagator
> from src.utils import util\_methods
> 
> import juliacall
> from juliacall import Main as jl\_main
> jl\_main.include("src/astro/bcr4bp/bcr4bp.jl")
> 
> class FbpMissionEnv(gym.Env):
> 
> metadata = {"render\_modes": \["rgb\_array"\]}
> 
> def \_\_init\_\_(self,
> dt\_step: np.float64,
> bcr4bp: Bcr4bp,
> mission\_settings: MissionSettings,
> propagator: Propagator):
>     
> # Init code ...
> # Julia environment definition
> self.\_bcr4bp\_env\_jl = jl\_main.bcr4bpEnvJl(jl\_main.Float64(self.\_bcr4bp.mu),
> jl\_main.Float64(self.\_bcr4bp.mu\_tertiary),
> jl\_main.Float64(self.\_bcr4bp.om\_tertiary),
> jl\_main.Float64(self.\_bcr4bp.dist\_tertiary),
> jl\_main.Float64(self.\_bcr4bp.tau\_ref),
> jl\_main.Float64(self.\_bcr4bp.alpha\_ref),
> jl\_main.Float64(self.\_propagator.abs\_tol),
> jl\_main.Float64(self.\_propagator.rel\_tol))
> 
> def reset(self, seed=None, options=None):
>         
> # Reset code ...
> return self.\_get\_obs(), self.\_get\_info()
> 
> def step(self, action):
> 
> # Some computing ...
> # Propagation
> # xx\_0 --\> np.array() of 6 elements
> # tau\_0 and tau\_f --\> floats
> xx\_f = np.array(jl\_main.bcr4bpPropagation(np.float64(xx\_0), np.array(\[tau\_0, tau\_f\], dtype=np.float64), self.\_bcr4bp\_env\_jl, True), np.float64)
> if np.size(xx\_f) != 6: # Bad propagation
> self.\_stop\_bad\_propagation = True
> return self.\_get\_obs(), -10, False, True, self.\_get\_info()
> # Some computing ...
> return self.\_get\_obs(), reward, terminated, False, self.\_get\_info()
> \`\`\`
> 
> When I run my code, the training works fine for some time. However, at an apparently random point, it segments (or returns exceptions). The error seems to be related to the Python to Julia conversion of inputs prior invoking jl\_main.bcr4bpPropagation or to the conversion of the return from Julia. If running in debug mode, when the code returns exceptions I am able to run the faulty line in the debug console with no problems
> \`xx\_f = np.array(jl\_main.bcr4bpPropagation(np.float64(xx\_0), np.array(\[tau\_0, tau\_f\], dtype=np.float64), self.\_bcr4bp\_env\_jl, True), np.float64))\`
> and I cannot explain this behavior. I guess it is related to some bad management of memory addresses. I also started thinking that maybe there are some limitation in using WSL in this context. I am not using multi-threads training / vectorized environments, so everything should be quite smooth. I tried different approaches such as, for example, converting the inputs to Julia format before calling the function. This problem does not appear if using the scipy integrate module rather than Julia. Therefore, I guess this segmentation fault is due to some troubles in calling Julia during run-time.
> 
> I report for reference the segfault\_log file from faulthandler (this is only and example, as the segmentation always happens at the same point, but for different reasons. Note that in this case I was able to run the faulty line in the debug console)
> \`\`\`
> \> Traceback (most recent call last):
> File "/usr/lib/python3.10/runpy.py", line 196, in \_run\_module\_as\_main
> return \_run\_code(code, main\_globals, None,
> File "/usr/lib/python3.10/runpy.py", line 86, in \_run\_code
> exec(code, run\_globals)
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/\_\_main\_\_.py", line 71, in 
> \<module\>
> cli.main()
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 
> 501, in main
> run()
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 
> 351, in run\_file
> runpy.run\_path(target, run\_name="\_\_main\_\_")
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_runpy.py", line 310, in run\_path
> return \_run\_module\_code(code, init\_globals, run\_name, pkg\_name=pkg\_name, script\_name=fname)
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_runpy.py", line 127, in 
> \_run\_module\_code
> \_run\_code(code, mod\_globals, init\_globals, mod\_name, mod\_spec, pkg\_name, script\_name)
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_runpy.py", line 118, in \_run\_code
> exec(code, run\_globals)
> File "/home/user/project/scripts/train.py", line 83, in \<module\>
> model.learn(total\_timesteps=3e6,
> File "/home/user/project/.venv/lib/python3.10/site-packages/stable\_baselines3/ppo/ppo.py", line 311, in learn
> return super().learn(
> File "/home/user/project/.venv/lib/python3.10/site-packages/stable\_baselines3/common/on\_policy\_algorithm.py", line 323, in learn
> continue\_training = self.collect\_rollouts(self.env, callback, self.rollout\_buffer, n\_rollout\_steps=self.n\_steps)
> File "/home/user/project/.venv/lib/python3.10/site-packages/stable\_baselines3/common/on\_policy\_algorithm.py", line 218, in collect\_rollouts
> new\_obs, rewards, dones, infos = env.step(clipped\_actions)
> File "/home/user/project/.venv/lib/python3.10/site-packages/stable\_baselines3/common/vec\_env/base\_vec\_env.py", line 206, in step
> return self.step\_wait()
> File "/home/user/project/.venv/lib/python3.10/site-packages/stable\_baselines3/common/vec\_env/dummy\_vec\_env.py", line 58, in step\_wait
> obs, self.buf\_rews\[env\_idx\], terminated, truncated, self.buf\_infos\[env\_idx\] = self.envs\[env\_idx\].step(
> File "/home/user/project/.venv/lib/python3.10/site-packages/stable\_baselines3/common/monitor.py", line 94, in step
> observation, reward, terminated, truncated, info = self.env.step(action)
> File "/home/user/project/.venv/lib/python3.10/site-packages/gymnasium/wrappers/order\_enforcing.py", line 56, in step
> return self.env.step(action)
> File "/home/user/project/.venv/lib/python3.10/site-packages/gymnasium/wrappers/env\_checker.py", line 51, in step
> return self.env.step(action)
> File "/home/user/project/src/env/fbp\_mission\_env.py", line 285, in step
> xx\_f = np.array(jl\_main.bcr4bpPropagation(np.float64(xx\_0), np.array(\[tau\_0, tau\_f\], dtype=np.float64), self.\_bcr4bp\_env\_jl, True), np.float32)
> File "/home/user/.julia/packages/PythonCall/Nr75f/src/JlWrap/array.jl", line 338, in \_\_array\_\_
> arr = self.\_jl\_callmethod($(pyjl\_methodnum(pyjlarray\_array\_\_array)))
> juliacall.JuliaError: MethodError: no method matching pyjlarray\_array\_\_array(::Nothing)
> The function pyjlarray\_array\_\_array exists, but no method is defined for this combination of argument types.
> Closest candidates are:
> pyjlarray\_array\_\_array(!Matched::AbstractArray)
> @ PythonCall ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/array.jl:277
> Stacktrace:
> \[1\] \_pyjl\_callmethod(f::Any, self\_::Ptr{PythonCall.C.PyObject}, args\_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
> @ PythonCall.JlWrap ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/base.jl:62
> \[2\] \_pyjl\_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
> @ PythonCall.JlWrap.Cjl ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/C.jl:63
> \`\`\`
> 
> Another segmentation fault that happened is (this time it segmented closing the debugger)
> \`\`\`
> Fatal Python error: Segmentation fault
> 
> Current thread 0x00007f966a5fd640 (most recent call first):
> Garbage-collecting
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/table.py", line 668 in \_get\_cells
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/table.py", line 757 in \_render
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/table.py", line 515 in \_\_rich\_console\_\_
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/console.py", line 1326 in render
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/console.py", line 1330 in render
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/segment.py", line 305 in split\_and\_crop\_lines
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/console.py", line 1366 in render\_lines
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/live\_render.py", line 87 in \_\_rich\_console\_\_
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/console.py", line 1326 in render
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/console.py", line 1705 in print
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/live.py", line 242 in refresh
> File "/home/user/project/.venv/lib/python3.10/site-packages/rich/live.py", line 32 in run
> File "/usr/lib/python3.10/threading.py", line 1016 in \_bootstrap\_inner
> File "/usr/lib/python3.10/threading.py", line 973 in \_bootstrap
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydev\_bundle/pydev\_monkey.py", line 1134 in \_\_call\_\_
> 
> Thread 0x00007f966adfe640 (most recent call first):
> File "/usr/lib/python3.10/threading.py", line 324 in wait
> File "/usr/lib/python3.10/threading.py", line 607 in wait
> File "/home/user/project/.venv/lib/python3.10/site-packages/tqdm/\_monitor.py", line 60 in run
> File "/usr/lib/python3.10/threading.py", line 1016 in \_bootstrap\_inner
> File "/usr/lib/python3.10/threading.py", line 973 in \_bootstrap
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydev\_bundle/pydev\_monkey.py", line 1134 in \_\_call\_\_
> 
> Thread 0x00007f966b5ff640 (most recent call first):
> File "/usr/lib/python3.10/threading.py", line 324 in wait
> File "/usr/lib/python3.10/queue.py", line 180 in get
> File "/home/user/project/.venv/lib/python3.10/site-packages/tensorboard/summary/writer/event\_file\_writer.py", line 269 in \_run
> File "/home/user/project/.venv/lib/python3.10/site-packages/tensorboard/summary/writer/event\_file\_writer.py", line 244 in run
> File "/usr/lib/python3.10/threading.py", line 1016 in \_bootstrap\_inner
> File "/usr/lib/python3.10/threading.py", line 973 in \_bootstrap
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydev\_bundle/pydev\_monkey.py", line 1134 in \_\_call\_\_
> 
> Thread 0x00007f9846ffd640 (most recent call first):
> File "/usr/lib/python3.10/threading.py", line 324 in wait
> File "/usr/lib/python3.10/threading.py", line 607 in wait
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/pydevd.py", line 325 in \_on\_run
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_daemon\_thread.py", line 53 in run
> File "/usr/lib/python3.10/threading.py", line 1016 in \_bootstrap\_inner
> File "/usr/lib/python3.10/threading.py", line 973 in \_bootstrap
> 
> Thread 0x00007f98477fe640 (most recent call first):
> File "/usr/lib/python3.10/threading.py", line 324 in wait
> File "/usr/lib/python3.10/threading.py", line 607 in wait
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/pydevd.py", line 280 in \_on\_run
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_daemon\_thread.py", line 53 in run
> File "/usr/lib/python3.10/threading.py", line 1016 in \_bootstrap\_inner
> File "/usr/lib/python3.10/threading.py", line 973 in \_bootstrap
> 
> Thread 0x00007f9847fff640 (most recent call first):
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_comm.py", line 227 in \_read\_line
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_comm.py", line 245 in \_on\_run
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_daemon\_thread.py", line 53 in run
> File "/usr/lib/python3.10/threading.py", line 1016 in \_bootstrap\_inner
> File "/usr/lib/python3.10/threading.py", line 973 in \_bootstrap
> 
> Thread 0x00007f984cf10640 (most recent call first):
> File "/usr/lib/python3.10/threading.py", line 324 in wait
> File "/usr/lib/python3.10/queue.py", line 180 in get
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_comm.py", line 390 in \_on\_run
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_daemon\_thread.py", line 53 in run
> File "/usr/lib/python3.10/threading.py", line 1016 in \_bootstrap\_inner
> File "/usr/lib/python3.10/threading.py", line 973 in \_bootstrap
> 
> Thread 0x00007f984e547000 (most recent call first):
> File "/usr/lib/python3.10/threading.py", line 324 in wait
> File "/usr/lib/python3.10/threading.py", line 607 in wait
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/pydevd.py", line 2266 in \_do\_wait\_suspend
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/pydevd.py", line 2197 in do\_wait\_suspend
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/pydevd.py", line 2384 in do\_stop\_on\_unhandled\_exception
> File "/home/user/.vscode-server/extensions/ms-python.debugpy-2024.12.0-linux-x64/bundled/libs/debugpy/\_vendored/pydevd/\_pydevd\_bundle/pydevd\_breakpoints.py", line 174 in stop\_on\_unhandled\_exception
> File "/usr/lib/python3.10/runpy.py", line 196 in \_run\_module\_as\_main
> 
> Extension modules: \_pydevd\_bundle.pydevd\_cython, numpy.core.\_multiarray\_umath, numpy.core.\_multiarray\_tests, numpy.linalg.\_umath\_linalg, numpy.fft.\_pocketfft\_internal, numpy.random.\_common, numpy.random.bit\_generator, numpy.random.\_bounded\_integers, numpy.random.\_mt19937, numpy.random.mtrand, numpy.random.\_philox, numpy.random.\_pcg64, numpy.random.\_sfc64, numpy.random.\_generator, scipy.\_lib.\_ccallback\_c, scipy.sparse.\_sparsetools, \_csparsetools, scipy.sparse.\_csparsetools, scipy.linalg.\_fblas, scipy.linalg.\_flapack, scipy.linalg.cython\_lapack, scipy.linalg.\_cythonized\_array\_utils, scipy.linalg.\_solve\_toeplitz, scipy.linalg.\_decomp\_lu\_cython, scipy.linalg.\_matfuncs\_sqrtm\_triu, scipy.linalg.cython\_blas, scipy.linalg.\_matfuncs\_expm, scipy.linalg.\_decomp\_update, scipy.sparse.linalg.\_dsolve.\_superlu, scipy.sparse.linalg.\_eigen.arpack.\_arpack, scipy.sparse.linalg.\_propack.\_spropack, scipy.sparse.linalg.\_propack.\_dpropack, scipy.sparse.linalg.\_propack.\_cpropack, scipy.sparse.linalg.\_propack.\_zpropack, scipy.sparse.csgraph.\_tools, scipy.sparse.csgraph.\_shortest\_path, scipy.sparse.csgraph.\_traversal, scipy.sparse.csgraph.\_min\_spanning\_tree, scipy.sparse.csgraph.\_flow, scipy.sparse.csgraph.\_matching, scipy.sparse.csgraph.\_reordering, scipy.io.matlab.\_mio\_utils, scipy.io.matlab.\_streams, scipy.io.matlab.\_mio5\_utils, scipy.special.\_ufuncs\_cxx, scipy.special.\_ufuncs, scipy.special.\_specfun, scipy.special.\_comb, scipy.special.\_ellip\_harm\_2, scipy.integrate.\_odepack, scipy.integrate.\_quadpack, scipy.integrate.\_vode, scipy.integrate.\_dop, scipy.integrate.\_lsoda, scipy.optimize.\_group\_columns, scipy.\_lib.messagestream, scipy.optimize.\_trlib.\_trlib, scipy.optimize.\_lbfgsb, \_moduleTNC, scipy.optimize.\_moduleTNC, scipy.optimize.\_cobyla, scipy.optimize.\_slsqp, scipy.optimize.\_minpack, scipy.optimize.\_lsq.givens\_elimination, scipy.optimize.\_zeros, scipy.optimize.\_highs.cython.src.\_highs\_wrapper, scipy.optimize.\_highs.\_highs\_wrapper, scipy.optimize.\_highs.cython.src.\_highs\_constants, scipy.optimize.\_highs.\_highs\_constants, scipy.linalg.\_interpolative, scipy.optimize.\_bglu\_dense, scipy.optimize.\_lsap, scipy.spatial.\_ckdtree, scipy.spatial.\_qhull, scipy.spatial.\_voronoi, scipy.spatial.\_distance\_wrap, scipy.spatial.\_hausdorff, scipy.spatial.transform.\_rotation, scipy.optimize.\_direct, torch.\_C, torch.\_C.\_dynamo.autograd\_compiler, torch.\_C.\_dynamo.eval\_frame, torch.\_C.\_dynamo.guards, torch.\_C.\_dynamo.utils, torch.\_C.\_fft, torch.\_C.\_linalg, torch.\_C.\_nested, torch.\_C.\_nn, torch.\_C.\_sparse, torch.\_C.\_special, google.\_upb.\_message, PIL.\_imaging, kiwisolver.\_cext, pyarrow.lib, pandas.\_libs.tslibs.ccalendar, pandas.\_libs.tslibs.np\_datetime, pandas.\_libs.tslibs.dtypes, pandas.\_libs.tslibs.base, pandas.\_libs.tslibs.nattype, pandas.\_libs.tslibs.timezones, pandas.\_libs.tslibs.fields, pandas.\_libs.tslibs.timedeltas, pandas.\_libs.tslibs.tzconversion, pandas.\_libs.tslibs.timestamps, pandas.\_libs.properties, pandas.\_libs.tslibs.offsets, pandas.\_libs.tslibs.strptime, pandas.\_libs.tslibs.parsing, pandas.\_libs.tslibs.conversion, pandas.\_libs.tslibs.period, pandas.\_libs.tslibs.vectorized, pandas.\_libs.ops\_dispatch, pandas.\_libs.missing, pandas.\_libs.hashtable, pandas.\_libs.algos, pandas.\_libs.interval, pandas.\_libs.lib, pyarrow.\_compute, pandas.\_libs.ops, pandas.\_libs.hashing, pandas.\_libs.arrays, pandas.\_libs.tslib, pandas.\_libs.sparse, pandas.\_libs.internals, pandas.\_libs.indexing, pandas.\_libs.index, pandas.\_libs.writers, pandas.\_libs.join, pandas.\_libs.window.aggregations, pandas.\_libs.window.indexers, pandas.\_libs.reshape, pandas.\_libs.groupby, pandas.\_libs.json, pandas.\_libs.parsers, pandas.\_libs.testing (total: 135)
> \`\`\`
> 
> Another time, exception has been returned in the Julia array wrapper. here I tried to use deepcopy before invoking Julia:
> \`\`\`
> Exception has occurred: JuliaError
> MethodError: no method matching pyjlarray\_array\_\_array(::Nothing)
> The function \`pyjlarray\_array\_\_array\` exists, but no method is defined for this combination of argument types.
> 
> Closest candidates are:
> pyjlarray\_array\_\_array(!Matched::AbstractArray)
> @ PythonCall ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/array.jl:277
> 
> Stacktrace:
> \[1\] \_pyjl\_callmethod(f::Any, self\_::Ptr{PythonCall.C.PyObject}, args\_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
> @ PythonCall.JlWrap ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/base.jl:62
> \[2\] \_pyjl\_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
> @ PythonCall.JlWrap.Cjl ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/C.jl:63
> File "/home/user/.julia/packages/PythonCall/Nr75f/src/JlWrap/array.jl", line 338, in \_\_array\_\_
> arr = self.\_jl\_callmethod($(pyjl\_methodnum(pyjlarray\_array\_\_array)))
> File "/home/user/project/src/env/fbp\_mission\_env.py", line 140, in reset
> xx\_0 = np.array(jl\_main.bcr4bpPropagation(deepcopy(xx\_0), deepcopy(\[time, time + self.\_dt\_step\]), self.\_bcr4bp\_env\_jl, True), np.float64)
> File "/home/user/project/scripts/train.py", line 83, in \<module\>
> model.learn(total\_timesteps=1e6,
> juliacall.JuliaError: MethodError: no method matching pyjlarray\_array\_\_array(::Nothing)
> The function \`pyjlarray\_array\_\_array\` exists, but no method is defined for this combination of argument types.
> 
> Closest candidates are:
> pyjlarray\_array\_\_array(!Matched::AbstractArray)
> @ PythonCall ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/array.jl:277
> 
> Stacktrace:
> \[1\] \_pyjl\_callmethod(f::Any, self\_::Ptr{PythonCall.C.PyObject}, args\_::Ptr{PythonCall.C.PyObject}, nargs::Int64)
> @ PythonCall.JlWrap ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/base.jl:62
> \[2\] \_pyjl\_callmethod(o::Ptr{PythonCall.C.PyObject}, args::Ptr{PythonCall.C.PyObject})
> @ PythonCall.JlWrap.Cjl ~/.julia/packages/PythonCall/Nr75f/src/JlWrap/C.jl:63
> \`\`\`
> 
> As I am not a computer expert, I may have made some very stupid errors, especially concerning poor management of variables. Hope you can suggest me how to solve this problem and make my code more robust.
> Thanks a lot!

Unlike the other post, I’m using Linux instead of WSL, but curiously, I’ve also used the same Python packages (PyTorch and SB3) when I run into this problem. But as far as I understand, the essential part of the problem is captured by the few lines of code I posted at the beginning, not related to the other packages, as my code is essentially standalone for providing data.

P.S. Now I have a cleaner demonstration of the problem in a new post:

> [@Juliacall / PythonCall array conversion crash (now with MWE)](https://discourse.julialang.org/t/juliacall-pythoncall-array-conversion-crash-now-with-mwe/131318):
>
> Here’s the Python code which extracts a tuple of two Julia arrays from the juliacall interface and converts them to numpy arrays. The code is an infinite loop, but crashes sporadically after a few million iterations with segfault: # juliacall\_problem1.py from juliacall import Main as jl import numpy as np counter = 0 while True: counter += 1 try: a, b = jl.seval("(fill(0f0, 3, 8, 8), fill(true, 3, 8, 8))") c, d = np.array(a), np.array(b) except: print(f"Fail…
