Compliling Components using GHPython and PyDev

grasshopper
python

#1

Hello everyone,

I am trying to compile a test component importing PyDev code into the GHPython component. Is it possible at all? I wonder if somebody already tested it.

However, on the quest of trying it out myself, I discovered another problem. The PyDev workflow which has been working so far with Rhino 5 is not working in Rhino WIP. Did someone encounter the same problem?

For Rhino 05, I have recently configured PyDev following this:

In order to update the workflow to Rhino WIP, I used the new RhinoCommon.dll and RhinoCommon.xml files to make PyDev see Rhino. That seems to be working fine. However, on the RhinoPython side, I am not being able to make Rhino see PyDev. I have a — Runtime error (ImportException): No module named ‘my module name’ — returned. I did double check whether my Eclipse module was linked to the Rhino Python Options.

Many thanks,
Miriam


(Giulio Piacentino) #2

Hi Miriam

I think you mean ‘run Python code from an external editor (IDE)’, right?
There is also functionality regarding compilation, but I think that it not what you are looking for, I think.

The error _“No module named ‘<_somename>’.” means that <somename>.py is not to be found in any folder listed in the sys.path variable. You can add that folder dynamically to sys.path

import sys; if not mypath in sys.path: sys.path.append(mypath)

or go to EditPythonScript -> Options -> Module search paths (this is for Rhino for Windows only).

I hope this helps

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com


#3

Hello Giulio,

Thanks for your prompt response.

Nope, I would like to know whether it is possible to compile components even when importing parts or all the code from PyDev. That is the ultimate goal.

And yay, with the ‘import sys’


it works! Many thanks.

However, when trying to import the path in EditPythonScript options it doesn’t. And the path is there (last one in the list)


Any idea why?

Thanks again :slight_smile:
Miriam


#4

Hi Giulio,

I promise I didn’t re-start Rhino and now the Python component runs without adding the path dynamically! Would love to know why :wink: Just as a matter of feedback, bellow is the difference of speed between adding the path dynamically (top) and having it loading normally from the RhinoPython editor:

With that sorted, we are back to the initial question:

How to compile the components utilising that workflow? When I try to compile that component here is the error I would appreciate some help with:

Thanks a lot in advance,
Miriam


Rhino 6 WIP, Grasshopper, Python does not load os module
(Giulio Piacentino) #5

Sorry, we will have to see if this happens again (not finding paths in sys.path). It seems strange.

I am not sure why it would take 240ms to check if a string is in a list and to add it if not. It seems this might be doing something more. Have you tried re-computing the whole definition? If you haven’t restarted Rhino in 5 days, it might be a good time to try that anyways.

About compiling: your setup will not work automatically. It will work automatically only if you have all your code in the component. Also, reload() is definitely a no-go for compiling. To compile this, you will need to set-up a folder where you want everything to compile. Then, copy the “compilable code” from the folder. You will have to save that, too, in the compile folder. Follow the instructions that appear after copying the code to clipboard. I need to make a guide with an example, just not today I think.


#6

Yes, when it started running without the dynamic call, I re-started Rhino straight away to check and both manners are working. I will run some tests and will report if any problems.

– (good idea!)

With regards to reload(). I didn’t know that it is a no-go for compilation, many thanks. Why? I was utilising reload() because if I don’t, the changes that I make to the code in PyDev just take effect if I reload Grasshopper itself.

With regards to the setup. I will follow the instructions, but still did not fully understand. Does that mean I will have to compile the code to this folder and import the directory in PyDev? Pardon, I am a bit confused. l will keep tuned for the guide.

Thanks Giulio!


#7

hi, i might have similar problem here:


#8

Hi Guys,

Unfortunately I am still not set. I will keep trying but, as usual, would appreciate some help.

I forgot about PyDev for a second and I tried to compile the code bellow, just for testing if there was something wrong with the compilation process itself and here are the results:

Figure 01 - Script view.

Figure 02 - Compilation view

‘MissingMethodException’ again. I could not fix it yet.

Many thanks,
Miriam


(Giulio Piacentino) #9

I think you might be another victim of “extra installs of IronPython” . There seems to be a conflict between the version installed by Rhino and an independent install.


#10

Ok, let me have a look at that post.

I have here:
IronPython 2.7.3
Python 2.7.12
Python 3.5.2


(Giulio Piacentino) #11

Uninstall IronPython. The error should go away. Rhino ships with its own version of IronPython


#12

IronPython uninstalled, system re-started. When re-opening GH:

When compiling, ApplicationException:


(Giulio Piacentino) #13

OK; this is better. Let me write a guide, test this in the last WIP (we have made some changes recently) and then I will get back on compiling, OK, Miriam?


#14

Cool, I will be working on other parts in the meantime.
Many thanks, Giulio.


(Giulio Piacentino) #15

@Miriam As promised, I wrote a tutorial and this can now be tested in the WIP.

I hope this is helpful; please let me know if you have any questions.


#16

Great timing, thanks a lot for putting this together. Will soon jump on this back again.


#17

PyDev for compilation: Tick!

Thank you!


Tutorial: creating a Grasshopper component with the Python GHPY compiler