1

I am using the Mac version of Rhino/Grasshopper. I am trying to import a module for using Python inside Grasshopper. When running the script, I receive the following error. I have AppKit installed. I’ve even tried saving AppKit and PyObjC in a separate directory and using sys.path.append to access it.

Any idea what I am doing wrong or can try?

Code:

import rhinoscriptsyntax as rs

import AppKit

enter image description here

Code:

import rhinoscriptsyntax as rs

my_path = '/Users/author/Desktop/pyobjc'
sys.path.append(my_path)

import AppKit

enter image description here

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
NewbCake
  • 433
  • 2
  • 7
  • 22
  • @Steve I remove drawBot and only import AppKit. I did a new pip install pyobjc in both python 2 and 3 but I still receive the import error. – NewbCake Feb 24 '19 at 02:28
  • wow. strange. Are you trying the import statement using just python from the command line, or is this complicated by Grasshopper (which I'm unfamilar with)? Sounds like you're doing it in python itself. Well, I just gave you one datapoint in checking that it works simply for me. Not sure what to think if you get different behavior doing the same thing. If you can give me any other info, I'd love to help you get to the bottom of this. – CryptoFool Feb 24 '19 at 02:34
  • The import statement just from terminal doesn't return an error. It seems to be complicated by Grasshopper. That's why I was trying to set a direct path to the AppKit folder. – NewbCake Feb 24 '19 at 02:36
  • Ah. Ok. I doubt that Grasshopper is screwing up Python. My guess is that it's using a different python version than where you've installed AppKit. Is that possible? – CryptoFool Feb 24 '19 at 02:37
  • 1
    I think one of the complications is that Grasshopper uses its own version (not sure what the right word is) of Python called IronPython – NewbCake Feb 24 '19 at 02:39
  • ah. that would do it. - I think you need to figure out how to install packages into that version of python rather than trying to hack it in with path changes. - I admire what your'e trying though :) – CryptoFool Feb 24 '19 at 02:39
  • Let me ask you this. When I do the sys.path.append to the pyobc folder, not sure if it solves the AppKit but it throws another error, something like 'No module _objc in objc' – NewbCake Feb 24 '19 at 02:41
  • I will try to install the packages into that version...but one of my difficulties is finding the darn site-packages folder – NewbCake Feb 24 '19 at 02:42
  • It sounds like that gets you further. Unfortunately, it also points out why pointing at individual packages with your path is problematic. It seemed that "pip install pyobjc" installed a bunch of stuff. So you might have to add a whole bunch of stuff to your path to pick up all of the packages that pyobc depends on. This may be what you're running into here. – CryptoFool Feb 24 '19 at 02:44
  • Yeah, I get you. But I think that is a better answer. – CryptoFool Feb 24 '19 at 02:44
  • Shouldn't it work if you've directed the path to the top level folder that contains both AppKit and objc? Or do you have to add each subfolder individually? – NewbCake Feb 24 '19 at 02:46
  • Possibly. I don't know much about doing that. The reason I don't know much about doing that, is that I think I've always found a better way to do it. But it's been many years since I've used IPython, so I can't tell you that this isn't the only way to go about it. As soon as you said IPython, I went from being somewhat an expert to being an amateur. - I can't even remember what IPython IS..how it's different from standard python. – CryptoFool Feb 24 '19 at 02:48
  • Ok. Well, thank you for trying. – NewbCake Feb 24 '19 at 02:50
  • I assume you've googled this issue for a solution. Seems like others would have run into this. I tried a bit, and didn't find anything too obvious. – CryptoFool Feb 24 '19 at 02:50
  • yikes. Googling for "appkit grasshopper" comes up with almost nothing...your question is the top item. Same for "pyobjc grasshopper" – CryptoFool Feb 24 '19 at 02:53
  • sorry I couldn't be more helpful :( - please let me know if you figure it all out – CryptoFool Feb 24 '19 at 02:53
  • I have such a hard time giving up. I looked at Grasshopper, and even installed it. It comes in as a single app named Rhinocerous.app, with no installer, right? Or did I install the wrong thing? If that's it, and so there's no installer, then IPython has to be within the app. And doing a "find" for all .py files, I see that it's there: l see /Applications/Rhinoceros.app/Contents/Resources/ManagedPlugIns/RhinoDLR_Python.rhp/Lib. Have you gotten that far yet? PS: I can't run it. Seems to require a license. – CryptoFool Feb 24 '19 at 03:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/188943/discussion-between-newbcake-and-steve). – NewbCake Feb 24 '19 at 03:07
  • @NewbCake, I think the term for a specific implementation of Python such as IronPython is *flavor*. For example: IronPython is an open-source flavor of the Python programming language implemented using the .NET Framework. – Trevor Reid Mar 21 '19 at 08:52

1 Answers1

0

The IronPython implemented in Rhino 3D will have search paths that are separate from other Python environments you may have installed.

On Rhino for Windows, you would have been able to run EditPythonScript in the Rhino command line to configure these paths via a dialog. Or _EditPythonScript for a strictly command line approach.

But on Rhino for Mac configuring these paths is less straightforward. There is not yet an editor, debugger, or user interface for configuration fully baked in.

There is a work around using the Atom editor that works with Rhino 5.2 WIP 5C41w and later. After installing the rhino-python package for Atom:

  1. Press the control + option + s to open the Rhino Python Search Paths panel.
  2. Add or edit one or more paths. You cannot edit the default system paths, but can add custom search paths and edit these as needed.
  3. Click Save to update

From your Python scripts in Rhino, you should now be able to import AppKit and other packages from the newly specified locations.

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46