# UE4.27 crashes while running python script on CMD

**URL:** <https://forums.unrealengine.com/t/ue4-27-crashes-while-running-python-script-on-cmd/494018>\
**Category:** Editor Scripting\
**Tags:** unreal-engine, UE4, question, UE4-27\
**Created:** [February 4, 2022, 1:38am UTC](https://forums.unrealengine.com/t/ue4-27-crashes-while-running-python-script-on-cmd/494018 "2022-02-04T01:38:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PengSengAng](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PengSengAng](https://forums.unrealengine.com/u/PengSengAng)\
**Post date:** [February 4, 2022, 1:38am UTC](https://forums.unrealengine.com/t/ue4-27-crashes-while-running-python-script-on-cmd/494018/1 "2022-02-04T01:38:23Z")

</div>

When i execute this script in UE4, it works successfully.  
When i run this script on command line with:

“C:\Program Files\Epic Games\UE\_4.27\Engine\Binaries\Win64\UE4Editor-Cmd.exe” “C:\Users\Documents\Unreal Projects\test\test.uproject” -run=pythonscript -script=“D:/test\_unreal.py”

I get this error and UE4 crashes:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/e/3/be34052e0f3477a116d2b5c4eaa14fc341f63c00.png)

The python script has only these lines:

import unreal  
import time  
unreal.EditorLevelLibrary.load\_level(asset\_path=’/Game/StarterContent/Maps/Minimal\_Default’)  
unreal.EditorLevelLibrary.spawn\_actor\_from\_object(unreal.CameraActor(name=‘camera1’), location=(0,0,0))

Up to the third line it works fine, but its the 4th line that crashes UE when running it from command line. Anyone knows why??

---

<div class="post-metadata">

**Author:** ![UE\_FlavienP](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ue_flavienp/32/1194546_2.png) [@UE\_FlavienP](https://forums.unrealengine.com/u/UE_FlavienP)\
**Post date:** [February 4, 2022, 11:27am UTC](https://forums.unrealengine.com/t/ue4-27-crashes-while-running-python-script-on-cmd/494018/2 "2022-02-04T11:27:12Z")

</div>

It can be because you are running the editor in headless mode and in that case some of the context is not loaded.

Just to check does it work if instead you do  
`“C:\Program Files\Epic Games\UE_4.27\Engine\Binaries\Win64\UE4Editor-Cmd.exe” “C:\Users\Documents\Unreal Projects\test\test.uproject” -ExecutePythonScript="D:/test_unreal.py"`

Drawback is that it is slower and you have a full UE starting.

---

<div class="post-metadata">

**Author:** ![Anonymous\_9fe7be10542cf6d7944be2b3fd498685](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_9fe7be10542cf6d7944be2b3fd498685](https://forums.unrealengine.com/u/Anonymous_9fe7be10542cf6d7944be2b3fd498685)\
**Post date:** [February 14, 2024, 3:15am UTC](https://forums.unrealengine.com/t/ue4-27-crashes-while-running-python-script-on-cmd/494018/3 "2024-02-14T03:15:04Z")

</div>

Do you know how to solve Unreal5.3? I hope to open the Unreal project file in an external Python editor and execute the Python script I execute in Unreal  
-It seems that ExecutePythonScript did not execute my Python script  
And if I use it, but it only pops up a box and doesn’t actually open the Unreal editor. I look forward to your reply very much, thank you!

```auto
import subprocess
subprocess.Popen([
    "path/to/UnrealEditor-Cmd.exe", "path/to/my.uproject", '-run=pythonscript',
    '-script="path/to/myscript.py"'
])

```
