# Adding CUDA.jl dependency to juliacall python package

**URL:** <https://discourse.julialang.org/t/adding-cuda-jl-dependency-to-juliacall-python-package/114072>\
**Category:** General Usage\
**Tags:** pythoncall\
**Created:** [May 9, 2024, 11:19pm UTC](https://discourse.julialang.org/t/adding-cuda-jl-dependency-to-juliacall-python-package/114072 "2024-05-09T23:19:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dale\_James\_Black](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dale_james_black/32/11595_2.png) [@Dale\_James\_Black](https://discourse.julialang.org/u/Dale_James_Black)\
**Post date:** [May 9, 2024, 11:19pm UTC](https://discourse.julialang.org/t/adding-cuda-jl-dependency-to-juliacall-python-package/114072/1 "2024-05-09T23:19:50Z")

</div>

I am trying to create a wrapper python package for my Julia library, DistanceTransforms.jl, called [PyDTs](https://github.com/MolloiLab/PyDTs). This package utilizes rye as the package manager and intends to work with CUDA.jl and PyTorch. Therefore, I am trying to setup the `juliapkg.json` like so:

```json
{
  "julia": "~1.9, ~1.10",
  "packages": {
    "DistanceTransforms": {
      "uuid": "71182807-4d06-4237-8dd0-bdafe4d097e2",
      "version": "=0.2.1"
    },
    "CUDA": {
      "uuid": "052768ef-5323-5732-b1bb-66c8b64840ba",
      "version": "=5.4.0"
    }
  }
}

```

And the imports like so:

```python
from juliacall import Main as jl

jl.seval("using Pkg; Pkg.status()")
jl.seval("using DistanceTransforms")
jl.seval("using CUDA")

DistanceTransforms = jl.DistanceTransforms
CUDA = jl.CUDA

```

But when importing the actual pkg and torch/numpy:

```python
import numpy as np
import torch
from pydts import (
    transform_1d,
    transform_2d,
    transform_3d,
    transform_gpu_2d,
    transform_gpu_3d,
)

```

I get an error that I don’t understand:

```python
/usr/local/lib/python3.10/dist-packages/juliacall/ __init__.py:60: UserWarning: torch was imported before juliacall. This may cause a segfault. To avoid this, import juliacall before importing torch. For updates, see https://github.com/pytorch/pytorch/issues/78829.
  warnings.warn(
[juliapkg] Locating Julia ~1.9, =1.10.0, ~1.10.3
[juliapkg] Using Julia 1.10.3 at /root/.julia/environments/pyjuliapkg/pyjuliapkg/install/bin/julia
[juliapkg] Using Julia project at /root/.julia/environments/pyjuliapkg
[juliapkg] Installing packages:
           julia> import Pkg
           julia> Pkg.Registry.update()
           julia> Pkg.add([Pkg.PackageSpec(name="DistanceTransforms", uuid="71182807-4d06-4237-8dd0-bdafe4d097e2"), Pkg.PackageSpec(name="CUDA", uuid="052768ef-5323-5732-b1bb-66c8b64840ba"), Pkg.PackageSpec(name="PythonCall", uuid="6099a3de-0909-46bc-b1f4-468b9a2dfc0d")])
           julia> Pkg.resolve()
           julia> Pkg.precompile()
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-7-5f75622512b8> in <cell line: 3>()
      1 import numpy as np
      2 import torch
----> 3 from pydts import (
      4 transform_1d,
      5 transform_2d,

6 frames
/usr/lib/python3.10/subprocess.py in run(input, capture_output, timeout, check, *popenargs, **kwargs)
    524 retcode = process.poll()
    525 if check and retcode:
--> 526 raise CalledProcessError(retcode, process.args,
    527 output=stdout, stderr=stderr)
    528 return CompletedProcess(process.args, retcode, stdout, stderr)

CalledProcessError: Command '['/root/.julia/environments/pyjuliapkg/pyjuliapkg/install/bin/julia', '--project=/root/.julia/environments/pyjuliapkg', '--startup-file=no', '-e', 'import Pkg; Pkg.Registry.update(); Pkg.add([Pkg.PackageSpec(name="DistanceTransforms", uuid="71182807-4d06-4237-8dd0-bdafe4d097e2"), Pkg.PackageSpec(name="CUDA", uuid="052768ef-5323-5732-b1bb-66c8b64840ba"), Pkg.PackageSpec(name="PythonCall", uuid="6099a3de-0909-46bc-b1f4-468b9a2dfc0d")]); Pkg.resolve(); Pkg.precompile()']' returned non-zero exit status 1.

```

Does anyone know the right way to import CUDA into a python package using PythonCall.jl and Rye?

---

<div class="post-metadata">

**Author:** ![Dale\_James\_Black](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dale_james_black/32/11595_2.png) [@Dale\_James\_Black](https://discourse.julialang.org/u/Dale_James_Black)\
**Post date:** [May 20, 2024, 10:36pm UTC](https://discourse.julialang.org/t/adding-cuda-jl-dependency-to-juliacall-python-package/114072/2 "2024-05-20T22:36:25Z")

</div>

I think I solved it. The CUDA.jl requirement needed to be relaxed. Not sure why but setting the `juliapkg,json` to `"version": "=5.3.4"` worked
