Search Unity

  1. Curious about what's going to be in 2020.1? Have a look at the 2020.1 beta blog post.
    Dismiss Notice
  2. Want to see 2020.1b in action? Sign up for our Beta 2020.1 Overview Webinar on April 20th for a live presentation from our evangelists and a Q&A session with guests from R&D.
    Dismiss Notice
  3. Interested in giving us feedback? Join our online research interviews on a broad range of topics and share your insights with us.
    Dismiss Notice

Introducing Python for Unity Editor

Discussion in 'External Tools Previews' started by Matjio, Jan 20, 2020.

Thread Status:
Not open for further replies.
  1. Matjio

    Matjio

    Unity Technologies

    Joined:
    Dec 1, 2014
    Posts:
    27
    Python for Unity Editor now available as a preview package!

    Introduction

    Python is the standard scripting language for Pipeline TDs (Technical Directors) in the film industry, and in general for content creation oriented workflows.

    After working closely with different production studios and partners (animated films, games, automotive, theme park ride, production management tools, ...) we are releasing a Preview package of Python for Unity which allows access from Python to the full C# API of UnityEditor, UnityEngine, as well as your own C# APIs added to your Unity projects, and running Python code from within C#.

    Typical use cases are:
    • Integration of existing pipeline tools written in Python and PySide.
    • Integration of third-party software like Autodesk Shotgun (Preview integration package to come soon).
    • Integration with third-party libraries like Pixar OpenTimelineIO (Experimental integration package to come soon)
    • Scene debugging in Unity using the Python Console
    This release is built primarily as a tool for pipeline TDs at studios. There is currently no intention to make Python a scripting language for Gameplay.

    Installation
    Because this package requires preliminary software installations and configurations, we have decided to not expose the package in the Unity Package Manager window, so Python for Unity requires some manual installation:
    1. First, follow the installation instructions in the manual
    2. Next, install Python for Unity itself: Edit your Unity manifest.json file (in the Packages folder of your project) so that it starts with
    Code (CSharp):
    1. {
    2.   "dependencies": {
    3.     "com.unity.scripting.python": "2.0.1-preview.2",
    Known issue: If Unity crashes on startup when you open a project that uses Python it might be an issue with Python 3 which would be earlier in the %PATH% on Windows. The current work around is to Uninstall Python 3, reinstall Python 2.7, then restart the Unity Hub before trying again (or reboot to make absolutely sure). We are still investigating this issue. We are also working on Python 3 support and embedded Python environment to facilitate the installation.

    Bug fix release: [2.0.1-preview.2] - 2020-02-13
    FIXES over 2.0.0-preview.6
    * Improved handling of a Python installation that can't find its home. Unity now displays an error rather than crashing.
    * Fixed repeated registration of an OnUpdate callback.
    * Prevented the Python top-level menu being added by default. Unpack the sample clients manually from the Package Manager instead.
    * The tilde character (~) in Python path and site-packages is now interpreted as the user home directory on all platforms.
    * In the Python Console, Ctrl-enter with no selection now executes the entire script (Cmd-enter on macOS).
    * Fixed the year in 2.0.0-preview.6 release date. It's already 2020 apparently! :)

    Your first Python script:

    Go to Window -> General -> Python Console
    Type the following code in the bottom window and click on the Execute button:

    Code (JavaScript):
    1. import UnityEngine
    2. print ("I can print using python")
    3. UnityEngine.Debug.Log("hello Unity world")
    Documentation is available here.

    There is also a suite of examples showing Python code calling C# and C# running Python code that can be found in the Python package folder.

    Platform

    Python for Unity is Editor-only. It doesn’t work in standalone builds.
    Our integration supports Windows, Mac and Linux Unity Editors.
    We started with support of Python 2.7 as many film and animation studios have not ported all their tools to more recent libraries. Python 3 support is in the works.

    Feedback

    We have heard your feedback, and the next 2 priorities are currently:
    • Python 3.7 (yes we know we are in 2020 and Python 2.7 is end of life, but we wanted at least one public version supporting 2.7)
    • Embedded Python environment
    Please send us more feedback in this sub-forum for what you’d like to see in the package.

    To report bugs, use the bug reporter in the Editor with a stripped down version of the project in order for our development team to reproduce the issue.
     
    Last edited: Feb 26, 2020
    sirjoan620, ikseek, bao_bao and 13 others like this.
  2. Matjio

    Matjio

    Unity Technologies

    Joined:
    Dec 1, 2014
    Posts:
    27
    New package available!
    ## [2.0.1-preview.2] - 2020-02-13
    this is a bugfix release for 2.0.0-preview.6
    FIXES
    * Improved handling of a Python installation that can't find its home. Unity now displays an error rather than crashing.
    * Fixed repeated registration of an OnUpdate callback (thanks @MostHated for finding it!).
    * Prevented the Python top-level menu being added by default. Unpack the sample clients manually from the Package Manager instead.
    * The tilde character (~) in Python path and site-packages is now interpreted as the user home directory on all platforms.
    * In the Python Console, Ctrl-enter with no selection now executes the entire script (Cmd-enter on macOS).
    * Fixed the year in 2.0.0-preview.6 release date. It's already 2020 apparently! :)

    Package manager:
    Code (CSharp):
    1. {
    2.   "dependencies": {
    3.     "com.unity.scripting.python": "2.0.1-preview.2",
     
    Last edited: Feb 26, 2020
Thread Status:
Not open for further replies.
unityunity