Skip to content

Instantly share code, notes, and snippets.

@k4sima
Last active January 13, 2022 06:10
Show Gist options
  • Save k4sima/e6a32dcf9cf472e133807ee728c7088b to your computer and use it in GitHub Desktop.
Save k4sima/e6a32dcf9cf472e133807ee728c7088b to your computer and use it in GitHub Desktop.
python-in-unity-test
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Python.Runtime;
using UnityEngine.UI;
public class pythontest : MonoBehaviour
{
[SerializeField] private Text text;
void Start()
{
Runtime.PythonDLL = Application.dataPath + "/StreamingAssets/python39/python39.dll";
PythonEngine.Initialize(mode: ShutdownMode.Reload);
RunPython();
}
public void OnApplicationQuit()
{
if (PythonEngine.IsInitialized)
{
PythonEngine.Shutdown(ShutdownMode.Reload);
}
}
private void RunPython()
{
using (Py.GIL())
{
dynamic sysModule = Py.Import("sys");
text.text = sysModule.version; //syatem info
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment