# Launching external programs from Julia

**URL:** <https://discourse.julialang.org/t/launching-external-programs-from-julia/129419>\
**Category:** General Usage\
**Created:** [May 28, 2025, 7:53pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419 "2025-05-28T19:53:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [May 28, 2025, 7:53pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/1 "2025-05-28T19:53:46Z")

</div>

I’ve been trying to figure out how to launch an external program from Julia, and I am stumped.

In Python, I can do this:

```julia
os.system("exec python -m PyQt5.uic.pyuic evaluate.ui -o ui_Evaluate.py -x")

```

I’ve tried most of the examples in this thread: [Better support for running external commands - #25 by StevenSiew](https://discourse.julialang.org/t/better-support-for-running-external-commands/44933/25)

…but none of them work.

For example, even a simple line like this

```julia
run(Cmd(`exec python`))

```

gives me an error:

```julia
ERROR: IOError: could not spawn `exec python`: no such file or directory (ENOENT)

```

or even

```julia
run(Cmd(`python`))

```

```julia
ERROR: IOError: could not spawn `python`: no such file or directory (ENOENT)

```

The “bashit()” example in the above mentioned thread gives the same error.

Finally, I decided to try to use PyCall, which should allow me to use the same code I’ve successfully been using in Python. Instead…

```julia
os = pyimport("os")
os.system("exec python -m PyQt5.uic.pyuic evaluate.ui -o ui_Evaluate.py -x")

```

which yields: `sh: line 0: exec: python: not found`

Yet, that works in Python, and it works in the command line. So why can’t python be found when calling os.system() from Julia via PyCall? After reading the documentation for Python’s os.system(), apparrently it just calls “Standard C function `system()`”. So why not skip Python and use ccall instead?

```julia
@ccall system("exec python -m PyQt5.uic.pyuic evaluate.ui -o ui_Evaluate.py -x"::Cstring)::Cstring

```

Failure: `sh: line 0: exec: python: not found`

So what am I doing wrong? Why does system() work in Python, but but gives me grief when called from Julia, using either PyCall or CCall?

---

<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:** [May 28, 2025, 8:05pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/2 "2025-05-28T20:05:28Z")

</div>

It means the python executable is not in the PATH environment variable, in the environment that launched Julia. Which OS are you using?

---

<div class="post-metadata">

**Author:** ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)\
**Post date:** [May 28, 2025, 8:16pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/3 "2025-05-28T20:16:53Z")

</div>

This isn’t the problem stumping you, but

> [@mpeters2](#):
>
> `Cmd(`exec python`)`

is redundant.

```julia
julia> typeof(`python`)
Cmd

julia> typeof(Cmd(`python`))
Cmd

julia> Cmd(`python`) == `python`
true

julia> run(`python`)
Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^Z

```

It’s like saying `String("python")`

---

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [May 28, 2025, 8:26pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/4 "2025-05-28T20:26:39Z")

</div>

I’m using MacOS and VSCode. Do I need to set this in VSCode, or somewhere else?

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 28, 2025, 8:54pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/5 "2025-05-28T20:54:36Z")

</div>

Are you 100% sure you have an executable called `python` in the first place? On many systems it’d be called `python3`

---

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [May 28, 2025, 9:07pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/6 "2025-05-28T21:07:03Z")

</div>

Yep. When I type “python” in the terminal, I get:

```julia
Python 3.10.16 | packaged by conda-forge | (main, Dec 5 2024, 14:20:01) [Clang 18.1.8] on darwin
Type "help", "copyright", "credits" or "license" for more information.

```

---

<div class="post-metadata">

**Author:** ![dilumaluthge](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dilumaluthge/32/29283_2.png) [@dilumaluthge](https://discourse.julialang.org/u/dilumaluthge)\
**Post date:** [May 28, 2025, 9:09pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/7 "2025-05-28T21:09:30Z")

</div>

Are you on Windows? Can you try this in Julia?

```julia
julia> run(`python.exe`)

```

And/or this?

```julia
julia> run(`python3.exe`)

```

---

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [May 28, 2025, 9:10pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/8 "2025-05-28T21:10:07Z")

</div>

I just tried replacing “python” with “python3”, and I get:

`(ModuleNotFoundError: No module named 'PyQt5')`

So, whatever environment that is launched with Julia, it’s not the same as the one used by Terminal.app.

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [May 28, 2025, 10:01pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/9 "2025-05-28T22:01:11Z")

</div>

If I type `which Python3` into the terminal, I get the path to the executable:

```julia
eben60@Mac ~ % which python3
/opt/homebrew/bin/python3

```

Could you probably try

```julia
run(Cmd(`/opt/homebrew/bin/python3 -m PyQt5.uic.pyuic evaluate.ui -o ui_Evaluate.py -x `))

```

(replace by the actual path on your computer)

---

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [May 28, 2025, 10:04pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/10 "2025-05-28T22:04:08Z")

</div>

Update: I ran the following code from within Julia:

`@ccall system("printf \"%s\n\" \$PATH"::Cstring)::Cstring`

…and apparently the PATH variables used by VScode are not the ones used by Terminal.app or by Spyder.

EDIT: I did the same thing from within the bash shell in VScode, and it has the same environmental variables as Spyder and Terminal.app! Arggghh!

Edit 2: I also checked the REPL in VScode and by launching Julia from Terminal.app

**All PATH variables present:**  
Terminal.app  
Spyder  
VScode bash shell  
Julia (Terminal.app) REPL

**Incomplete PATH variables:**  
running Julia program in VScode  
VScode REPL.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [May 28, 2025, 10:05pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/11 "2025-05-28T22:05:41Z")

</div>

```julia
ENV["PATH"]

```

is probably easier 😉

---

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [May 28, 2025, 10:07pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/12 "2025-05-28T22:07:57Z")

</div>

On my mac, I get following

```julia
julia> c = Cmd(`/opt/homebrew/bin/python3 -c 'print("Hi world")' `);

julia> run(c)
Hi world
Process(`/opt/homebrew/bin/python3 -c 'print("Hi world")'`, ProcessExited(0))

julia> c1 = Cmd(`python -c 'print("Hi world")' `);

julia> run(c1)
xcode-select: Failed to locate 'python', requesting installation of command line developer tools.
ERROR: failed process: Process(`python -c 'print("Hi world")'`, ProcessExited(72)) [72]

Stacktrace:
 [1] pipeline_error
   @ ./process.jl:598 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base ./process.jl:513
 [3] run(::Cmd)
   @ Base ./process.jl:510
 [4] top-level scope
   @ REPL[9]:1

julia> c2 = Cmd(`python3 -c 'print("Hi world")' `);

julia> run(c2)
Hi world
Process(`python3 -c 'print("Hi world")'`, ProcessExited(0))

```

---

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [May 28, 2025, 10:21pm UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/13 "2025-05-28T22:21:46Z")

</div>

I think I had remapped Python to Python3,

And its not that it can’t find Python, but that it is finding the wrong Python. Since it also has the wrong PATH variable, I’m guessing that it’s finding the default Apple Python installation (which is why it can’t find QT).

---

<div class="post-metadata">

**Author:** ![mpeters2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mpeters2/32/202247_2.png) [@mpeters2](https://discourse.julialang.org/u/mpeters2)\
**Post date:** [May 29, 2025, 2:19am UTC](https://discourse.julialang.org/t/launching-external-programs-from-julia/129419/14 "2025-05-29T02:19:54Z")

</div>

The solution was to go into VScode’s settings.json and change this line from false to true:

```
"terminal.integrated.inheritEnv": true,

```
