最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to Package a Unity Application with a Python Script into a Single Executable? - Stack Overflow

programmeradmin3浏览0评论

I want to develop a Unity application that communicates with a Python script via socket to exchange information. However, I don’t want to run Unity and the Python script separately. Is there a way to package everything into a single executable, ensuring that the Python script runs alongside the Unity application? How can I achieve this?

I was thinking of doing something via the terminal, but I’m not sure how to proceed. I’d like some ideas on possible ways to make this work in my case.

I want to develop a Unity application that communicates with a Python script via socket to exchange information. However, I don’t want to run Unity and the Python script separately. Is there a way to package everything into a single executable, ensuring that the Python script runs alongside the Unity application? How can I achieve this?

I was thinking of doing something via the terminal, but I’m not sure how to proceed. I’d like some ideas on possible ways to make this work in my case.

Share Improve this question asked Mar 23 at 18:45 Mário SantanaMário Santana 11 bronze badge 9
  • run python inside unity? – BugFinder Commented Mar 23 at 18:48
  • Or as a background Process ? – derHugo Commented Mar 23 at 18:49
  • stackoverflow/questions/71179346/… – derHugo Commented Mar 23 at 18:51
  • @BugFinder Yes, the idea is to run a neural network in Python, like MediaPipe, to process webcam data and send the results to Unity via socket. For example, Python could track the user's hand and send the data in real-time to control a virtual hand in Unity. – Mário Santana Commented Mar 23 at 18:54
  • @derHugo Yes, Python would run in the background using Process, but I want to package everything into a single executable so the user doesn’t have to start Unity and Python separately. I want the program to launch everything together automatically. – Mário Santana Commented Mar 23 at 18:54
 |  Show 4 more comments

1 Answer 1

Reset to default 0

If this is for a windows build I think there are mainly three options

Have your users install python as dependency

Probably not really desirable as it requires additional steps by your users and might of course introduce hickups

Portable Python

You could give it a shot and simply pack WinPython (a fully portable python) into your project and then as mentioned run a Process using that library to then run your python server script.

This depends a bit on your python requirements. There is a minimal version and also a very huge "complete" version - but nothing custom inbetween.

Compile to Exe

Similar to above but alternatively you could also use a tool like e.g. Py2Exe and beforehand already compile your python server script into an .exe file. You can then again simply pack it into your project and run via Process from within your c# code.

发布评论

评论列表(0)

  1. 暂无评论