pyRevit icon indicating copy to clipboard operation
pyRevit copied to clipboard

[Bug]: Dynamo cannot execute python node if pyRevit is installed

Open GiuseppeDotto opened this issue 1 year ago • 46 comments

✈ Pre-Flight checks

  • [X] I don't have SentinelOne antivirus installed (see above for the solution)
  • [X] I have searched in the issues (open and closed) but couldn't find a similar issue
  • [X] I have searched in the pyRevit Forum for similar issues
  • [X] I already followed the installation troubleshooting guide thoroughly
  • [X] I am using the latest pyRevit Version

🐞 Describe the bug

All the computer of the office where I work have issue with executing python dynamo nodes since pyRevit is installed on their computer.

error messages

These are the errors that popup from their Dynamo: image (this pops up as soon as the python node is called)

image (this pops up is the user does some operation, for example, change the engine to IronPython2 and then revert to CPython)

further info

  • The issue only occurs if the engine used by Dynamo is CPython. With IronPython 2 everything works just fine.
  • the script inside of the screenshotted python node is OUT=IN

researches

I read a similar issue unfortunately closed without answers: Errors in Dynamo Python Script.

⌨ Error/Debug Message

attempt to read or write protected memory.

♻️ To Reproduce

just open Dynamo and create python node

⏲️ Expected behavior

CPython in Dynamo should work properly

🖥️ Hardware and Software Setup (please complete the following information)

Windows 11

$pyrevit env

