How to install Python modules in Dynamo Core Runtime 2.8.0?

Uploading: Photo-1.png…
the system cannot find the specified path -Error

1 Like

Максим у меня на канале есть ролик на эту тему https://youtu.be/iw-rQeazlYc?si=6UTtvZO5xOTtuHbr

Translation: Maxim, I have a video on this topic on my channel https://youtu.be/iw-rQeazlYc?si=6UTtvZO5xOTtuHbr

Можно еще проще решить эту задачу, не устанавливая Анаконду, а с помощью файла get-pip.py (https://bootstrap.pypa.io/get-pip.py) установить pip. Для этого нужно запустить этот файл в том Питоне, который сидит в Динамо. Интернет должен быть включён.

Translation: You can solve this problem even easier by not installing Anaconda, but using the get-pip.py file (https://bootstrap.pypa.io/get-pip.py) to install pip. To do this, you need to run this file in the Python that is in Dynamo. The Internet must be turned on.

@maksim7747 and @Khasan_Mamaev I’ve translated your posts with Google Translate so that others in this thread can also get benefit :slight_smile: Moving forward as this Forum is in English could you please do the same? Totally cool to have both Russian and English.

2 Likes

:ok_hand:

Good afternoon!
Thank you Hassan! It turned out to be installed only with the help of Anaconda.

1 Like


Good afternoon, Hassan!
Python Openpyxl module has been installed successfully. The Python Numpy module is installed with an error. Screenshots are attached

Sorry, Khasan!

Bit of a stab in the dark - try this at the top of your code

import os
os.environ["CONDA_DLL_SEARCH_MODIFICATION_ENABLE"] = "1"

EDIT Unlikely though - your Conda installation should match the Dynamo version Python 3.9
Numpy docs note that it should work [link]

Thanks! It didn’t help. The module NumPy won’t start

Hi all,

I’m trying to install some python packages through the solution as provided by @c.poupin .
It has succesfully downloaded some of the packages I want but it errors at trimesh and open3d and I don’t know how to fix that.

image
This is the error message in the console (translated to “The System can’t find the provived file”)

I’m using Dynamo Sandbox 2.19.3.6394, Python 3.9.12

Check python39._pth file in you python root folder and uncomment import site (usually line 5)

Hi @Mike.Buttery ,

That didn’t seem to work unfortunately.
Could you share your .dyn-file?

Here is the python

import subprocess
import sys
import sysconfig
from pathlib import Path  # python3 library


def haspip():
    """Check for installation of pip"""
    return pipexe.exists()


def getpip(force=False):
    """Install pip from the internets"""
    if haspip() and not force:
        return f"Pip already installed at {str(pipexe)}"
    # Fingers crossed the enterprise firewall lets this through
    comm = ["curl", "https://bootstrap.pypa.io/get-pip.py", "|", pyexe, "-"]

    return subprocess.run(comm, capture_output=True, shell=True)


def install(package, upgrade=False):
    comm = [pyexe, "-m", "pip", "install"]
    if upgrade:
        comm.append("-U")
    if isinstance(package, str):
        comm += package.split()
    elif isinstance(package, list):
        comm += package
    else:
        raise TypeError("Input is not string or list of python modules")

    return subprocess.run(comm, capture_output=True, shell=True)


def checkinstall(packages):
    installed = []
    if isinstance(packages, str):
        packages = packages.split()

    for p in packages:
        try:
            exec("import {}".format(p))
            installed.append("{} installed".format(p))
        except ImportError:
            installed.append("{} is not installed".format(p))

    return installed


# Get file / exe locations for running Python install
pypath = Path(sysconfig.get_path("data"))  # root path to python install
pyexe = pypath.joinpath("python.exe")
pipexe = pypath.joinpath("Scripts/pip.exe")

# site-package library paths
sys.path.append(sysconfig.get_path("platlib"))

# pip path
if haspip():
    sys.path.append(str(pipexe.parent))
    pipresult = f"Using pip at {str(pipexe)}"
else:
    pipresult = getpip()

result = install(IN[0], IN[1])

OUT = (
    pipresult,
    checkinstall(IN[0]),
    f"stdout:\n{result.stdout.decode('utf-8')}",
    f"stderr:\n{result.stderr.decode('utf-8')}",
)
2 Likes