Skip to content

Customizing Dynamo's Python 3 installation

Sol Amour edited this page Aug 19, 2020 · 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 Python Home Created

Open up a new Dynamo graph, place a single Python node [1], double-click on the Python node to open up the Python editor, change the engine dropdown to CPython3 [4] and run the graph [5]. There is no need to save it.

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%, which will take you to your newly created Python home location [2]. 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 [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 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 😄 [3]
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 python38.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

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 python38._pth [11] in Dynamo's Python home, 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], which will download and install pip - a successful install will be returned [16], as will any warnings. '

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 in 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--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.

Releases

Roadmap

How To

Dynamo Internals

Contributing

Python3 Upgrade Work

Libraries

FAQs

API and Dynamo Nodes

Clone this wiki locally