Importing local python code directory function in Julia

Please see the documentation of PythonCall.jl:

2 Likes
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 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

Does this work?

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?

No, This doesn’t work for me. See this is link of that folder. I would like to convert all files to Julia but it will take too much time.

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

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
...
3 Likes