How to install Python modules in Dynamo Core Runtime 2.8.0?

How to install Python modules in Dynamo Core Runtime 2.8.0 ?

Just need to import them as you would all the way back in Dynamo 2.0 (and likely before that too).

ie: import clr, which imports the common language runtime into Dynamo’s Python integration. This presentation has a good breakdown: dynamoPython/DivingDeeper_ABeginnersLookAtPythonInDynamo_AU_London2018.pdf at master · Amoursol/dynamoPython · GitHub

Another slightly more complex example from this thread:

import sys
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import ctypes

which adds the ctypes library to the associated Python node.

No IronPython) Dynamo Core Runtime 2.8.0 have a normaly Python 3.8

Hello @Khasan_Mamaev - the Daily Builds as of today have access to different Python Engines as follows, but still use IronPython2 as the default - which has historically been in Dynamo :slight_smile:

Or;

image

image

We have a task to explore how we want to support this and will be writing a blog post afterwards, but as of right now we do not have an officially supported way :slight_smile:

3 Likes

Downloading locally in advance and importing the package via the by directory should work for the time being, right?

2 Likes

Hello @Khasan_Mamaev, while we are still working on an Officially supported way, here is how you can access these libraries today in Dynamo 2.7/2.8 as a workaround:

Note: Please make sure you are comfortable doing the following steps and make sure you read all of the Terms and Conditions :pray:

Steps:

  1. Download Anaconda - https://www.anaconda.com/products/individual
  2. After install, select the CMD.exe Prompt from the Home tab in the Anaconda Navigator (Install if you need to).
  3. This will open up the Command prompt in your (base) directory as Anaconda creates localized environments.
  4. Open up Dynamo 2.7 (or newer) and query the CPython version - as shown below (Note: Make sure you are in the CPython3 engine)
import sys

OUT = sys.version


5. Go back to the Anaconda Command Prompt and create a new environment that uses the correct version of Python - In my case version 3.7.3. I’ve called this environment Dynamo373 and you use the following code to create it:

 conda create --name Dynamo373 python=3.7.3
  1. You then want to activate this environment, and do so by typing the following code directly into your Anaconda Command Prompt:
 conda activate Dynamo373 
  1. You can then use Pip to install to this particular environment with:
 pip install numpy 

Note you can install other packages here, like Pandas or Keras etc.


8. Inside this Anacondas Command Prompt you will select the location path where they are being installed to your environment: In my case c:\users\amours\anaconda3\envs\dynamo373\lib\site-packages
9. Back in Dynamo you will open up a new Python node, set it’s engine to CPython3 and then append this path to your sys.path location.
10. Then you can simply import all of your desired libraries :slight_smile:

# Load the Python Standard and DesignScript Libraries
import sys
import clr

sys.path.append(r'C:\Users\amours\anaconda3\envs\Dynamo373\Lib\site-packages')
import numpy

zeros = numpy.zeros(5)
output = zeros.tolist()

OUT = output
13 Likes

This is great, but why it only works when using “pip install”, and warning errors using “conda install” ?

I’m unsure sorry @Jimmy1 - would have look into Anaconda itself :slight_smile:

Works perfect!!! Thanks!!! :slight_smile:

1 Like

Good job! Thanks ! I have done it as you showed . If there is someone who don’t need the whole Anaconda , he can install only numpy . of course , he must add the path of the numpy into sys.path instead of the path of Anaconda .

Hi @Eric5!

Indeed there is - this was a workaround until we published a new method, of which we did a day or so ago - you can access it here: https://github.com/DynamoDS/Dynamo/wiki/Customizing-Dynamo’s-Python-3-installation :slight_smile:

@solamour Hi, I followed the steps described here and successfully installed 3rd party pathon-modules. I can import them, if running python in the described directory.

Unfortunately I cannot import installed python-libraries in Dynamo (ModuleNotFoundError)
The command os.__file__ in the Python-Code-Node within Dynamo gives the following output:
“C:\Users\NCV\AppData\Local\python-3.8.3-embed-amd64\python38.zip\os.pyc”

Using DynamoCore 2.11.1.4675

What could have gone wrong?

1 Like

Hello @ncv239spb - It sounds like you may have missed a step along the way :blush:

Can you please see if you have the following on your set-up?

  1. In C:\Users\<yourUsername>\AppData\Local\python-3.8.3-embed-amd64\Scripts you can see a reference to pip

  2. In C:\Users\<yourUsername>\AppData\Local\python-3.8.3-embed-amd64\Lib\site-packages you can see all your Python 3 libraries installed - i.e. Numpy.

  3. In the python38._pth file in C:\Users\<yourUsername>\AppData\Local\python-3.8.3-embed-amd64 yours looks like mine - as below:

Hopefully there is something to amend here to unblock you!

1 Like

Hi Sol!
Looks like I’m running into a similar problem with Sandbox 2.11.1
Can’t import the libraries into the python script, though I followed the guide meticulously.
Here are some screenshots showing the up to date status of the relevant folders.

The easy_install modules are not there, for some reason, but all the libraries are installed successfully in the 3.8.3 site-packages folder. Still, the import gives me an error in Dynamo.

Would appreciate your help!
Ilia




Hello
try to add the path

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

sys.path.append(r'C:\Users\USERNAME\AppData\Local\python-3.8.3-embed-amd64\Lib\site-packages')
import numpy as np
2 Likes

Thanks! It worked.
Frankly, I think this solution should be added to the python 3 customization guide.

2 Likes

Consider it added :smiley:

2 Likes