# 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:** 20\
**Page:** 1

<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:** [June 27, 2024, 3:43pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/1 "2024-06-27T15:43:19Z")

</div>

**Please help me in importing local python code directory within Julia.** I am analyzing astrophysical simulation data output from [Atheena++](https://www.athena-astro.app/). I am writing code in julia to plot data manipulated by python script. My code is 👇 : but i am still getting error.

```julia
using Interpolations, TensorOperations, DelimitedFiles, PythonCall
athinput=run("/home/raman/Pictures/MikiFor2to3/pyfiles/read_athinput.py")
runname='/'
inputfile=runname+'home/raman/Pictures/sane00.athinput'
datalist ="./home/raman/Pictures/sane00.athinput/"

```

I am getting error 👇

```julia
   ~  julia Fluxes.jl  ✔ 
ERROR: LoadError: MethodError: no method matching run(::String)

Closest candidates are:
  run(::Base.AbstractCmd, Any...; wait)
   @ Base process.jl:477

Stacktrace:
 [1] top-level scope
   @ ~/Fluxes.jl:2
in expression starting at /home/raman/Fluxes.jl:2

```

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [June 28, 2024, 9:31am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/4 "2024-06-28T09:31:25Z")

</div>

Your code is a mess.

1. The error you see `MethodError: no method matching run(::String)` tells you that you are using `run` wrong. The correct way to to use it is with: `run(`your-cmd-here`)` note the different quotation marks!
2. You are not using the output of run that you store in `athinput`. But `run` likely does not return what you expect it to anyways and I can’t really guess what you expect it to return since you didn’t provide any explanation or even the Python script. Perhaps you’ll want to `readchomp(`your-cmd-here`)` instead of `run`
3. This line `inputfile=runname+'home/raman/Pictures/sane00.athinput'` this pure Python code that snuck into your Julia script. In Julia `'a'` denotes a character not a string and thus `'more-than-one-char'` throws. Also string concatenation is `*` in Julia.
4. Later in this script you use the `file` variable which you did not define. Perhaps it should be replaced with `athinput`?

Please put at least some effort into your posts here! People helping you here do this on their own free time. So very low effort post like yours might just be ignored.

This certainly was the last answer you’ll get from me, if your post does not show any sign that you at least tried to solve your problem i.e. by reading the error message.

---

<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:** [June 28, 2024, 10:38am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/5 "2024-06-28T10:38:23Z")

</div>

How to import local `.py` python file from your laptop in Julia? I am unable to understand this link. [How can we import python files? · JuliaPy/PythonCall.jl · Discussion #145 · GitHub](https://github.com/JuliaPy/PythonCall.jl/discussions/145)

```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 Resolving changes
             + pyexec
    CondaPkg Installing packages
             │ /home/raman/.julia/artifacts/7973f2c7725e2d0eef7a95159454c4145f0945a2/bin/micromamba
             │ -r /home/raman/micromamba
             │ install
             │ -y
             │ -p /home/raman/.julia/environments/v1.10/.CondaPkg/env
             │ --override-channels
             │ --no-channel-priority
             │ libstdcxx-ng[version='>=3.4,<13.0']
             │ pyexec[version='*']
             │ python[version='>=3.8,<4',channel='conda-forge',build='*cpython*']
             └ -c conda-forge
conda-forge/linux-64 No change
conda-forge/noarch 15.2MB @ 927.2kB/s 16.5s
error libmamba Could not solve for environment specs
    The following package could not be installed
    └─ pyexec * does not exist (perhaps a typo or a missing channel).
critical libmamba Could not solve for environment specs
ERROR: LoadError: InitError: failed process: Process(`/home/raman/.julia/artifacts/7973f2c7725e2d0eef7a95159454c4145f0945a2/bin/micromamba -r /home/raman/micromamba install -y -p /home/raman/.julia/environments/v1.10/.CondaPkg/env --override-channels --no-channel-priority "libstdcxx-ng[version='>=3.4,<13.0']" "pyexec[version='*']" "python[version='>=3.8,<4',channel='conda-forge',build='*cpython*']" -c conda-forge`, ProcessExited(1)) [1]

Stacktrace:
  [1] pipeline_error
    @ ./process.jl:565 [inlined]
  [2] run(::Cmd; wait::Bool)
    @ Base ./process.jl:480
  [3] run(::Cmd)
    @ Base ./process.jl:477
  [4] _run(io::IO, cmd::Cmd, args::Any; flags::Any)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:398
  [5] _resolve_conda_install(io::Any, conda_env::Any, specs::Any, channels::Any; create::Any)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:299
  [6] _resolve_conda_install(io::Any, conda_env::Any, specs::Any, channels::Any)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:287
  [7] resolve(; force::Bool, io::IO, interactive::Bool, dry_run::Bool)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:525
  [8] resolve()
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:405
  [9] envdir()
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/env.jl:70
 [10] init_context()
    @ PythonCall.C ~/.julia/packages/PythonCall/S5MOg/src/C/context.jl:63
 [11] __init__ ()
    @ PythonCall.C ~/.julia/packages/PythonCall/S5MOg/src/C/C.jl:23
 [12] run_module_init(mod::Module, i::Int64)
    @ Base ./loading.jl:1134
 [13] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1122
 [14] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:1067
 [15] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base ./loading.jl:1581
 [16] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1938
 [17] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1812
 [18] #invoke_in_world#3
    @ ./essentials.jl:926 [inlined]
 [19] invoke_in_world
    @ ./essentials.jl:923 [inlined]
 [20] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1803
 [21] macro expansion
    @ ./loading.jl:1790 [inlined]
 [22] macro expansion
    @ ./lock.jl:267 [inlined]
 [23] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1753
 [24] #invoke_in_world#3
    @ ./essentials.jl:926 [inlined]
 [25] invoke_in_world
    @ ./essentials.jl:923 [inlined]
 [26] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1746
during initialization of module C
in expression starting at /home/raman/Fluxes.jl:1

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 28, 2024, 12:36pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/6 "2024-06-28T12:36:00Z")

</div>

You cannot import Python files, only Python packages. Can you explain what you actually want to do? What is your goal? Execute Python scripts? Call Python functions? Instantiate Python classes? Or something else?

---

<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:** [June 28, 2024, 2:57pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/7 "2024-06-28T14:57:15Z")

</div>

> [@ufechner7](#):
>
> Execute Python scripts

Yes, I want to execute python scripts within julia. I have simulation data with will be manipulated by lengthy python scripts 👇

```julia
    ~/Pi/MikiFor2to3/pyfiles  ls  ✔ 
athena_read.py fm_torus.pyc metric.py read_athinput.py read_data.pyc
athena_read.pyc __init__.py metric.pyc read_athinput.pyc unimesh.py
fm_torus.py __init__.pyc __pycache__ read_data.py unimesh.pyc

```

and then i will feed output to my julia scripts which will plot finally.  
I would like to convert all those python scripts in julia but it will take a lot of time, so i just want to use julia only at last stage of data analysis.

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 28, 2024, 3:21pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/8 "2024-06-28T15:21:51Z")

</div>

If you want to run the whole script and it has no direct interaction with Julia, you can simply run it via `run()` shell interaction. See: [Running External Programs · The Julia Language](https://docs.julialang.org/en/v1/manual/running-external-programs/)

Example:

```julia
julia> run(`python hello.py`)
Hello
Process(`python hello.py`, ProcessExited(0))

```

assuming a file `hello.py` exists in the current directory and Python is installed and in the search path.

---

<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 28, 2024, 3:49pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/9 "2024-06-28T15:49:26Z")

</div>

See the documentation of CondaPkg.jl:

> **[GitHub - JuliaPy/CondaPkg.jl: Add Conda dependencies to your Julia project](https://github.com/JuliaPy/CondaPkg.jl)**
>
> Add Conda dependencies to your Julia project. Contribute to JuliaPy/CondaPkg.jl development by creating an account on GitHub.

```julia
julia> using CondaPkg
julia> # now press ] to enter the Pkg REPL
pkg> conda status # see what we have installed
pkg> conda add python perl # adds conda packages
pkg> conda pip_add build # adds pip packages
pkg> conda rm perl # removes conda packages
pkg> conda run python --version # runs the given command in the conda environment
pkg> conda update # update conda and pip installed packages

```

In particular note the `conda pip_add build` command to help you load Python packages installed via pip.

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

In particular, see

> **[Reference · PythonCall & JuliaCall](https://juliapy.github.io/PythonCall.jl/stable/pythoncall-reference/#PythonCall.Core.pyeval)**
>
> 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:** [June 29, 2024, 2:56am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/10 "2024-06-29T02:56:48Z")

</div>

I want to import `read_data()` function  
`dta=read_data(datafile,athinput)`  
from python script to julia script. This python function takes input data from other python scripts output.

---

<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 29, 2024, 3:11am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/11 "2024-06-29T03:11:10Z")

</div>

Yes, I know. First you have to make sure you have the Python packages setup. In your case pyfiles is not on conda-forge so you must use `pip` via CondaPkg.jl as I pointed out above.

Then you might want you to load your Python file by using `pyexec` to `include` the Python file.

---

<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:** [June 29, 2024, 3:12am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/12 "2024-06-29T03:12:39Z")

</div>

@mkitti I have modified `pyfiles` in my local directory. I don’t need to add official `pyfiles` as they would not work for me as i have to do some modifications. My local modified `pyfiles` is having extra `.py` files 👇

```julia
   ~/Pi/MikiFor2to3/pyfiles  ls  ✔ 
athena_read.py fm_torus.pyc metric.py read_athinput.py read_data.pyc
athena_read.pyc __init__.py metric.pyc read_athinput.pyc unimesh.py
fm_torus.py __init__.pyc __pycache__ read_data.py unimesh.pyc

```

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [June 29, 2024, 5:27am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/13 "2024-06-29T05:27:35Z")

</div>

I’m sorry to repeat this, but this is still a Python problem. You did not learn how to _add your local package to an environment_ (conda being more relevant here) as suggested in the previous thread. Your `athinput=run("...")` line doesn’t even begin to resemble Python’s import statement or PythonCall’s `pyimport` wrapper, and it makes me suspect that you were just running .py files instead of importing packages at all. `pyexec` wraps Python’s exec, but I heavily recommend you don’t do such an unidiomatic practice to submodules of `pyfiles`, assuming you intended it to have a package structure. Please learn more about Python in the appropriate Python forums where you can expect many more knowledgeable Python users.

---

<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 29, 2024, 7:05am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/14 "2024-06-29T07:05:49Z")

</div>

```julia
using Pkg
Pkg.activate(".")
Pkg.add(["PythonCall", "CondaPkg"])
# maybe skip the next line?
run(`git clone https://github.com/tianjos/pyfiles`)
using CondaPkg
CondaPkg.add_pip("pyfiles", version="@./pyfiles")
using PythonCall
const pyfiles = PythonCall.pyimport("pyfiles")

```

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [June 29, 2024, 7:28am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/15 "2024-06-29T07:28:10Z")

</div>

> [@raman\_kumar](#):
>
> I have modified `pyfiles` in my local directory.

UPDATE:  
The code above might already work if the folder with your version of pyfiles is a subfolder of your Julia project.

---

<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:** [June 30, 2024, 10:56am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/16 "2024-06-30T10:56:55Z")

</div>

I have python package `pyfiles` in local directory in my laptop at location: 👉 `/home/raman/Pictures/MikiFor2to3/pyfiles/` How can i import functions in it from Julia?

---

<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, 10:59am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/17 "2024-06-30T10:59:43Z")

</div>

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

See [GitHub - JuliaPy/CondaPkg.jl: Add Conda dependencies to your Julia project](https://github.com/JuliaPy/CondaPkg.jl?tab=readme-ov-file#can-i-install-a-package-from-a-url-or-file) .

---

<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:** [June 30, 2024, 11:05am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/18 "2024-06-30T11:05:56Z")

</div>

I am getting 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 Resolving changes
             + build (pip)
             + pip
             + pyexec
    CondaPkg Installing packages
             │ /home/raman/.julia/artifacts/7973f2c7725e2d0eef7a95159454c4145f0945a2/bin/micromamba
             │ -r /home/raman/micromamba
             │ install
             │ -y
             │ -p /home/raman/.julia/environments/v1.10/.CondaPkg/env
             │ --override-channels
             │ --no-channel-priority
             │ libstdcxx-ng[version='>=3.4,<13.0']
             │ pip[version='>=22.0.0']
             │ pyexec[version='*']
             │ python[version='>=3.8,<4',channel='conda-forge',build='*cpython*']
             └ -c conda-forge
conda-forge/linux-64 Using cache
conda-forge/noarch Using cache
error libmamba Could not solve for environment specs
    The following package could not be installed
    └─ pyexec * does not exist (perhaps a typo or a missing channel).
critical libmamba Could not solve for environment specs
ERROR: LoadError: InitError: failed process: Process(`/home/raman/.julia/artifacts/7973f2c7725e2d0eef7a95159454c4145f0945a2/bin/micromamba -r /home/raman/micromamba install -y -p /home/raman/.julia/environments/v1.10/.CondaPkg/env --override-channels --no-channel-priority "libstdcxx-ng[version='>=3.4,<13.0']" "pip[version='>=22.0.0']" "pyexec[version='*']" "python[version='>=3.8,<4',channel='conda-forge',build='*cpython*']" -c conda-forge`, ProcessExited(1)) [1]

Stacktrace:
  [1] pipeline_error
    @ ./process.jl:565 [inlined]
  [2] run(::Cmd; wait::Bool)
    @ Base ./process.jl:480
  [3] run(::Cmd)
    @ Base ./process.jl:477
  [4] _run(io::IO, cmd::Cmd, args::Any; flags::Any)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:398
  [5] _resolve_conda_install(io::Any, conda_env::Any, specs::Any, channels::Any; create::Any)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:299
  [6] _resolve_conda_install(io::Any, conda_env::Any, specs::Any, channels::Any)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:287
  [7] resolve(; force::Bool, io::IO, interactive::Bool, dry_run::Bool)
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:525
  [8] resolve()
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/resolve.jl:405
  [9] envdir()
    @ CondaPkg ~/.julia/packages/CondaPkg/MmzxM/src/env.jl:70
 [10] init_context()
    @ PythonCall.C ~/.julia/packages/PythonCall/S5MOg/src/C/context.jl:63
 [11] __init__ ()
    @ PythonCall.C ~/.julia/packages/PythonCall/S5MOg/src/C/C.jl:23
 [12] run_module_init(mod::Module, i::Int64)
    @ Base ./loading.jl:1134
 [13] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String)
    @ Base ./loading.jl:1122
 [14] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any})
    @ Base ./loading.jl:1067
 [15] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128)
    @ Base ./loading.jl:1581
 [16] _require(pkg::Base.PkgId, env::String)
    @ Base ./loading.jl:1938
 [17] __require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1812
 [18] #invoke_in_world#3
    @ ./essentials.jl:926 [inlined]
 [19] invoke_in_world
    @ ./essentials.jl:923 [inlined]
 [20] _require_prelocked(uuidkey::Base.PkgId, env::String)
    @ Base ./loading.jl:1803
 [21] macro expansion
    @ ./loading.jl:1790 [inlined]
 [22] macro expansion
    @ ./lock.jl:267 [inlined]
 [23] __require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1753
 [24] #invoke_in_world#3
    @ ./essentials.jl:926 [inlined]
 [25] invoke_in_world
    @ ./essentials.jl:923 [inlined]
 [26] require(into::Module, mod::Symbol)
    @ Base ./loading.jl:1746
during initialization of module C
in expression starting at /home/raman/Fluxes.jl:1

```

when i run `Fluxes.jl` script having lines:

```julia
using Pkg, Interpolations, TensorOperations, DelimitedFiles, PythonCall, CondaPkg
Pkg.activate(".")
CondaPkg.add_pip("pyfiles", version="@./home/raman/Pictures/MikiFor2to3/pyfiles/")
athinput=run(`/home/raman/Pictures/MikiFor2to3/pyfiles/read_athinput.py`))
datafile ="./home/raman/Pictures/sane00.athinput/"

```

and your post [Importing local python code directory function in Julia - #9 by mkitti](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/9)  
gives

> **ERROR**
>
> ```julia
> https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/9?u=raman_kumar
> 
> ```

---

<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, 11:24am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/19 "2024-06-30T11:24:04Z")

</div>

You probably need to edit your CondaPkg.toml or figure out how to remove `pyexec` or whatever that is.

---

<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:** [June 30, 2024, 11:36am UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/20 "2024-06-30T11:36:14Z")

</div>

Thanks, I removed `pyexec` by using `conda rm pyexec`.  
But now on running code 👇

```julia
using Pkg, Interpolations, TensorOperations, DelimitedFiles, PythonCall, CondaPkg
Pkg.activate(".")
CondaPkg.add_pip("pyfiles", version="@./home/raman/Pictures/MikiFor2to3/pyfiles/")
athinput=run(`/home/raman/Pictures/MikiFor2to3/pyfiles/read_athinput.py`))
datafile ="./home/raman/Pictures/sane00.athinput/"

```

i am getting

> **Error**
>
> ```julia
>    ~  julia Fluxes.jl  1 ✘  16s  
> 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: IOError: could not spawn `/home/raman/Pictures/MikiFor2to3/pyfiles/read_athinput.py`: permission denied (EACCES)
> Stacktrace:
> [1] _spawn_primitive(file::String, cmd::Cmd, stdio::Vector{Union{RawFD, IO}})
> @ Base ./process.jl:128
> [2] #784
> @ ./process.jl:139 [inlined]
> [3] setup_stdios(f::Base.var"#784#785"{Cmd}, stdios::Vector{Union{RawFD, IO}})
> @ Base ./process.jl:223
> [4] _spawn
> @ ./process.jl:138 [inlined]
> [5] run(::Cmd; wait::Bool)
> @ Base ./process.jl:479
> [6] run(::Cmd)
> @ Base ./process.jl:477
> [7] 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:** [June 30, 2024, 12:38pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/21 "2024-06-30T12:38:07Z")

</div>

> [@raman\_kumar](#):
>
> ```julia
> athinput=run(`/home/raman/Pictures/MikiFor2to3/pyfiles/read_athinput.py`))
> 
> ```

Here you are trying to execute a Python script as another process. I do not think that is your intention.

---

<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:** [June 30, 2024, 12:39pm UTC](https://discourse.julialang.org/t/importing-local-python-code-directory-function-in-julia/116315/22 "2024-06-30T12:39:22Z")

</div>

What should i do to import python script `read_data()` function in Julia?

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