简体   繁体   中英

How to compile Python code into a shared library to be used in a C# application (like Unity)?

I have a bunch of Python code with a lot of dependencies (pytorch, opencv, etc.) that I want to use in a Unity application that can be deployed on both PCs and mobile devices. After a lot of research, I found that the most painless way seems to be compiling my code into a shared library for the Unity application to call. However, I don't know what is the best way to do it.

One way that I've been considering has been embedding Python into C++, and then compile it into a shared library. But according to what I've tried so far I still need to have the Python code around for the C++ library to call. That would be quite difficult considering the number of dependencies (the app is to be deployed onto mobile devices).

I wonder if there is a way to compile my Python code into a standalone shared library that can be called in a Unity application?

You can use IronPython it will execute scripts directly in C#, because ironPython is just like Cpython probably the one your using but written in C# not C

Get IronPython at www.ironpython.net Not an ad

Or see this

How do I run a Python script from C#?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM