Jul 6, 2024
How to add Python 3 packages to pyRevit? (pandas, numpy, openpyxl...)
Learn how to add more python3 packages to pyrevit in this lesson. It's all about installing these modules and providing the correct paths, but I will show you all the steps.
Intro
In this lesson you will learn how to install pandas, numpy, openpyxl and any other python 3 package to be used in pyRevit. The process is not complicated, but there are a few steps to follow.
Let's begin
CPython
To use python 3 packages like pandas or numpy, we need to use CPython engine in pyRevit.
It's very simple to do, but there are a few things you should know about, so please check out these 2 posts about CPython in pyRevit Dev Docs.
Create Your First CPython Command
Anatomy of CPython Scripts
💡There are a few important points mentioned:
How to run scripts in python 3 ->
#! python3
CPython scripts always read using UTF-8 encoding. No need for
# -*- coding: utf-8 -*-
List of pyRevit packages
How to solve Interface Error Message " Duplicate type name within an assembly."
CPython engine is under active development and might be unstable.
You will encounter issues with Interfaces (
TypeError : Duplicate type name within an assembly.
) You can find a solution in Anatomy of CPython Scripts
pyRevit python version
To install python 3 packages correctly, we should use the same version of python as used by pyRevit.
To do that use the following code:
![](https://framerusercontent.com/images/nmi8G0rnWnJOV4ysBm6nxORtC34.png)
👉 In my case I see python 3.8.5. So that's what I will install.
Install packages
Now we have the right python installed, and we can get more packages with pip in the cmd console.
Open the console by writing 'cmd' in the search.
![](https://framerusercontent.com/images/b9Gpt4pFrTmYEc4qHk54VgsE.png)
💡Now, before you install anything, make sure that you use the correct python version with pip.
You can type 'pip -V' and it will display what version of python is used. It's necessary in case you have more than 1 python version installed, and you need to make sure you use the right one.
You can also find all the python version on your computer by writing 'where python'
![](https://framerusercontent.com/images/xlMCTr7cCGxszWoVBF5iDZQnYW8.png)
Once you know that you have the right pip version, you can install any packages that you want.
Also, while you install packages, make a note of the path to where they are installed. You might need that.
🎦 Watch the video if you need help with the step.
Add Paths in pyRevit
Now the tricky part - we need to let pyRevit use these installed packages.
💡But keep in mind, that a single path might not be enough.
There are various dependencies between packages, so it's best to check available paths for your python interpreter
Write 'python -m site' and you will see a list of available paths.
![](https://framerusercontent.com/images/2LA76Fq60AKcGwY69QzBJ0ujQXc.png)
Once you have these paths you can write the following in your python script to ensure pyRevit can access these new packages
![](https://framerusercontent.com/images/0CMW69TbmT1kXa0M2WE7MK0.png)
💡You can also use PYTHONPATH environment variable to provide these paths. This is the variable pyRevit looks at by default. (Ignore this step if you don't know about environment variables)
Check out the tutorial for more
🎦 Watch this video if you want to see me install and configure everything and explain you how to do the same.
Remarks
⚠️Don't forget that CPython engine is under active development and might be unstable.
I've noticed that pyrevit.forms might give you an error because of that. So be prepared for the unexpected.
Join Newsletter
📩 You will be added to Revit API Newsletter
Join Us!
which is already read by 6700+ people!
![](https://framerusercontent.com/images/svHzzMLtnnRCxtCUwbgAm6CUeB8.jpg)
![](https://framerusercontent.com/images/Y44kwhY0i7q37LzXUjrlxeGUo.jpg)
![](https://framerusercontent.com/images/lqKYmh8rqwZwgY2C9MSQER6iBCI.jpg)
![](https://framerusercontent.com/images/SyGCvJ3dbHsJEyklWWBhweY.jpg)
![](https://framerusercontent.com/images/DwiaUdmQHs3FVdDH2PXwAr0Y.jpg)