Python Scripting issue

Hi All,

I am probably making a very basic mistake here as i am new to python, but I am having an issue where I run scripts by copy pasting the code driectly into the output log it works perfectly. But if I try to run the same script from a .py file on disk via the GUI or command line I get the following error:


Cmd: py ../../../../../../Users/christopher.zoog/Downloads/PythonExamples/PythonExamples/Unreal Studio Examples/ConvertActors/convert_actors.py
LogPython: Error: SyntaxError: invalid syntax (<string>, line 1)

The same code inside the convert_actors.py works fine if copy/pasted. Just curious as to what i am doing wrong.

I’ve unblocked the .py so that shouldn’t be it.

Thanks,
Chris

Are you using 4.20? The UI failing to run a script in a path containing spaces is a known issue with 4.20 preview 1, and has been fixed for preview 2.

If you run the file from the output log you should be able to work around the issue by wrapping the filename/path in quotes to mitigate the spaces, eg) “my path/script.py”

Yup, it was 4.20. Thanks so much for the quick reply, just wanted to make sure I wasn’t missing something obvious! The quote workaround works for me.

Thanks. It seems my fix might have also missed preview 2, but it will be in the next one :slight_smile:

This issue appears to be happening for version 5.3 on windows, despite no spaces occurring in the file path:

Is this a known issue for version 5.3? I have enabled the Python plugins for scripting:

Toggling Developer Mode, within Edit > Project Settings > Plugins - Python as in the following, resolved the issue:

This step seems to be missing from the documentation: Scripting the Unreal Editor Using Python

Anything else you may have done? I’m running into the same issue, toggling developer mode didn’t fix it for me.

If you are in the python command line toggle, you do not need to type py Path-to-python-script just type the path to the python script
image