A issue to use PythonCall to call a Simple Python File Of WxPython Hello World

Hello, I am new to Julia and just start to learn it this week. I got a problem to use PythonCall to call a Simple Python File Of WxPython Hello World. My Julia code and Python code are below. When I ran Julia code the below an error came out, I have searched online and tried many ways, but no luck. It looks like it can not find python.exe, but I am sure it is under the folder “C:\Python-3.12\python.exe”. is there a way to fix it? Thanks a lot! I appreciate it.

"
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Apps > Advanced app settings > App execution aliases.
ERROR: failed process: Process(python 'C:\JuliaTryOut\Test01.py', ProcessExited(9009)) [9009]

Stacktrace:
[1] pipeline_error
@ .\process.jl:597 [inlined]
[2] run(::Cmd; wait::Bool)
@ Base .\process.jl:512
[3] run(::Cmd)
@ Base .\process.jl:509
[4] top-level scope
@ c:\JuliaTryOut\Test01.jl:18
"

-------------------My Julia Code---------------------------------------------------------
ENV[“JULIA_CONDAPKG_BACKEND”] = “Null”;

ENV[“JULIA_PYTHONCALL_EXE”] = “C:\Python-3.12\python.exe”

using PythonCall

pyimport(“sys”).path.append(pwd())

println(PythonCall.C.CTX.exe_path)

#pyexec(read(“Test01.py”, String));

run(python C:\\JuliaTryOut\\Test01.py)

-------------------My Python File Test01.py-------------------------------------------------------------
import wx

class MyFrame(wx.Frame):
def init(self):
# Initialize the parent class (wx.Frame)
super().init(parent=None, title=‘Hello World’, size=(300, 200))

    # Add a panel to the frame for better layout management
    panel = wx.Panel(self)

    # Add static text to the panel
    self.text = wx.StaticText(panel, label="Hello, wxPython!", pos=(100, 70))

if name == ‘main’:
# 1. Initialize the Application
app = wx.App()

# 2. Create and show the main frame
frame = MyFrame()
frame.Show()

# 3. Start the main event loop
app.MainLoop()

Hello,

Welcome to the community!

Can you please enclose the code and the error message in your message in triple backticks, like ``` ?

That makes it easier to read.

ufechner7, is the below format one you want?

-------------------Error Message---------------------------------------------------------
‘’’
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Apps > Advanced app settings > App execution aliases.
ERROR: failed process: Process(python 'C:\JuliaTryOut\Test01.py', ProcessExited(9009)) [9009]

Stacktrace:
[1] pipeline_error
@ .\process.jl:597 [inlined]
[2] run(::Cmd; wait::Bool)
@ Base .\process.jl:512
[3] run(::Cmd)
@ Base .\process.jl:509
[4] top-level scope
@ c:\JuliaTryOut\Test01.jl:18
‘’’

-------------------My Julia Code---------------------------------------------------------
‘’’
ENV[“JULIA_CONDAPKG_BACKEND”] = “Null”;

ENV[“JULIA_PYTHONCALL_EXE”] = “C:\Python-3.12\python.exe”

using PythonCall

pyimport(“sys”).path.append(pwd())

println(PythonCall.C.CTX.exe_path)

#pyexec(read(“Test01.py”, String));

run(python C:\\JuliaTryOut\\Test01.py)
‘’’

-------------------My Python File Test01.py-------------------------------------------------------------
‘’’
import wx

class MyFrame(wx.Frame):
def init(self):
# Initialize the parent class (wx.Frame)
super().init(parent=None, title=‘Hello World’, size=(300, 200))

    # Add a panel to the frame for better layout management
    panel = wx.Panel(self)

    # Add static text to the panel
    self.text = wx.StaticText(panel, label="Hello, wxPython!", pos=(100, 70))

if name == ‘main’:
# 1. Initialize the Application
app = wx.App()

# 2. Create and show the main frame
frame = MyFrame()
frame.Show()

# 3. Start the main event loop
app.MainLoop()

‘’’

Sorry, you are not there yet.

Firstly, you can edit your post. Better than creating a new post.

Secondly, you used three right single quotation marks (U+2019, often called curly or typographic apostrophes). Backticks (`), by contrast, are straight grave accents (U+0060) used in computing for code blocks, template literals, and command substitution.

Try to copy-and-paste the backticks from my post if you cannot find them on your keyboard: ```

See also: Please read: make it easier to help you

1 Like

It sounds like Python is not on your PATH. You could simply add it:

ENV["PATH"] = "C:\\Python-3.12;" * ENV["PATH"]

(note the ;).

Now your

run(`python C:\\JuliaTryOut\\Test01.py`)

should work. You can also avoid messing with PATH entirely by just providing the complete Python path:

run(`C:\\Python-3.12\\python.exe C:\\JuliaTryOut\\Test01.py`)

Note that we have not used PythonCall.jl here. If you just want to run a Python script, but not really interact with it, you really don’t need this package. But you could (probably) use

pyexec(read("C:\\JuliaTryOut\\Test01.py", String), Main) 

or

pyexec(read("C:\\JuliaTryOut\\Test01.py", String), PyDict())

If pwd() == “C:\\JuliaTryOut\\", as is presumably the case, you can just use "Test01.py". Compared to what you had commented out, you then just needed the second argument.

When using Windows, path delimiters should either be escaped "C:\\Python-3.12\\python.exe" or you could use raw strings: raw"C:\python-3.12\python.exe".