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: https://github.com/Amoursol/dynamoPython/blob/master/images/DivingDeeper_ABeginnersLookAtPythonInDynamo_AU_London2018.pdf

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:

2 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
5 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: