I have successfully installed Pandas and Numpy in Rhino 8. However, I’m struggling with installing libraries such as scikit learn or pytorch libraries. The error seems like related to dependency conflicts… For which I was hoping the installer can handle it automatically.
Has anyone had similar issues, and what is your solution?
Just a throught…
The python environment under .rhinocode directory doesn’t seem like a conventional python venv. What is the approach to run the environment and install the needed python packages manually instead of installing through script editor?
- The venvs inside of Rhino are basically independent paths for installing packages. The traditional venv design won’t work here since once python that is loaded inside of Rhino you can’t unload unless you restart Rhino.
- Script editor literally uses
pip install pytorch
to install the package and pip will resolve dependencies. But for example if you have already installed and loaded numpy in a Rhino instance, and thenpip install pytorch
needs to install a different numpy version, it might fail removing the existing numpy as its binaries are already loaded in Rhino. Run “Tools > Advanced > Reset Python 3 Runtime” to reset the runtime, and install pytorch fresh.
I’m documenting these soon.
Hi @eirannejad , thanks for the quick response. I can’t seem to find the “Tools>Advanced” let along “Reset Python 3 Runtime”. It’s late afternoon so my brain is running very slow… Can you point me to where that exactly is?
Ok, it is my brain frozen. I found it in the editor window.
I followed your suggestion and reset the python 3 runtime, and I also removed all python modules from site-env in case of any potential conflicts.
Intalling Pytorch along is indeed successful, but It’s not with installing scikit-learn library. The error still shows dependency conflicts related to matplotlib which I believe is installed along with the scikit-learn.
THen I tried to add matplotlib along with scikit-learn, now I get other dependency conflicts.
@yangallen3 What is your package specification line look like? Would you mind sharing so I can test as well?
Yes. I’m running this in the Grasshopper Script Editor btw.
# r: scikit-learn==1.3.2
I just ran this on a clean python 3 runtime and it worked:
# r: scikit-learn==1.3.2
import sklearn
print(sklearn)
Do you see a red status bar when running this script? Would you mind running RhinoCodeLogs
and sharing the logs with me? You can easily save the contents from the Logs menu
Yes, at first I see the red band at the bottom of the editor, it says “Error restoring packages”, as the image shown.
And then here is the error message once I clicked in:
`Info 01/22/2024 22:12:15 [RhinoCode] Installing: scikit-learn ==1.3.2
Info 01/22/2024 22:12:15 [RhinoCode] Running process: C:\Users\xxxx.rhinocode\py39-rh8\python.exe -m pip --disable-pip-version-check install --target “C:\Users\xxxx.rhinocode\py39-rh8\site-envs\default-X_c+x5XZ” --upgrade --no-warn-script-location --retries 0 --timeout 1 “scikit-learn ==1.3.2”
Error 01/22/2024 22:12:53 [RhinoCode] Process exited with code 2
Error 01/22/2024 22:12:53 [RhinoCode] Error restoring packages | System.Exception: Error installing: scikit-learn ==1.3.2 | ERROR: pip’s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
matplotlib 3.7.1 requires fonttools>=4.22.0, which is not installed.
matplotlib 3.7.1 requires importlib-resources>=3.2.0; python_version < “3.10”, which is not installed.
matplotlib 3.7.1 requires kiwisolver>=1.0.1, which is not installed.
matplotlib 3.7.1 requires pyparsing>=2.3.1, which is not installed.
matplotlib 3.7.1 requires python-dateutil>=2.7, which is not installed.
altair 4.2.2 requires pandas>=0.18, which is not installed.
altair 4.2.2 requires toolz, which is not installed.
ERROR: Exception:
Traceback (most recent call last):
File “\?\C:\Users\xxxx.rhinocode\py39-rh8\lib\site-packages\pip_internal\cli\base_command.py”, line 173, in _main
status = self.run(options, args)
File “\?\C:\Users\xxxx.rhinocode\py39-rh8\lib\site-packages\pip_internal\cli\req_command.py”, line 203, in wrapper
return func(self, options, args)
File “\?\C:\Users\xxxx.rhinocode\py39-rh8\lib\site-packages\pip_internal\commands\install.py”, line 446, in run
self._handle_target_dir(
File “\?\C:\Users\xxxx.rhinocode\py39-rh8\lib\site-packages\pip_internal\commands\install.py”, line 501, in _handle_target_dir
shutil.rmtree(target_item_dir)
File “shutil.py”, line 749, in rmtree
File “shutil.py”, line 622, in _rmtree_unsafe
File “shutil.py”, line 627, in _rmtree_unsafe
File “shutil.py”, line 625, in _rmtree_unsafe
PermissionError: [WinError 5] Access is denied: ‘C:\Users\xxxx\.rhinocode\py39-rh8\site-envs\default-X_c+x5XZ\numpy\core\_multiarray_tests.cp39-win_amd64.pyd’
at Rhino.Runtime.Code.Languages.PythonNet.CPythonEnviron.AddPackages(IEnumerable1 pkgSpecs) at Rhino.Runtime.Code.Environments.Environ
1.Rhino.Runtime.Code.Environments.IEnviron.AddPackages(IEnumerable1 pkgSpecs) at Rhino.Runtime.Code.Code.RestorePackages() at RhinoCodeEditor.Editor.Commands.WithCodeExecutableCommand.ExecuteCodeContext.RestoreCode()
This line is pip trying to delete the .pyd
file in an exsiting installation of numpy but fails because it is already loaded in Rhino. Did you run this on a fresh python 3 runtime with no environments?
Hmm… I didn’t set up any environment for running this python editor, i thought the script editor would use the environment from one of the site-envs in the .rhinocode directory, although I did reset python 3 in Rhino prior to this run.
I do have a globally installed Numpy on my machine, not installed in any virtual environment, not sure if this would cause any problems while rhino is trying to load or remove Numpy.
It should not. Delete ~/.rhinocode/py39-rh8\site-envs\default-X_c+x5XZ
and install again. Rhino should be closed.
Thank you, Ehsan, for your detailed guidance! Following your steps, I managed to resolve the issue. Here’s what I did:
- I reset the Python runtime.
- Closed Rhino to ensure no conflicts with packages currently in use.
- Removed the auto-generated environment.
This time I installed only Scikit-learn without adding any other packages initially.
Your analysis was spot on. The root cause of the error was due to having Matplotlib installed before Scikit-learn. Since Matplotlib also depends on NumPy, and Scikit-learn was trying to modify the NumPy installation, a conflict occurred.
By scratching off the line that installs Matplotlib ( # r: matplotlib
), I successfully avoided the conflict and installed Scikit-learn without any issues.
Sweet Thanks for the test and feedback. Jus so you know, I have a ticket to create a Rhino backend for matplotlib so plots can open in Eto windows in Rhino:
RH-74046 CPython matplotlib needs a Rhino/Eto backend probably (affects pandas)