# Openpyxl module

**URL:** <https://forum.dynamobim.com/t/openpyxl-module/94081>\
**Category:** Developers\
**Tags:** revit, excel, python, dynamo\
**Created:** [September 27, 2023, 10:09am UTC](https://forum.dynamobim.com/t/openpyxl-module/94081 "2023-09-27T10:09:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanhdatp297GRTHP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thanhdatp297grthp/32/167370_2.png) [@thanhdatp297GRTHP](https://forum.dynamobim.com/u/thanhdatp297GRTHP)\
**Post date:** [September 27, 2023, 10:09am UTC](https://forum.dynamobim.com/t/openpyxl-module/94081/1 "2023-09-27T10:09:45Z")

</div>

I tried to import openpyxl module through syntax

import openpyxl  
from openpyxl import load\_workbook

However python script warns that, “No module named openpyxl”  
As you see i have installed openpyxl via cmd, but it still fails  
Can someone help me?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/2/e2980db287c52d6d7b955bd5dd0c9555873c34f3.jpeg)

---

<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:** [September 27, 2023, 11:23am UTC](https://forum.dynamobim.com/t/openpyxl-module/94081/2 "2023-09-27T11:23:08Z")

</div>

Hi,  
with openpyxl lib you need to use the CPython3 engine

---

<div class="post-metadata">

**Author:** ![thanhdatp297GRTHP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thanhdatp297grthp/32/167370_2.png) [@thanhdatp297GRTHP](https://forum.dynamobim.com/u/thanhdatp297GRTHP)\
**Post date:** [September 27, 2023, 5:58pm UTC](https://forum.dynamobim.com/t/openpyxl-module/94081/3 "2023-09-27T17:58:41Z")

</div>

I did but it still fail

---

<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:** [September 27, 2023, 6:36pm UTC](https://forum.dynamobim.com/t/openpyxl-module/94081/4 "2023-09-27T18:36:46Z")

</div>

@thanhdatp297GRTHP you need to install the python modules this way

> **[Customizing Dynamo's Python 3 installation](https://github.com/DynamoDS/Dynamo/wiki/Customizing-Dynamo's-Python-3-installation)**
>
> Open Source Graphical Programming for Design. Contribute to DynamoDS/Dynamo development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [September 28, 2023, 9:21am UTC](https://forum.dynamobim.com/t/openpyxl-module/94081/5 "2023-09-28T09:21:39Z")

</div>

It looks like you have it installed on a python instance (3.11) that is not being used by Dynamo  
You can find the install location `OUT = sys.path` which will return a few paths

```python
C:\Users\<username>\AppData\Local\python-3.8.3-embed-amd64\python38.zip,
C:\Users\<username>\AppData\Local\python-3.8.3-embed-amd64,
C:\Users\<username>\AppData\Local\python-3.8.3-embed-amd64\lib\site-packages

```

`pip` is not always the easiest module to install with Dynamo  
Try this in a Python node with CPython3

```python
import subprocess
import sysconfig
from pathlib import Path # python3 library

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

def getpip():
    """Install pip from the internets"""
    if pipexe.exists():
        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)

OUT = getpip()

```

You may have to reload the Dynamo graph to get access to `pip`, you may also have to uncomment the `import site` line in the _python\<version\>.\_pth_ file (e.g. _python38.\_pth_) located in the python root folder (`pypath` above)

Then you can install from a list or string of module names with a function something like this

```python
def install(package):
    comm = [pyexe, "-m", "pip", "install"]
  
    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)
```

---

<div class="post-metadata">

**Author:** ![thanhdatp297GRTHP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thanhdatp297grthp/32/167370_2.png) [@thanhdatp297GRTHP](https://forum.dynamobim.com/u/thanhdatp297GRTHP)\
**Post date:** [September 28, 2023, 10:18am UTC](https://forum.dynamobim.com/t/openpyxl-module/94081/6 "2023-09-28T10:18:03Z")

</div>

I found the error, it seems like a conflict when I try to import both of openpyxl and AddReferenceByName(Microsoft.Office.Interop.Excel) at the same time.  
I just remove command line AddReferenceByName(Microsoft.Office.Interop.Excel) and the code worked.  
Thanks for all
