# Importing local python code directory function in Julia

**URL:** https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315
**Category:** Offtopic
**Tags:** python, pythoncall
**Created:** [June 27, 2024, 3:43pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315 "2024-06-27T15:43:19Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [June 30, 2024, 12:41pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/23 "2024-06-30T12:41:03Z")

</div>

Please see the documentation of PythonCall.jl:

> **[Guide · PythonCall & JuliaCall](https://juliapy.github.io/PythonCall.jl/stable/pythoncall/)**
>
> Documentation for PythonCall & JuliaCall.

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [July 1, 2024, 9:37am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/24 "2024-07-01T09:37:31Z")

</div>

```julia
using Pkg, Interpolations, TensorOperations, DelimitedFiles, PythonCall, CondaPkg
Pkg.activate(".")
CondaPkg.add_pip("pyfiles", version="@./home/raman/Pictures/MikiFor2to3/pyfiles/")
pyfiles = pyimport("pyfiles")

```

I got

> **Error**
>
> ```julia
>    ~  julia Fluxes.jl  ✔ 
> CondaPkg Found dependencies: /home/raman/.julia/environments/v1.10/CondaPkg.toml
> CondaPkg Found dependencies: /home/raman/.julia/packages/PythonCall/S5MOg/CondaPkg.toml
> CondaPkg Dependencies already up to date
> Activating new project at `~`
> CondaPkg Found dependencies: /home/raman/.julia/environments/v1.10/CondaPkg.toml
> CondaPkg Found dependencies: /home/raman/.julia/packages/PythonCall/S5MOg/CondaPkg.toml
> CondaPkg Dependencies already up to date
> ERROR: LoadError: Python: ModuleNotFoundError: No module named 'pyfiles'
> Python stacktrace: none
> Stacktrace:
> [1] pythrow()
> @ PythonCall.Core ~/.julia/packages/PythonCall/S5MOg/src/Core/err.jl:92
> [2] errcheck
> @ ~/.julia/packages/PythonCall/S5MOg/src/Core/err.jl:10 [inlined]
> [3] pyimport(m::String)
> @ PythonCall.Core ~/.julia/packages/PythonCall/S5MOg/src/Core/builtins.jl:1444
> [4] top-level scope
> @ ~/Fluxes.jl:4
> in expression starting at /home/raman/Fluxes.jl:4
> 
> ```

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 1, 2024, 1:19pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/25 "2024-07-01T13:19:55Z")

</div>

Does this work?

```julia
CondaPkg.add_pip("pyfiles", version="@./home/raman/Pictures/MikiFor2to3/")
pyfiles = pyimport("pyfiles")

```

That’s a wild guess on my part.

Your issue is now a Python error, so I’m quite limited what I can do remotely to help you and also not an expert. Could you share your Python files with us somewhere?

---

<div class="post-metadata">

### Author: ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)
#### Post date: [July 1, 2024, 3:37pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/26 "2024-07-01T15:37:07Z")

</div>

> [@mkitti](#):
>
> Does this work?
> 
> ```julia
> CondaPkg.add_pip("pyfiles", version="@./home/raman/Pictures/MikiFor2to3/")
> pyfiles = pyimport("pyfiles")
> 
> ```

No, This doesn’t work for me. See this is link of that [folder.](https://drive.google.com/drive/folders/1z2B6WZFIeDtrbI0lY4ielXzQWpgfc_U2?usp=sharing) I would like to convert all files to Julia but it will take too much time.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [July 5, 2024, 3:37am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/27 "2024-07-05T03:37:04Z")

</div>

This is as far as I can get you. Hopefully this is far enough.

```julia-repl
julia> cd("MikiFor2to3")

julia> Pkg.activate(".")
  Activating project at `~/Downloads/juliacon2024/raman/MikiFor2to3`

julia> Pkg.add(["CondaPkg", "PythonCall"])
   Resolving package versions...
    Updating `~/Downloads/juliacon2024/raman/MikiFor2to3/Project.toml`
  [992eb4ea] ~ CondaPkg v0.2.22 `~/.julia/dev/CondaPkg` ⇒ v0.2.22
    Updating `~/Downloads/juliacon2024/raman/MikiFor2to3/Manifest.toml`
  [992eb4ea] ~ CondaPkg v0.2.22 `~/.julia/dev/CondaPkg` ⇒ v0.2.22

julia> using CondaPkg

julia> CondaPkg.add(CondaPkg.PkgSpec.(["numpy", "scipy", "h5py", "matplotlib"]))
    CondaPkg Found dependencies: /home/mkitti/Downloads/juliacon2024/raman/MikiFor2to3/CondaPkg.toml
    CondaPkg Found dependencies: /home/mkitti/.julia/packages/PythonCall/S5MOg/CondaPkg.toml
    CondaPkg Dependencies already up to date

julia> using PythonCall

julia> const sys = PythonCall.pyimport("sys")
Python: <module 'sys' (built-in)>

julia> sys.path.append(pwd())
Python: None

julia> const pyfiles = pyimport("pyfiles")

julia> athena_read = pyimport("pyfiles.athena_read")

julia> data = pyfiles.read_data("sane00.prim.01800.athdf", athinput="sane00.athinput")

julia> v2 = copy(PyArray(data.v2));

julia> typeof(v2)
Array{Float64, 3}

julia> size(v2)
(64, 128, 288)

julia> pyimport(".m2c_read_athdata")
...
ERROR: Python: NotImplementedError: `interp2d` has been removed in SciPy 1.14.0.

For legacy code, nearly bug-for-bug compatible replacements are
`RectBivariateSpline` on regular grids, and `bisplrep`/`bisplev` for
scattered 2D data.

In new code, for regular grids use `RegularGridInterpolator` instead.
For scattered data, prefer `LinearNDInterpolator` or
`CloughTocher2DInterpolator`.

For more details see
https://scipy.github.io/devdocs/tutorial/interpolate/interp_transition_guide.html
...

```

[Previous page](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315.md?page=1)
