Cpython not working

Hello everyone,

I’m trying to use Python 3 with pyRevit, but it’s not working. Even basic functions like print aren’t executing.

Here’s my setup and process:

  • I use #! python3 at the beginning of my code.
  • I’ve installed Python 3.8.5 to align with pyRevit’s CPython engine.
  • I’ve set the PYTHONPATH for my modules.

Below are examples of the error messages I’m receiving:
error message for basic print function:


error message when using some of the modules, its usually the same. If I am trying import any modules it says:
No module named __future__

CPython Traceback:
ModuleNotFoundError : No module named ‘future
File “C:\Users\kubar\AppData\Roaming\pyRevit\Extensions\ČVUT.extension\ČVUT.tab\Predemolition.panel\New Material.pushbutton\pip install_script.py”, line 3, in
from rapidfuzz import fuzz
File “C:\Users\kubar\AppData\Local\Programs\Python\Python38\Lib\site-packages\rapidfuzz_init_.py”, line 5, in
from future import annotations

pyRevitLabs.PythonNet
v Python.Runtime.Runtime.CheckExceptionOccurred()
v Python.Runtime.PyScope.Exec(String code, IntPtr _globals, IntPtr _locals)
v Python.Runtime.PyScope.Exec(String code, PyDict locals)
v PyRevitLabs.PyRevit.Runtime.CPythonEngine.Execute(ScriptRuntime& runtime)

here is the code I am using to test rapidfuzz module:

#! python3

from rapidfuzz import fuzz
from rapidfuzz import process

str1 = "Hello, world!"
str2 = "Hello, world!!!"

similarity = fuzz.ratio(str1, str2)
print(f"Similarity between '{str1}' and '{str2}': {similarity}%")

choices = ["Hello, world!", "Hello, there!", "Goodbye, world!"]

best_match = process.extractOne("Hello, world!!!", choices)
print(f"Best match: '{best_match[0]}' with similarity {best_match[1]}%")

all_matches = process.extract("Hello, world!!!", choices)
for match in all_matches:
print(f"Match: '{match[0]}' with similarity {match[1]}%")

Now I solved the print function. The issue was the wrong PATH for python. But if I want to run any modules it still shows the same error message.

Hi Jakub,
Try to remove all non ASCII characters in the extension/tab/panel/pushbutton names.
I’ve already had issues with cpython, but right now I have a big extension that runs on cpython without any trouble.

FYI : CPython and non-ASCII characters

1 Like

Thank you so much for the tip! It works now

Great news !
Was it the ascii characters after all ?

from my experience : when something doesn’t work with cpython scripts, you often need to restart Revit. And after modifying a cpython script you need to reload pyRevit to see new changes unlike ironpython scripts

Yes, it was the ascii characters after all:)

I changed it and reloaded Pyrevitte, but it didn’t work. So I restarted Revit, and after that, it finally started working!

Again, thanks so much!

1 Like