pyrevitlabs / pyRevit

Rapid Application Development (RAD) Environment for Autodesk Revit®
http://wiki.pyrevitlabs.io
GNU General Public License v3.0
1.29k stars 331 forks source link

[Bug]: Cpython can not use print() function #2193

Open AnakinSamB opened 6 months ago

AnakinSamB commented 6 months ago

✈ Pre-Flight checks

🐞 Describe the bug

Code snippet to reproduce: grafik I have no problems using iron python but i would like to use some Cpython features. Thanks in advance

⌨ Error/Debug Message

CPython Traceback:
AttributeError : 'ScriptIO' object has no attribute 'write'
 File "T:\CAD\Revit-Entwicklung\08_APPs\Entwicklung_Extensions\Revit-Entwicklung.extension\Entwicklung.tab\Sam.panel\Feedback.pushbutton\script.py", line 7, in <module>
print(sys.path)

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

♻️ To Reproduce

No response

⏲️ Expected behavior

No response

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

==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.8.12.22247+0031" | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "Autodesk Revit 2024" | Engine: IPY277 (277) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2022.1.2" | Engine: IPY277 (277) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2020.2.5" | Engine: IPY277 (277) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2019.2.2 Hotfix" | Engine: IPY277 (277) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2018 First Customer Ship" | Engine: IPY277 (277) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2017 First Customer Ship" | Engine: IPY277 (277) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
==> Installed Extensions
RdZ | Type: Unknown | Repo: "" | Installed: "Z:\Stammdaten\02 - Revit\07_APP\Projekte\RdZ\RdZ.extension"
Revit-Entwicklung | Type: Unknown | Repo: "" | Installed: "T:\CAD\Revit-Entwicklung\08_APPs\Entwicklung_Extensions\Revit-Entwicklung.extension"
ZWP_App | Type: Unknown | Repo: "" | Installed: "T:\CAD\Revit-Entwicklung\08_APPs\ZWP_APP\ZWP_App.extension"
==> Default Extension Search Path
C:\Users\s.benkendorf\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
T:\CAD\Revit-Entwicklung\08_APPs\Entwicklung_Extensions
Z:\Stammdaten\02 - Revit\07_APP\Projekte\RdZ
T:\CAD\Revit-Entwicklung\08_APPs\ZWP_APP
==> Extension Sources - Default
https://github.com/eirannejad/pyRevit/raw/master/extensions/extensions.json
==> Extension Sources - Additional
==> Installed Revits
Autodesk Revit 2024 | Version: 24.2.0.63 | Build: 20231029_1515(x64) | Language: 1033 | Path: "C:\Programme\Autodesk\Revit 2024\"
2022.1.2 | Version: 22.1.21.13 | Build: 20220123_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
2020.2.5 | Version: 20.2.50.77 | Build: 20210804_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
2019.2.2 Hotfix | Version: 19.2.20.24 | Build: 20190808_0900(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2019\"
2018 First Customer Ship | Version: 18.0.0.420 | Build: 20170223_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2018\"
2017 First Customer Ship | Version: 17.0.416.0 | Build: 20160225_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2017\"
==> Running Revit Instances
PID: 8216 | 2021.1.6 | Version: 21.1.60.25 | Build: 20220123_1515(x64) | Language: 0 | Path: ""
==> User Environment
Microsoft Windows 10 [Version 10.0.19045]
Latest Installed .Net Framework: 4.8
No .Net Target Packs are installed.
Installed .Net-Core Target Packs: v7.0.117 v7.0.314 v7.0.407
pyRevit CLI v4.8.12.22247+0031

Additional context

No response

sanzoghenzo commented 6 months ago

Hi @AnakinSamB , I see that you have a quite old version of pyrevit, can you please upgrade it and check if the issue persist? I've fixed some (but not all) of the problems of cpython in version 4.8 15. Hopefully we'll have a working cpython environment for pyRevit 5 release!

AnakinSamB commented 6 months ago

Hi @sanzoghenzo, thanks for the quick reply, unfortunately that did not solve the problem :/. If there is no quick solution i can also wait for the latest version to be released and if that does not fix the error, i will report back here.

sanzoghenzo commented 6 months ago

Is the error the same? Also, do you confirm that the sample code you posted raises the same error? I ask because the error messages says that the error is at line 7, but the sample code has 4 lines... could it be that you're importing something else before printing?

AnakinSamB commented 6 months ago

I tried something else before posting the bug but it did not resolve the issue, thats why the error message says line 7... sorry for the confusion -> the sample code creates the same error grafik

sanzoghenzo commented 6 months ago

Do you have any lib folder in that extension, or other loaded extensions?

Can you please try to unload all your extension, enable the pyRevitDevTools (from the Extensions manager) and then run the "Engine Tests" -> "Test CPython Command" or "Test CPython Search paths"?

AnakinSamB commented 5 months ago

Good Afternoon,

the error code when i start Text Cpython Command:

grafik grafik

when i start Text Cpython Search paths: grafik

AnakinSamB commented 5 months ago

i forgot to mention that i could not find any lib folder either in the current custom extension or any other custom extension

sanzoghenzo commented 5 months ago

I honestly don't know what's going on...

Not sure if it's related, but one thing I see from the pyrevit env output you posted is that under the "running Revit instances" you have the following:

PID: 8216 | 2021.1.6 | Version: 21.1.60.25 | Build: 20220123_1515(x64) | Language: 0 | Path: ""

But that version is not listed in the "Installed Revits". Does it say the same thing also with the new pyrevit version?

@jmcouffin have you seen something like this before?

AnakinSamB commented 5 months ago

grafik grafik

yes it does, i could try to change it, but i would need help

jmcouffin commented 5 months ago

grafik grafik

yes it does, i could try to change it, but i would need help

please copy paste the whole pyrevit env report, not just bits and pieces

@jmcouffin have you seen something like this before?

yes, but my install of python 3.8 is a bit of a mess, so this is not entirely relevant.

sanzoghenzo commented 5 months ago

@jmcouffin have you seen something like this before?

yes, but my install of python 3.8 is a bit of a mess, so this is not entirely relevant.

I was referring to the fact that the running revit instance states version "2021.1.6", which is not in the "Installed Revits"...

It may be totally unrelated to the issue, though...

jmcouffin commented 5 months ago

I was referring to the fact that the running revit instance states version "2021.1.6", which is not in the "Installed Revits"...

to my knowledge it is unrelated.

AnakinSamB commented 5 months ago
==> Registered Clones (full git repos)
==> Registered Clones (deployed from archive/image)
master | Deploy: "basepublic" | Branch: "master" | Version: "4.8.15.24089+0912" | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
==> Attachments
master | Product: "24.2" | Engine: DEFAULT (2711) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2022.1.2" | Engine: DEFAULT (2711) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2020.2.5" | Engine: DEFAULT (2711) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2019.2.2 Hotfix" | Engine: DEFAULT (2711) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2018 First Customer Ship" | Engine: DEFAULT (2711) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
master | Product: "2017 First Customer Ship" | Engine: DEFAULT (2711) | Path: "C:\Users\s.benkendorf\AppData\Roaming\pyRevit-Master"
==> Installed Extensions
Revit-Entwicklung | Type: Unknown | Repo: "" | Installed: "T:\CAD\Revit-Entwicklung\08_APPs\Entwicklung_Extensions\Revit-Entwicklung.extension"
==> Default Extension Search Path
C:\Users\s.benkendorf\AppData\Roaming\pyRevit\Extensions
==> Extension Search Paths
T:\CAD\Revit-Entwicklung\08_APPs\Entwicklung_Extensions
==> Extension Sources - Default
https://github.com/eirannejad/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:\Programme\Autodesk\Revit 2024\"
2022.1.2 | Version: 22.1.21.13 | Build: 20220123_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2022\"
2020.2.5 | Version: 20.2.50.77 | Build: 20210804_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2020\"
2019.2.2 Hotfix | Version: 19.2.20.24 | Build: 20190808_0900(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2019\"
2018 First Customer Ship | Version: 18.0.0.420 | Build: 20170223_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2018\"
2017 First Customer Ship | Version: 17.0.416.0 | Build: 20160225_1515(x64) | Language: 1033 | Path: "C:\Program Files\Autodesk\Revit 2017\"
==> Running Revit Instances
PID: 14384 | 2021.1.6 | Version: 21.1.60.25 | Build: 20220123_1515(x64) | Language: 0 | Path: ""
==> User Environment
Microsoft Windows 10 [Version 10.0.19045]
Executing User: ZWP-NETZ\s.benkendorf
Active User: ZWP-NETZ\s.benkendorf
Admin Access: No
%APPDATA%: "C:\Users\s.benkendorf\AppData\Roaming"
Latest Installed .Net Framework: 4.8
No .Net Target Packs are installed.
Installed .Net-Core Target Packs: v7.0.118 v7.0.315 v7.0.408
pyRevit CLI v4.8.15.24089+0912.f079f5fd51756b988a06d005d4f4cd2961f36e63
sanzoghenzo commented 1 month ago

HI @AnakinSamB, could you please try the latest WIP installer? We have updated the pythonnet library along with the support to Revit 2025.

Hopefully the problem went away :crossed_fingers:

AnakinSamB commented 3 days ago

Hi @sanzoghenzo, i installed the newest Pyrevit Version 4.8.16.24121+2117 and CPython returns now a new error when i try to import from Autodesk.Revit.DB

CPython Traceback: SystemError : returned a result with an error set File "T:\CAD\Revit-Entwicklung\08_APPs\Entwicklung_Extensions\Revit-Entwicklung.extension\Entwicklung.tab\Sam.panel\Feedback.pushbutton\script.py", line 29, in from Autodesk.Revit.UI import *

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

sanzoghenzo commented 2 days ago

Hi @AnakinSamB, the version to test is the WIP installer found in the pyrevitlabs.io main page, here's the direct link

sanzoghenzo commented 2 days ago

I just tested on my local copy (that is in line with #2384) and from Autodesk.Revit.UI import * works without any issue

@jmcouffin I believe CPython is more or less fixed, the big thing that is still missing is to make pyrevit.forms (= WPF) work with it