Unable to load in custom module

Hello everyone,

I wasn’t having luck with loading third-party modules in Rhino 7. I searched through many posts until I discovered that Rhino 8 has new functionalities regarding Python. I attempted to install the packages in the site-package folder using the cmd and use the import function, but that didn’t seem to work. So, I tried using sys to provide a reference to the site-package folder, but that didn’t help either.

Could it be because the request module is not compatible with Rhino? Does anyone have a tutorial on how to install and use third-party modules for ghpython?

Thanks a lot!

I’m not sure where the Rhino 8 CPython is, but it looks just like you used pip from a separate Python 3.9 installation. I think requests is installed, just in a separate Python installation than the one Rhino uses.

Why not add at the start of your script

# r: requests

import requests

That should have the embedded Python install the module if it isn’t yet. No need to mess about with paths.

Do you know how to the select the python version I want to use to install the requests module? I only learned how to use pip install in the cmd. And I tried using the comand prompt in the GH component but that did not do anything.

With a script module set to Python 3, did you try what I suggested?

Yes it worked great stuff!

Do you know where I can find the documentation for the solution you provided? I’d like to understand how it works so I can use it in case I encounter other issues. Additionally, is it possible to load every other packages using the same method?

I don’t know if it is documented elsewhere yet, @eirannejad will know.

But for now you can just run ScriptEditor in Rhino, then add a new script and choose new Python 3

The new file will have a doc string explaining this.