-
Notifications
You must be signed in to change notification settings - Fork 635
Customizing Dynamo's Python 3 installation
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.
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.
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!
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
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 andpip
is nowhere to be found [7]. This is a known caveat but it can be solved.
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
.
In order to make pip
available please follow these steps:
- Download get-pip.py [8] and place it into Dynamo's Python home [9][10].
- 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 readsimport site
[12].
- Navigate to your Python home [13] and copy the path. Inside the
Command prompt
application navigate to your Python version folder by typing into theCommand 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] wherecd
is a call tochange directory to
your chosen path.
- 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 thePATH
, as Dynamo does not need that.
After doing that you should see the Scripts
folder, containing pip
[17].
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.
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)
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.
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
Looking for help with using the Dynamo application? Try dynamobim.org.
- Dynamo 2.0 Language Changes Explained
- How Replication and Replication Guide work: Part 1
- How Replication and Replication Guide work: Part 2
- How Replication and Replication Guide work: Part 3