COMMUNITY

Compile hello world python

I have the following haxe code:

class Main {
  static function main() {
    Sys.println("haxe:) " + Sys.programPath());
  }
}

And my hxml looks like

--class-path src
-main Main
--python bin/binPython/main.py

When I run python bin/binPython/main.py I get the following error:

Traceback (most recent call last):
File “bin/binPython/main.py”, line 613, in
Main.main()
File “bin/binPython/main.py”, line 43, in main
python_Lib.printString((("" + (“null” if _hx_str is None else _hx_str)) + HxOverrides.stringOrNull(python_Lib.lineEnd)))
File “bin/binPython/main.py”, line 529, in printString
python_lib_Sys.stdout.buffer.write(_hx_str.encode(encoding, “strict”))
AttributeError: ‘file’ object has no attribute ‘buffer’
Error: Command failed with error 1

I have tried some different python versions, most lately but it doesn’t seem to work

I found that the vscode terminal said a different python version than the external terminal.

Then I found out everything worked fine with python3

-cmd python3 --version // Python 3.9.1
-cmd python3 bin/binPython/main.py

Yes, Haxe targets Python 3.