Grasshopper

algorithmic modeling for Rhino

Hi all:

I am quite new to using Python in grasshopper; in fact, I'm sort of new to python altogether. I recently downloaded a Python library called Beautiful Soup. I am trying to write a simple script to glean information from webpages (aka screen-scraping), and I would like to use grasshopper to manage the data that I receive from my script.

Immediately I am facing an obstacle because I do not know how to install the Beautiful Soup library so that I can use it within my ghPython component. Ideally, I would like to be able to call "import BeautifulSoup", but this causes issues because I don't know in which directory I should install it... Has anyone worked with BeautifulSoup + GH before and can explain how they accomplished this? Or maybe there is someone who has installed an external Python library who can elucidate the process for me. Any advice at all is welcomed.

- William

Views: 3118

Replies to This Discussion

William,

It's important to note that as Rhino implements IronPython there are some libraries which will not work with the installation you're using. I've done a quick install myself and it seems to be working okay however you may find there are bits that may not work. Trial and error I'm afraid.

The easiest way if you're familiar with Python is to use pip to install it via the cmd shell. However if you're not comfortable doing that you can simply download the source package from their website and extract the folder named 'bs4'. You can save this where ever you like but I'd suggest using the location below: C:\Program Files\Rhinoceros 5 (64-bit)\Plug-ins\IronPython\Lib\site-packages

You then need to add that same path so Rhino will know where to find beautiful soup when you ask it to. In Rhino (not grasshopper yet) open the python editor with '_EditPythonScript' go to the tools menu>options and then add the path to the module search paths.

Press ok. Sometimes Rhino will need to be closed and opened again to effect this change. Next open your grasshopper component and you should be able to use:

import bs4

print dir(bs4)

Good luck.

Mat:

Thank you so much for your answer. It worked perfectly, and the explanation was very thorough; I am super grateful for your help and expertise. This should hopefully sate my appetite for the next couple of days as it allows me to import and take advantage of many of the wonderful python libraries available around the web.

As I have already mentioned, I am quite new to python. I do have a shallow background in programming, however. I look forward to exploring python's applications within the GH environment. As far as workflow is concerned, are IDEs commonly used? For example, are people using third-party software like SublimeText, et cetera and then copying and pasting the code into their ghPython editor? I have experience with IDEs back when I was programming with Java. I found them useful, but I am not aware of the common practices within the Rhino/GH programming environment. Does anyone have a workflow that they've found useful, or is everyone simply using the built-in editors of say the C# component, python component, VB component?

Thanks again, Mat!

Personally I'm more comfortable using a simple word editor (notepad++) when I'm working on something more complex. Else for short bits I tend to find the python editor built into Grasshopper and Rhino is usually sufficient.

There has been some work done on the python script interface with Grasshopper in Version 6 WIP of Rhino. Some interesting stuff for debugging and the ability to compile python code to nodes. 

If you're developing grasshopper nodes you  might want to look at C# rather than python (for speed and a number of other issues) but of course you lose the ability to plug-in some of the great python modules out there.

For C# development (which I'm only just starting to learn myself) I've set up visual studio.

Thanks again, Mat. I just downloaded Notepad++, and I'm going to give it a whirl.

I have given C# a brief look once I learned that it was Microsoft's response to Java. And I've noticed that the basic structure of C# code looks eerily similar to Java's structure and syntax as well. I believe that my previous experience with Java should make the transition into the C# world not terribly daunting, but I am reluctant to shift away from Python since I really appreciate its design.

Unfortunately you're right about Python's ability to compete in terms of speed, which I imagine is symptomatic of its existence as an interpreter-driven programming language. Maybe it is Python's interpreter environment that allowed its language to be designed so wonderfully... I don't know, a double-edged sword perhaps. I digress, but thank you again for your quick and informative feedback!

Hi William,

I was curious if you had any luck with data scraping to get live website data into grasshopper?  I have been researching how to do this for some time now, and haven't found any useful blogs about it.  Can you let me know what you find out?

Thanks!

-Cody C

1. Requests. The most famous http library written by kenneth reitz. It’s a must have for every python Program developer.

2. Scrapy. If you are involved in webscraping then this is a must have library for you. After using this library you won’t use any other.

3. wxPython. A gui toolkit for python. I have primarily used it in place of tkinter. You will really love it.

4. Pillow. A friendly fork of PIL (Python Imaging Library). It is more user friendly than PIL and is a must have for anyone who works with images.

5. SQLAlchemy. A database library. Many love it and many hate it. The choice is yours.

6. BeautifulSoup. I know it’s slow but this xml and html parsing library is very useful for beginners.

7. Twisted. The most important tool for any network application developer. It has a very beautiful api and is used by a lot of famous python developers.

8. NumPy. How can we leave this very important library ? It provides some advance math functionalities to python.

9. SciPy. When we talk about NumPy then we have to talk about scipy. It is a library of algorithms and mathematical tools for python and has caused many scientists to switch from ruby to python.

10. matplotlib. A numerical plotting library. It is very useful for any data scientist or any data analyzer.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service