-
Notifications
You must be signed in to change notification settings - Fork 2
Python.NET
Jacob edited this page May 27, 2021
·
30 revisions
- Download the latest NuGetForUnity .unitypackage here
- In Unity, go to Assets > Import Package > Custom Package, locate where you downloaded NuGetForUnity, and install it.
- You should now see NuGet in the Unity menu bar.
- In Unity, go to NuGet > Manage NuGet Packages, select
Show All VersionsandShow Prerelease. - Search for pythonnet.
- Install pythonnet Version 3.0.0-preview2021-05-03.
- Download a version of embedded python. I used latest release for winx64
- In Unity, create a new folder under Assets called StreamingAssets.
- Extract the .zip of your downloaded Python into the StreamingAssets folder.
- To enable pip, download get-pip.py and save it in the Python folder (Assets/StreamingAssets/python-3.9.5-embed-amd64)
- Run get-pip.py in command line. First cd into Assets/StreamingAssets/python-3.9.5-embed-amd64, then execute
python.exe get-pip.py
- Now you can install any module you want with
python.exe -m pip install module-name
- You should go to Edit > Project Settings > Player > Other Settings > Configuration and change the Api Compatibility Level to .Net 4.x to be safe. Apparently there can be some issues using .Net Standard 2.0.
- In a C# script you will want to include in the Start() method
void Start()
{
Runtime.PythonDLL = Application.dataPath + "/StreamingAssets/python-3.9.5-embed-amd64/python39.dll";
PythonEngine.Initialize(mode: ShutdownMode.Reload);
}