Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpython engine CPY385 - Matplotlib import #1684

Closed
CSantos2022 opened this issue Dec 16, 2022 · 3 comments
Closed

Cpython engine CPY385 - Matplotlib import #1684

CSantos2022 opened this issue Dec 16, 2022 · 3 comments
Labels
Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to Python 3 Issues related to cpython engines [subsystem]

Comments

@CSantos2022
Copy link

CSantos2022 commented Dec 16, 2022

Describe the bug
I have installed pyRevit but I am getting a small bug when Revit starts and pyRevit loads. I am not sure if it can be related, so I will present that bug.

Startup script execution test.
C:\Users\carlo\AppData\Roaming\pyRevit-Master\extensions\pyRevitDevTools.extension\lib
C:\Users\carlo\AppData\Roaming\pyRevit-Master\extensions\pyRevitDevTools.extension
C:\Users\carlo\AppData\Roaming\pyRevit-Master\pyrevitlib
C:\Users\carlo\AppData\Roaming\pyRevit-Master\site-packages
C:\Users\carlo\AppData\Roaming\pyRevit-Master\bin
C:\Users\carlo\AppData\Roaming\pyRevit-Master\pyrevitlib\pyrevit\loader\addin
C:\Users\carlo\AppData\Roaming\pyRevit-Master\bin\engines\277
C:\Users\carlo\AppData\Roaming\pyRevit-Master\bin\engines\IPY277
C:\Users\carlo\AppData\Roaming\pyRevit
C:\Users\carlo\AppData\Roaming\pyRevit\2022
C:\Users\carlo\AppData\Roaming\pyRevit\Extensions 
C:\Users\carlo\AppData\Roaming\pyRevit-Master\bin 
C:\Users\carlo\AppData\Roaming\pyRevit-Master\bin
C:\Users\carlo\AppData\Roaming\pyRevit-Master\bin
lib/ import works in startup.py
ERROR [pyrevit.routes.server.router] Route pattern is invalid: /posts/<int:uiapp>

The first issue importing matplolib import is related to the site-package pyparsing.
ImportError : Matplotlib requires pyparsing>=2.2.1; you have 2.2.0
But actually, when I install Matplotlib, it also installs the latest site-package pyparsing3.0.9. However, pyRevit has the site-package pyparsing2.2.0 installed by default, and that one is automatically considered even if pyparsing3.0.9 is available on the site-package folder of python.
Let's see how it works:

#! python3
import sys
print(sys.version)
import pyparsing
print(pyparsing.__version__)

CPython Traceback:

3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]
2.2.0

Now, manually removing the site-package pyparsing from the pyRevit-master directory, and extending the code a bit more to include more libraries (numpy, pandas, scipy):

#! python3
import sys
print(sys.version)
import pyparsing
print(pyparsing.__version__)
import numpy
print(numpy.__version__)
print(numpy.__file__)
import pandas as pd
print(pd.__version__)
print(pd.__file__)
import scipy
print(scipy.__version__)
print(scipy.__file__)

Now, we can see that the pyparsing version is 3.0.9 because cpython engine does not find the package installed by default on the site-package folder from pyRevit. In addition I can see that packages are being loaded from the right place (previously defined as PYTHONPATH environment variable).

3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)]
3.0.9
1.23.4
C:\Users\carlo\pyproj\bimenv\Lib\site-packages\numpy\__init__.py
1.5.1
C:\Users\carlo\pyproj\bimenv\Lib\site-packages\pandas\__init__.py
1.9.3
C:\Users\carlo\pyproj\bimenv\Lib\site-packages\scipy\__init__.py

The problems come when I try to import matplotlib.

#! python3
import matplotlib
print(matplotlib.__version__)

CPython Traceback:
TypeError : expected str, bytes or os.PathLike object, not WindowsPath
File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 886, in <module>
 rcParamsDefault = _rc_params_in_file(
 File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 789, in _rc_params_in_file
 with _open_file_or_url(fname) as fd:
 File "contextlib.py", line 113, in __enter__
 File "C:\Users\carlo\pyproj\bimenv\Lib\site-packages\matplotlib\__init__.py", line 765, in _open_file_or_url
 fname = os.path.expanduser(fname)
 File "ntpath.py", line 293, in expanduser

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

I have looked for help, and I've found a similar issue in matplotlib GitHub
However, in my case, I don't think that the root cause sits in something else in the system because I've tried import matplotlib from the Python shell 3.8.5, which works well in that case.
image

Desktop (please complete the following information):

  • pyRevit Environment:
==> User Environment
Microsoft Windows 10 [Version 10.0.19045]
Admin Access: No
%APPDATA%: "C:\Users\carlo\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.10.22040+1743
@CSantos2022 CSantos2022 changed the title Cpython engine CPY385 - Matplotlib and seaborn import Cpython engine CPY385 - Matplotlib import Dec 16, 2022
@eirannejad
Copy link
Collaborator

You can remove the pyrevit-shipped site-packages path from sys.path at the top of your script and add your own so it only sees the packages you want

@eirannejad eirannejad added the Python 3 Issues related to cpython engines [subsystem] label Jan 2, 2023
@CSantos2022
Copy link
Author

Thank you for your reply. Indeed, I solved the first issue as you suggested, but my second issue remains, which comes out when I try to import matplotlib.

"
#! python3
import matplotlib
print(matplotlib.version)
"

@CSantos2022
Copy link
Author

Hello @eirannejad :)
I would like to know if you have any suggestions to face this issue.
This issue for me is a bit weird because I am using the same CPython engine (embedded on Revit by PyRevit and external on Windows), and I am being able to run "import matplotlib" outside but not inside Revit.

Thanks in advance for your time :)

@jmcouffin jmcouffin added the Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to label Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closed Old Issue Issue older than a year. Thanks for pointing it out. If you feel it is still relevant, feel free to Python 3 Issues related to cpython engines [subsystem]
Projects
None yet
Development

No branches or pull requests

3 participants