# How to install Python modules in Dynamo Core Runtime 2.8.0?

**URL:** <https://forum.dynamobim.com/t/how-to-install-python-modules-in-dynamo-core-runtime-2-8-0/52922>\
**Category:** Developers\
**Tags:** python, cpython3\
**Created:** [July 13, 2020, 5:43pm UTC](https://forum.dynamobim.com/t/how-to-install-python-modules-in-dynamo-core-runtime-2-8-0/52922 "2020-07-13T17:43:27Z")\
**Posts on this page:** 1\
**Showing post:** 40

<div class="post-metadata">

**Author:** ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)\
**Post date:** [March 29, 2022, 2:26pm UTC](https://forum.dynamobim.com/t/how-to-install-python-modules-in-dynamo-core-runtime-2-8-0/52922/40 "2022-03-29T14:26:45Z")

</div>

> [@e.j.nap](#):
>
> so I automated it, at least for a Windows environment. Comments welcome:

Hello and welcome !  
it’s a nice idea 👌 👍, here my version

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/f/a/faecabcea081c87de6eddef22aac48e48ea1b038.png)

![install py packages2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/5/b/5bad41aa6bf2b56725e94ed7487ac1d24a4e4e47.gif)

```auto

# More info here
# https://github-wiki-see.page/m/DynamoDS/Dynamo/wiki/Customizing-Dynamo%27s-Python-3-installation
import sys
import clr
import System
import re
pyEngineName = sys.implementation.name 
if pyEngineName != "ironpython":
    reDir = System.IO.DirectoryInfo(re. __file__ )
    path_py3_lib = reDir.Parent.Parent.FullName

    clr.AddReference("System.Windows.Forms")
    import System.Windows.Forms
    from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon

    init_setup = False

    import platform, os, subprocess, importlib.util
    from System import Environment
    from System.Net import WebClient
    #
    # get paths
    assert os.path.isdir(path_py3_lib)
    pipDirPath = os.path.join(path_py3_lib, 'Scripts')
    pipfilePath = pipDirPath + "\\pip"
    get_pip_path = os.path.join(path_py3_lib, 'get-pip.py')
    site_packagepath = os.path.join(path_py3_lib, 'Lib\site-packages')
    #
    if not os.path.isfile(get_pip_path):
        client = WebClient()
        client.DownloadFile('https://bootstrap.pypa.io/get-pip.py', get_pip_path)
    pthFilePath = os.path.join(path_py3_lib, 'python38._pth')
    assert os.path.isfile(pthFilePath)
    
    with open(pthFilePath, 'r+') as f:
        lines = f.readlines()
        if re.match(r'#import site', lines[-1]) is not None:
            lines[-1] = re.sub(r'#', '', lines[-1])
            f.writelines(lines)
    
    if not os.path.isdir(pipDirPath):
        print(f'installing pip in local Python environment: {path_py3_lib}')
        subprocess.Popen(["python", get_pip_path])
        # try to update pip
        try:
            #subprocess.run(['python', '-m', pipfilePath, 'install', '--upgrade pip'], cwd = path_py3_lib)
            subprocess.Popen(["python", '-m', pipfilePath, 'install', '--upgrade pip'], cwd = path_py3_lib)
        except Exception as ex:
            print(str(ex))
        init_setup = True
        MessageBox.Show("Initialization in Progress...\nWhen installation finished, close Dynamo and relaunch this script to install packages", "Initialization In Progress...", MessageBoxButtons.OK, MessageBoxIcon.Warning)
    else: 
        print('pip was already installed for this local Python environment')
        init_setup = False
    #
    installPackages = IN[0]
    if installPackages and not init_setup:
        sys.path.append(site_packagepath)
        for packageName in installPackages:
            spec = importlib.util.find_spec( packageName )
            if spec is None: 
                try:
                    subprocess.run([pipfilePath, 'install', '--target='+ site_packagepath, packageName], cwd = path_py3_lib)
                    print(f'{packageName} succesfully installed')
                except Exception as ex:
                    print(f'error while installing {packageName}')
                    print(str(ex))
            else:
                print(f"package {packageName} is already installed")

```

EDIT :  
🔽 UPDATED CODE HERE 🔽

> [@How to install Python modules in Dynamo Core Runtime 2.8.0?](https://forum.dynamobim.com/t/how-to-install-python-modules-in-dynamo-core-runtime-2-8-0/52922/54):
>
> hello, here an updated code [image] [image] # More info here # https://github-wiki-see.page/m/DynamoDS/Dynamo/wiki/Customizing-Dynamo%27s-Python-3-installation import sys import clr import System import re print('\n'.join(sys.path)) pyEngineName = sys.implementation.name clr.AddReference("System.Windows.Forms") import System.Windows.Forms from System.Windows.Forms import MessageBox, MessageBoxButtons, MessageBoxIcon from System.Reflection import Assembly dynamo = Assembly.Load('DynamoCor…

---

_[View the full topic](https://forum.dynamobim.com/t/how-to-install-python-modules-in-dynamo-core-runtime-2-8-0/52922)._
