architecture-building-systems / revitpythonshell

An IronPython scripting environment for Autodesk Revit and Vasari
MIT License
492 stars 112 forks source link

Error when importing modules #61

Closed gtalarico closed 6 years ago

gtalarico commented 6 years ago

I get this error when importing the ssl module Work on same ironpython version on CLI, but fails on RPS.

Does anyone have any idea what might be the cause or a workaround?

image

daren-thomas commented 6 years ago

It looks like the encoding of the file ssl.py is not specified properly (could be a BOM mark?). Where did you get the module?

CyrilWaechter commented 6 years ago

I tried some stuffs in ironpython64 console :

  1. rename C:\Program Files (x86)\IronPython 2.7\Lib\ssl.py to old_ssl.py
  2. import ssl >>> ImportError: No module named ssl
  3. ssl >>> <module 'ssl' from 'C:\Program Files (x86)\IronPython 2.7\Lib\ssl.py'>
  4. sys.path.append(r'C:\\pyRevit\pyRevit-v4\pyRevit\pylib')
  5. import ssl >>> ImportError: Cannot import name _SSLContext
  6. replace ssl.py from pyRevit lib by ssl.py from IronPython 2.7 lib
  7. import ssl >>> # no error

@eirannejad I saw that you updated IronPython standard lib to 2.7.7 (revision number : b56d731cb83c5593de1a0b6dd0a72f33644cf9be), so I don't understand why files are different.

Then I tried some other stuff in RPS :

  1. import ssl >>> SyntaxError: unexpected token '»'
  2. sys.path.Clear()
  3. sys.path >>> [] # empty
  4. import ssl >>> SyntaxError: unexpected token '»'

@daren-thomas It looks like RPS is still finding a ssl.py file somewhere even when sys.path is empty. I don't understand. (Update: actually, it does the same with in ironpython console if I pop all sys.path entries. import ssl still work)

eirannejad commented 6 years ago

Uhm this might be my bad. Originally when I updated pyRevit to 2.7.7 apparently I forgot to update the standard library. And then I did the same for RPS. We need to check to see if the standard library in RPS is the latest shipped with 2.7.7

eirannejad commented 6 years ago

@CyrilWaechter FYI, RPS attached a zipped file of the standard library to the it's executor assembly and that's why RPS is able to find the modules with no sys.path

gtalarico commented 6 years ago

My bad for not updating this ! Manully replacing the standard library with the one shipped with 2.7.7 fixed it.

eirannejad commented 6 years ago

@daren-thomas It was the encoding issue. ssl.py was saved in UTF-8 BOM. After converting it to UTF-8 in notepad++ and relinking the standard library zip file, there are no exceptions on import ssl

2018-01-13 08_58_17-ironpython console

eirannejad commented 6 years ago

Submitted PR: https://github.com/architecture-building-systems/revitpythonshell/pull/67

eirannejad commented 6 years ago

This could be closed btw

daren-thomas commented 6 years ago

@eirannejad thanks for pointing that out :-)