Importing IronPython libraries

I also have the same problem importing other IronPython libraries, such as the urllib and urllib2 for writing web requests. I’m using Rhino 6 SR 24 on Windows.

They seem to import okay for me on Windows:

Anders.
Thanks for your reply!
In this screenshot, you see what I get:

  • I don’t get the intellisense option to import
  • I cannot check the dir(urllib)
  • I cannot import the long list of IronPython modules

In fact, many modules don’t show up from the IronPython Lib folder.
I have already troubleshooted:

  1. setting default search folders in Python Edit window > Options
  2. making sure that the files aren’t blocked on Windows

Setup:

  • running Windows 10 version 10.0.18363 Build 18363
  • running bootcamp on a MacBook Pro 2013
  • running Rhino 6 sr 24 (education)

None of this is unusual. There seems to be something blocking the imports of the other Python modules?


The intellisense is named intelliclunk in Rhino for a good reason :wink: But just because a module doesn’t show up on import doesn’t mean you can’t use it. Unfortunately the help("modules") method doesn’t work in IronPython for listing all available Python modules. But you could do something like this to get an overview (note that this won’t list the available .NET libraries):

200417_GHPython_GetIronPythonModules_00.gh (4.6 KB)

Can you post a screenshot of the error messages that you get?

3 Likes

Anders

Thank you so much for the help. Your script works well to expose 235 modules from IronPython. I actually don’t get any errors anywhere… it’s just all blank. Sadly my Rhino V7 has the same problems.

However, I then did this test with urllib2 in the ghPython component and it worked:

import urllib2
print dir(urllib2)

response = urllib2.urlopen('http://www.maketank.org/')
html = response.read()
print html

I guess this built-in Rhino python editor isn’t a helpful Intellisense. I’ve tried to setup other IDEs and Intellisense on windows but it’s been a terrible process. What do you used for an IDE? Any recommendations for an IDE where I can use a better intellisense? I really need it to be complete and work well.

Thanks, Darrel

It isn’t entirely useless, one just have to be aware of the limitations. When you import a module it will generally autocomplete when you invoke the import name. Also, if the type is known by the editor (e.g. when inputting something in GHPython and using dot notation directly on the input parameter name) autocomplete will generally work.

I actually just use the GHPython editor when developing for and in Rhino/Grasshopper. And then Sublime Text when doing CPython stuff outside of Rhino. I try not to rely on intellisense in general when writing Python code, and instead use features of the language for introspection (see here and here). I also usually have e.g. the RhinoCommon API docs open, and whatever else I’m implementing.

In that case, I would probably consider dropping down to C# and installing Visual Studio. But again, that depends a bit on your development requirements (i.e. are you developing a full-fledged plugin, just making some small scripts here and there etc.).

1 Like

Anders

One last reply I guess. I’ve added a modified version of the .py and .gh script here in my Github repo called GetIronPythonModules. The readme explains the scripts.

  • Yes, the intellisense seems to start working after an import.
  • I also have the RhinoCommon and Rhinoscriptsyntax open too, but really need the help of intellisense
  • I really want to avoid C# since I mostly script for Grasshopper at the moment. I don’t like the class focus, verbose structure and type requirements of C#.

Thanks. Darrel

1 Like

I hear you, you might also want to give this a go: