Skip to content

Customizing Dynamo's Python 3 installation

Ashish Aggarwal edited this page Mar 29, 2024 · 55 revisions

Introduction

Dynamo uses what's called the Embeddable Package of Python. This allows Dynamo to have its own Python home, without requiring users to install Python or adding it to the PATH. On the other hand this also makes it harder to find, and adds some extra considerations when installing packages. This guide will explain how to customize this installation.

Where is it?

Dynamo creates the Python home dynamically, so first of all you'll need to run any graph that contains a Python node using the CPython3 engine.

Creating Python Home

Open up a new Dynamo graph, place a single Python node [1], double-click on the Python node to open up the Python editor, the CPython3 engine is selected by default. There is no need to save it!

Python Home Created

After this, the Python home will be created under your local application data folder. You can check this by opening up Windows Explorer and typing into the navigation bar %localappdata% [4]. Inside this folder, you will see a bunch of things and now, since we ran the Dynamo graph, you should also see a folder called python-<VERSION>-embed-amd64 [5]. In the image above, there are two different versions of Python installed here [6].

What <VERSION> you see will depend on the version of Python Dynamo is using:

  • For Dynamo 2.7, this is Python version 3.7.3
  • For Dynamo 2.8, this is Python version 3.8.3
  • For Dynamo 3.0, this is Python version 3.9.12
  • For all other versions of Dynamo, or if you are in doubt which is the correct version, you can always run this code in a Python node to ask Dynamo 😄
import sys
OUT = sys.version

Embeddable Package contents

New Python Environment

If you are familiar with a regular Python installation, you'll notice the structure is different, but most of the components are there:

  • DLL and PYD files are lying in the base folder rather than a subfolder. No big deal.
  • Standard Lib is actually zipped in python39.zip. There is no need to extract it or add it to the path to use it, which is pretty amazing!
  • There is no Scripts folder and pip is nowhere to be found [7]. This is a known caveat but it can be solved.

Installing PIP

Dynamo is using the Python Embeddable Package, which by default does not have pip (Python's version of a Package Manager). As we are currently using this embeddable package, we need to customize it to enable the use of pip.

Download Pip

In order to make pip available please follow these steps:

  1. Download get-pip.py [8] and place it into Dynamo's Python home [9][10].

Fixing Pip Path

  1. Edit the file named python39._pth [11] in Dynamo's Python home by opening with Notepad, removing the # in the last line so that it reads import site [12].

Command Prompt

  1. Navigate to your Python home [13] and copy the path. Inside the Command prompt application navigate to your Python version folder by typing into the Command prompt the path of where your Python version lives. It should look something like this: cd C:\Users\<USERNAME>\AppData\Local\python-<VERSION>-embed-amd64[14] where cd is a call to change directory to your chosen path.

Get Pip

  1. Now that you are in the correct folder, you can run python get-pip.py [15] (the command may vary for you based on your local python installation), which will download and install pip - a successful install will be returned [16]. Don't worry about the warnings related to the PATH, as Dynamo does not need that.

Pip installed

After doing that you should see the Scripts folder, containing pip [17].

Installing Python packages

Install Python Libraries

Now that you have pip installed, our installation is no different than any regular Python installation. You can run .\Scripts\pip install <ANY_PACKAGE> [18] if you are still in the same Command prompt (It simply takes the current directory you are in and the . allows you to temporarily move into a sub-folder) and your chosen package, in our case Numpy [19], will get downloaded under the Lib folder [20].

If you have closed the Command prompt, you will need to navigate to the Scripts sub-folder by typing %localappdata% again. Your path in this case will look similar to: cd C:\Users\<USERNAME>\AppData\Local\python-<VERSION>-embed-amd64\Scripts\ and just run pip install <PACKAGE> directly.

Anything else?

Using an Imported Library

You might be surprised but no. Installed libraries are already available for import [21], you don't need to add anything to sys.path or do anything special. Simply import any of your installed libraries as normal!

import pandas as pd

dataFrame = pd.DataFrame({
	"Name": ["Odinson, Thor",
		"Maximoff, Wanda",
		"Banner, Dr. Bruce",
		"Romanoff, Natasha",
		"Stark, Tony",
		"Danvers, Carol ",
		"Rogers, Steve"],
	"Age": [1505, 24, 54, 39, 53, 65, 38],
	"Sex": ["male","female","male",
		"female","male","female",
		"male"]
})

OUT = repr(dataFrame)

What about virtual environments?

Good question! Virtual environments are not supported by the Python Embeddable Package, probably because, in a way, this is a special Python installation specific for a single application.

What if I see Warning: ModuleNotFoundError even if I followed all the steps above?

Unfortunately something has gone wrong, but never fear - we have a workaround! Simply append the location of site packages to your system path as shown in the code snippet below (Shout-out to Cyril Poupin on this one!)

import sys
import os

localapp = os.getenv(r'LOCALAPPDATA')

sys.path.append(os.path.join(localapp, r'python-3.8.3-embed-amd64\Lib\site-packages'))
import numpy as np

If all this fails, you can refer to Cyril Poupin's more lengthy process in this Forum post

Releases

Roadmap

How To

Dynamo Internals

Contributing

Python3 Upgrade Work

Libraries

FAQs

API and Dynamo Nodes

Clone this wiki locally