Problem using CPython Libraries

Hello,

I have some issues using Cpython libraries. I would like to use libraries in python as usual by installing them with pip, but even the pre-existing exemple with numpy doesn’t work.

I get this error :
Traceback (most recent call last):
File “file:///C:/Users/**/test.py", line 3, in
File "C:\Users*
.rhinocode\py39-rh8\site-envs\default-HL8Gx7po\numpy_init_.py”, line 164, in
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.

I tried to install numpy in the proper folder with the pip in rhino’s python install and it seems to be already installed :

Requirement already satisfied: numpy in c:\users*******.rhinocode\py39-rh8\lib\site-packages

And when i check the sys.path i got many path inculding this one :

‘C:\Users\********\.rhinocode\py39-rh8\lib\site-packages’

Also if i run “import numpy” directly throught the python.exe in .rhinocode it work perfectly !

So if somebody has a solution it would be really helpfull !

Thanks

I was working on it for a few days and i finally found a way !

When i run :

import sys
print(sys.path)

Among many path there is this one :

‘C:\Users\******\.rhinocode\py39-rh8\site-envs\default-HL8Gx7po’

And it’s this one which causes the probleme, because python should not look in this directory for modules. So I have to remove it from sys.path like this :

import sys
sys.path.remove(‘C:\Users\******\.rhinocode\py39-rh8\site-envs\default-HL8Gx7po’)

I have to do it at the beginning of each code because i dont want to mess with the pythonpath.

I hope it will help someone !

@Besson_Thomas Numpy sometimes throws this error and I have a ticket to look deeper at this. For any of pip packages that are giving you troubles you can specify the line below in your script and the package installer will install in site-packages instead

venv: site-packages

RH-80494 ImportError on importing numpy from source directory

@Besson_Thomas
Which version of Rhino are you running?

@Besson_Thomas

I would appreciate if you can check something for me. Install numpy normally in the script editor (not in site-packages). This should error on your machine as shown above.

Then go to this folder: (%HOMEPATH% is your home directory and default-* is the default environment in rhino python 3 deployment):

%HOMEPATH%\.rhinocode\py39-rh8\site-envs\default-*\numpy\core

Check to see if all these .pyd files are available.

explorer_Uk1FsvvAXf

The primary reason that this ImportError is happening, should be either one of these .pyd files are missing or security policies setup on your machine that stops them from being loaded. I am trying to confirm this

Rhino 8.5

All of these file are in the folder :confused:

1 Like

@eirannejad I also get this error. It goes away if I delete the environment that I am pointing in [Options Menu]. On the other hand. I realized that whatever modification I do in the Options Menu never gets saved, i.e., I have to it over again for every single component that I create. The button Restore Defaults is not working here either. I am using Rino 8.6 SR6

ImportError: Error importing numpy: you should not try to import numpy from its source directory;
please exit the numpy source tree, and relaunch your python interpreter from there.

To come back to the solution pointed by @eirannejad, my default-* folder is empty. How do I add the missing .pyd files there?