LearnRevitAPI

Jul 18, 2024

py3 packages in pyRevit

I've seen many of you try to use numpy, pandas or other python 3 packages, and many has reported various issues. 

So I want to help you solve this problem and show you how to do it step by step

💡You can Watch:  How to import python3 packages like Numpy, Pandas or other in pyRevit

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.

Create Your First CPython Command
Anatomy of CPython Scripts

Or here are some points to keep in mind:

🔸 CPython engine is under active development and might be unstable.
🔸To use CPython engine - write '#! python3' as the first line.
🔸CPython always uses UTF-8 encoding. No need to declare that
🔸You will get errors with Interfaces (Duplicate type name...) But you can solve it by looking at Anatomy of CPython Scripts

Install the correct python version

To install these packages correctly, we should use the same version as used by pyRevit. 

You can find the python version with this code:

In my case I can see that pyRevit uses 3.8.5 python version. 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.

💡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'

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 This 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.


Once you have these paths you can write the following in your python script to ensure pyRevit can access these new packages

💡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.

Happy Coding!

Join Learn Revit API Course

Learn Revit API step by step so it's not so overwhelming.

You will get access to 50+ lessons which contain not only 15 hours of video content, but also each lesson is written out to help you learn. 

On top of that you will get access to the LearnRevitAPI community.

Join the Course

Enjoyed Newsletter?

Leave a Testimonial Here.

⌨️ Happy Coding!
Erik Frits

Join Newsletter

📩 You will be added to Revit API Newsletter

Join Us!

which is already read by 7200+ people!

Last Chance To Claim LIFETIME ACCESS. [~40 Seats left]