- Home /
Python for Unity - Running python alongside unity
Python for Unity: 4.0.0-pre.1
MacOS: 11.5.2
Unity: 2021.2.5f1
Python: 3.9.6
I have a python script which runs indefinitely, communicating with unity via TCP. Launching the script once is all i need but executing PythonRunner.RunFile($"{Application.streamingAssetsPath}/main.py");
Runs the python script but unity does not run with it. Only after I quit python, does unity run. Is there a way to avoid this?
EDIT: I want to package this so that when the user launches the game, the python script gets executed automatically. If the user does not have python installed on their machine, executing the python script with shell script does not work. Since PythonRunner executes the script with the interpreter provided in the Library folder, using it will avoid that specific issue.
Answer by xxmariofer · Dec 10, 2021 at 08:22 AM
Have you tested running the python script from terminal instead of using PythonRunner class
Yes, it works fine there but I want to package this so that when the user launches the game, the python script gets executed automatically. If the user does not have python installed on their machine, executing the script via ter$$anonymous$$al ( I'm assu$$anonymous$$g by using a shell script) will not work. Since PythonRunner executes the script with the interpreter provided in the Library folder, this will avoid that specific issue.
is this the method you are trying to call?
if so, its an editor script, those scripts dont get compiled in build and you wont be able to use it outside the editor.
even if it wasnt an editor package, to use python in your build there are 2 chances, or unity compile the python script to c++ code, so the script would neeed to be in the project before building, or you need to deploy a full python installation on the user machine
Oh, thanks for clarifying.
Is it possible to share an article about how to do the 2 methods you suggested?
Your answer
Follow this Question
Related Questions
How to implement global AI and Activities? 0 Answers
How to run a python script from Unity? 0 Answers
python for unity ubuntu 0 Answers
Is it possible to use the Open Babel Python module in Unity? 1 Answer
Runtime Python interpreter 0 Answers