Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by airfutureguy1 · Dec 10, 2021 at 07:19 AM · python

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Dec 10, 2021 at 08:22 AM

Have you tested running the python script from terminal instead of using PythonRunner class

https://forum.unity.com/threads/run-terminal-command-and-get-output-within-unity-application-osx.683164/#post-4574398

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image airfutureguy1 · Dec 10, 2021 at 08:31 AM 0
Share

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.

avatar image xxmariofer airfutureguy1 · Dec 10, 2021 at 10:12 AM 1
Share

is this the method you are trying to call?

https://docs.unity3d.com/Packages/com.unity.scripting.python@2.0/api/UnityEditor.Scripting.Python.PythonRunner.html

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

avatar image airfutureguy1 xxmariofer · Dec 10, 2021 at 11:42 AM 0
Share

Oh, thanks for clarifying.
Is it possible to share an article about how to do the 2 methods you suggested?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

131 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges