Working with Python 3

Running Python 3 code in the interactive console

  1. Open a console view: Window > Console.
  2. Use the New Console drop-down and choose Python Console.

    New Python console

  3. Select "Python console" in the next dialog box.
  4. Enter your Python 3 code...

    Python console input

Running Python 3 code from the Python Editor

  1. Create a new project.
  2. Open the Project properties: Right-click on the project and choose "Properties" (or use Alt+Enter)
  3. Select section "Python - Interpreter" and switch the Project type to "Python":

    Project Python Interpreter

  4. Create a new Python script in the "scripts" folder
  5. Focus the Python Editor and hit F9. The script will be run with the configured Project Python Interpreter.
  6. Any print output or error messages will appear in a correspondingly named output console:

    Print output message

Managing Python Interpreters

Python 3 interpreters can be managed in the Python Preferences at Preferences > Python > Interpreters > Python Interpreters

Manage Python Interpreters

It is recommended to use separate virtual environments for larger Python scripts and minimize sharing the environments across projects. This allows independent management of 3rd party packages without affecting other projects.

Note:
In this Beta release of the Python 3 API, UI support for managing custom virtual environments is limited and therefore requires configuration on the command line (see below).

Creating custom virtual environments for CityEngine

In the following, let "ce_python_home" be the location of the CityEngine Python support files:

  • On Windows, this is "C:\Program Files\ArcGIS\CityEngine2025.1\plugins\com.esri.pythonbridge.win32.win32.x86_64_xxx"
  • On Linux, this is "${HOME}/arcgis/cityengine2025.1/plugins/com.esri.pythonbridge.gtk.linux.x86_64_xxx"

Let "api_version" be the version of the "cityengine" API package, for example "0.0.1+ce2025111624" in above screenshot (the actual value changes per release).

  1. Open a command line terminal.
  2. To create a new virtual environment, run the following command (on Linux, use `python3.11` from the system path instead):
    "[ce_python_home]\python\python.exe" -m venv [new virtual environment location]
  3. Add the "cityengine" API package to your new virtual environment:

    [new virtual environment location]\Scripts\python.exe -m pip install [ce_python_home]\api_pkg_cache\cityengine-[api_version]-py3-none-any.whl

  4. In the CityEngine interpreter manager, choose New > Browse for python/pypy.exe and navigate to "[new virtual environment location]\Scripts\python.exe" (on Linux, it is "[new virtual environment location]/bin/python").
  5. Give it a distinct name:

    Name the interpreter

  6. The intepreter from the new virtual environment is now listed, including the "cityengine" API package:

    Customize interpreter

See also