==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
pyOMA | Deploy: "core" | Branch: "master" | Version: "4.8.16" | Path: "C:\Users\gdotto\AppData\Roaming\pyOMA"
==> Attachments
pyOMA | Product: "24.2" | Engine: DEFAULT (2711) | Path: "C:\Users\gdotto\AppData\Roaming\pyOMA"
pyOMA | Product: "23.1.3" | Engine: DEFAULT (2711) | Path: "C:\Users\gdotto\AppData\Roaming\pyOMA"
pyOMA | Product: "Autodesk Revit 2021" | Engine: DEFAULT (2711) | Path: "C:\Users\gdotto\AppData\Roaming\pyOMA"
==> Installed Extensions
DDeT | Type: Unknown | Repo: "" | Installed: "\\office-server\DDeT.extension"
pyOMA | Type: Unknown | Repo: "" | Installed: "\\office-server\pyOMA.extension"
pyRevitCore | Type: UIExtension | Repo: "" | Installed: "\\office-server\pyRevitCore.extension"
pyRevitTools | Type: UIExtension | Repo: "" | Installed: "\\office-server\pyRevitTools.extension"
==> Default Extension Search Path
C:\Users\gdotto\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
C:\Users\gdotto\OneDrive - Office for Metropolitan Architecture\Documents\GitHub\myPrivate
\\office-server
==> Extension Sources - Default
https://github.com/pyrevitlabs/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
24.2 | Version: 24.2.0.63 | Build: 20231029_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2024\"
23.1.3 | Version: 23.1.30.97 | Build: 20230828_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2023\"
Autodesk Revit 2021 | Version: 21.1.21.45 | Build: 20201116_1100(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2021\"
==> Running Revit Instances
PID: 3860 | 24.2 | Version: 24.2.0.63 | Build: 20231029_1515(x64) | Language: 0 | Path: "C:\Program Files\Autodesk\Revit 2024"
==> User Environment
Microsoft Windows 10 [Version 10.0.22631]
Executing User: OMA\gdotto
Active User:
Admin Access: No
%APPDATA%: "C:\Users\gdotto\AppData\Roaming"
Latest Installed .Net Framework: 4.8
No .Net Target Packs are installed.
No .Ne-Core Target Packs are installed.
pyRevit CLI v4.8.16.24121+2117.23a0b8cbc4babdeb29a0611e159d017bbe9cbad5

Additional context

No response

GiuseppeDotto avatar Sep 11 '24 15:09 GiuseppeDotto

Version of revit used? Version of Dynamo?

Just saying here, The issue can be on both sides Dynamo or pyRevit DynamoTeam is actually a team, so maybe asking on their forum or GH might make more sense.

jmcouffin avatar Sep 11 '24 15:09 jmcouffin

I personaly never had this type of issue

jmcouffin avatar Sep 11 '24 15:09 jmcouffin

Revit: 2024.2.0 Dynamo: v.2.19.3

We already opened a ticket with Autodesk that didn't get solved. Particularly hard case because I can't replicate it anywhere else except for the office computers.

I will definitely open again a blog post on Dynamo forum, here is the previous one. In the meantime, any hint from your side is very welcome.

GiuseppeDotto avatar Sep 11 '24 16:09 GiuseppeDotto

Just tried it on my machine, not reproductible. Revit 2024, latest everything.

https://github.com/user-attachments/assets/a1314ff7-22ea-40d7-adc3-3ed08b714fe4

wild guess, any other python installed on computers. dynamo has its own python engines, pyrevit too. Maybe you have vanilla python installs for other purposes and they do not behave nicely?

jmcouffin avatar Sep 11 '24 16:09 jmcouffin

Thanks a lot for the reply. on my computer there is a vanilla python installed, however I would exclude this is the cause because other users without python installed have the same issue. Additionally, this issue started upon pyRevit installation.

As you saw, the post on the dynamo forum is quite old. I will take care to run another test uninstalling pyRevit and I will let you know if the issue really depends on pyRevit installation.

GiuseppeDotto avatar Sep 11 '24 16:09 GiuseppeDotto

I'm having the same issue. CPython nodes work when deactivating pyRevit, but not when pyRevit is active.

thomvill avatar Sep 12 '24 12:09 thomvill

on my computer there is a vanilla python installed, however I would exclude this is the cause because other users without python installed have the same issue. Additionally, this issue started upon pyRevit installation.

maybe they have rhino GH + rhino inside revit?

jmcouffin avatar Sep 12 '24 12:09 jmcouffin

I confirm the behavior, python on Dynamo works if pyRevit is not installed. The computers with the issue don't have rhino inside revit.

GiuseppeDotto avatar Sep 12 '24 13:09 GiuseppeDotto

I confirm the behavior, python on Dynamo works if pyRevit is not installed. The computers with the issue don't have rhino inside revit.

Can you precisely provide the steps you performed? @GiuseppeDotto

I need to be able to reproduce.

jmcouffin avatar Sep 12 '24 13:09 jmcouffin

correct, sorry @jmcouffin for lacking information. The test was performed in 2 different scenario:

scenario 1

  1. starting from a computer without pyRevit installed
  2. Dynamo check => python works ✅
  3. install pyRevit using CLI
  4. Dynamo check => python doesn't work ❌

scenario 2

  1. starting from a computer with pyRevit already installed
  2. Dynamo check => python doesn't work ❌
  3. uninstall pyRevit and delete all the clones
  4. Dynamo check => python works ✅
  5. install pyRevit using CLI
  6. Dynamo check => python doesn't work ❌

how do we install pyRevit

the way we deploy pyRevit to all the office computer is simple as:

  1. install the latest pyRevit CLI with Admin rights
  2. run a BAT script to clone pyRevit core, attach to all the Revit versions and add our custom paths. See below for reference

pyrevit clone ourCloneName core --dest=%appdata%\ourCloneName pyrevit attach ourCloneName 2711 --installed pyrevit extensions paths add "\our\path\to\the\folder\with\extensions"

GiuseppeDotto avatar Sep 13 '24 06:09 GiuseppeDotto

I'll add that in my case it's enough to disable the pyRevit addin-file and restart Revit for the CPython nodes to start working, and vice versa. No need to uninstall/reinstall for new behavior to appear.

thomvill avatar Sep 13 '24 07:09 thomvill

and Revit 2024 Dynamo 2.19.3 right? other versions too?

jmcouffin avatar Sep 13 '24 07:09 jmcouffin

Yes, is still Revit 2024.2 and Dynamo 2.18.3. I just tried with Revit 2023.1 and Dynamo 2.16.2 and the issue is still occurring. The doesn't take place with Revit 2021, where the python engine was still IronPython.

GiuseppeDotto avatar Sep 13 '24 16:09 GiuseppeDotto

Has anyone found a workaround this? im having same problems but doesn't matter if i use Cpython or IronPython. And everything work as soon as i turn of pyrevit for the current revit version and restart revit with it turned of.

At first I thought it was do to a windows update my company rolled out as everything stopped working last week around that time. Might still be a combination? Could there have been something in the windows update that is giving me problems with python in dynamo and pyrevit?

Oliver2201 avatar Sep 25 '24 07:09 Oliver2201

Has anyone found a workaround this? im having same problems but doesn't matter if i use Cpython or IronPython. And everything work as soon as i turn of pyrevit for the current revit version and restart revit with it turned of.

At first I thought it was do to a windows update my company rolled out as everything stopped working last week around that time. Might still be a combination? Could there have been something in the windows update that is giving me problems with python in dynamo and pyrevit?

I do think this is a different matter.

The thing is, I cannot reproduce on my computer. I did play with dynamo up and down in revit 2024 with the latest WIP installers and no issu switching from cpython to ironpython back and forth.

jmcouffin avatar Sep 25 '24 08:09 jmcouffin

I actually had the same thought than @Oliver2201 , just our updates happened 1 year ago, and since then I tried to replicate the issue, without success, on many other computers out of my organization. @jmcouffin , if you know about any possible method to display a more informative error message, I am very happy to test it out.

GiuseppeDotto avatar Sep 25 '24 08:09 GiuseppeDotto

Apart from the revit journal and dynamo logs, no idea. Maybe asking to the dynamo team? The error happens in dynamo after all

jmcouffin avatar Sep 25 '24 08:09 jmcouffin

Hello, I am having the same issue, on multiple computers. Currently I solved it in revit 2024 by using IronPython 2.7, but in Revit 2025 it does not work anymore and I have to use CPython3. Nevertheless all the nodes that uses CPython3 does not work (same error as shown in this post) when Pyrevit is installed. If I uninstall Pyrevit, everything works fine. Has anyone solve this issue? My Revit 2025 is up-to-date and I am using the latest PyRevit WIP install file. Thanks.

lmizerova avatar Jan 15 '25 04:01 lmizerova

Hi @lmizerova , unfortunately this a bug that is hard, if not impossible, to solve because of how .net works.

A simple workaround that I can suggest: instead of uninstalling pyrevit every time, you can use the cli to disable and re-enable it via pyrevit detach --all and pyrevit attach master default --installed as explained in the wiki

sanzoghenzo avatar Jan 15 '25 06:01 sanzoghenzo

I just tried all the scenarios using the latest Release. In Revit 2025, after installing packages for IPY 27 an 3 In Revit 2024 too everything works fine.

jmcouffin avatar Feb 05 '25 10:02 jmcouffin

On my office computer, the issue persists even with the new version. Are we able to determine why this is happening? Perhaps some required system settings need adjustment?

GiuseppeDotto avatar Feb 14 '25 18:02 GiuseppeDotto

Perhaps some required system settings need adjustment?

My computer is 3 months old, win11 pro, All up to date and fresh installs of Revit, I opened dynamo just to test this specific issue.

Maybe send me a script that does not go through Mine were simply printing stuffs with the right python engine

jmcouffin avatar Feb 14 '25 18:02 jmcouffin

I don't even get to write the script, is the dynamo python node itself that return the error. Even if the script was OUT = 0, the node would fail to execute and display the same error.

My guess is that we are dealing with a Windows configuration of some file(s) set as not editable after the installation of Revit or pyRevit, together with an overlap of python venv path between Dynamo and pyRevit. To add more information, in my company we are installing programs using the "Company Portal" from Microsoft. For pyRevit specifically, we install the CLI using the MSI file and we configure so to create for each user a local clone in %appdata%, with a config.ini file pointing at the extensions shared on the local server.

GiuseppeDotto avatar Feb 17 '25 09:02 GiuseppeDotto

My guess is that we are dealing with a Windows configuration of some file(s) set as not editable after the installation of Revit or pyRevit, together with an overlap of python venv path between Dynamo and pyRevit. To add more information, in my company we are installing programs using the "Company Portal" from Microsoft. For pyRevit specifically, we install the CLI using the MSI file and we configure so to create for each user a local clone in %appdata%, with a config.ini file pointing at the extensions shared on the local server.

No idea and no way to test things in the same environment.

jmcouffin avatar Feb 17 '25 09:02 jmcouffin

@devloai can you help understand and fix this issue?

jmcouffin avatar Feb 17 '25 09:02 jmcouffin

@GiuseppeDotto 👆 when nothing else...

jmcouffin avatar Feb 17 '25 09:02 jmcouffin

Thanks for the detailed report. After analyzing the issue, I believe I understand what's happening:

The conflict occurs because both pyRevit and Dynamo are trying to manage CPython environments, leading to memory access conflicts. This explains why:

  1. The issue only affects CPython nodes but not IronPython
  2. The issue appears right after pyRevit installation
  3. Disabling pyRevit resolves the problem

Here's the proposed fix plan:

  1. Modify pyRevit's Python engine initialization to:

    • Isolate pyRevit's CPython environment from global Python settings
    • Add environment variable checks to detect Dynamo's presence
    • Implement proper cleanup of Python environment when switching between pyRevit and Dynamo contexts
  2. Add a new configuration option in pyRevit to:

    • Allow users to explicitly disable CPython engine when working with Dynamo
    • Provide a way to temporarily suspend pyRevit's Python environment management
  3. Improve error handling to:

    • Detect potential conflicts with other Python environments
    • Provide more informative error messages
    • Add documentation about Dynamo compatibility

Would you like me to proceed with implementing this fix? Please reply with "@devloai" to confirm.

devloai[bot] avatar Feb 17 '25 09:02 devloai[bot]

@devloai

jmcouffin avatar Feb 17 '25 09:02 jmcouffin

Would you like me to proceed with implementing this fix? Please reply with "@devloai" to confirm.

let's give it a try

jmcouffin avatar Feb 17 '25 09:02 jmcouffin

Working on implementing Python environment isolation between pyRevit and Dynamo to resolve the CPython node execution conflicts.

Status: Done.

devloai[bot] avatar Feb 17 '25 09:02 devloai[bot]