RhinoCode ScripEditor for development of libraries

Hi,

There are two key issues I have when developing python libraries and testing them on RhinoCode. I am using vscode and pip to install my local package to rhinocode python directory, since I am always working within a conda environment.

Following are key problems:

  1. RESTART RHINO - everytime I add new code, methods or classes in vscode I need to reload rhino. First time you pip install your package like this: C:/Users/my_user_name/.rhinocode/py39-rh8/python.exe -m pip install -e .
    But still rhino needs to be restarted every time you change code in Visual Studio Code.
  2. CONDA - rhinocode uses its own environment so everything must be installed through PIP, this leads to two sub-problems:
    2.1. I always need to switch between my conda environment and rhino editor since is impossible to work on conda.
    2.2. The PIP only solution prevents to install conda packages specially c++ ones e.g. boost, cgal and others, let alone local packages that pip builds on c++ conda libraries.

I am wondering why the decision was made to have a stadalone python editor instead of more flexible conda environments that you switch simple everytime you work on different project? I think I heard this questions from multiple users.

I get that for fully polished libraries it is a great editor, but for development it is really slowing the work.

1 Like

@Petras_Vestartas

Rhino 8 uses pip to install packages. I have a ticket for conda support but that is future.

  • You can use a standalone conda to install your packages (python 3.9.10) in any other environment and point the script editor to those directories:

    • Python paths config: Rhino
    • Using # env: /put/path/here/ on top of your script
  • We had an issue reloading imported modules in Python 3 runtime that is fixed for Rhino 8.6 RC. You can use importlib.reload method at the top of your script to reload the imported module when you are making changes to that in vscode

  • Our pip also had an issue installing some packages due to missing libraries in ~/.rhinocode/py39-rh8 folder. We have solved that for Rhino 8.5 RC that is out right now. It should be better now but let me know if it still can not install your packages. You can also add # venv: site-packages to the top of your script in case of problematic packages to install them in the default site-packages/ instead of site-envs/ as it normally does.

Does this help?

1 Like

Hi,

Thank you for a reply. The egg link works. But the problem I am facing now is .pyd file. By .pyd I am refererring to c++ compiled code of mine in my conda environment.

I compiled it using 3.9.10 version. But even manually adding the path to sys does not recognize it. I tried all sorts of different solutions the whole week…

Any suggestions how to load correctly .pyd?

I also thought about compiling my .pyd file using rhino Python.exe, but you do not redistribute Python39.lib nor python.h C++ headers.

Which python package is this? I am assuming you are adding the path to where the package folder exists and not the path that directly contains the .pyd files right? sys.path are search paths for where the package folder exist. Just checking to make sure

numpy has .pyd libraries and they seem to be working.

One other thing you can to test do is to add the path of where the .pyd files are loaded to the system PATH in environment variables and see if Rhino will find those when running the script. I’d like to know that if it does, so maybe I can improve this.

Please try these conda commands, you would understand it better this way:

conda create -n wood-dev python=3.9.10 mpir mpfr boost-cpp eigen=3.4 cgal-cpp=5.5 pybind11 compas --yes
conda activate wood-dev
git clone https://github.com/petrasvestartas/compas_wood.git
cd compas_wood
pip install -e .

For egg linking to rhino python directory:
C:/Users/petrasv/.rhinocode/py39-rh8/python.exe -m pip install -e .

1 Like

I get this on windows when running the first conda command

PackagesNotFoundError: The following packages are not available from current channels:

  - cgal-cpp=5.5
  - python=3.9.10
  - compas

Maybe first add and using administrative rights:

conda config --add channels conda-forge

1 Like

Also I do not know about .pyd files, but .dll always must have these two .dlls next to it, due to CGAL dependency. I have also an other version of code using ctypes library on python. But debugging through ctypes library c++ is really tedious and slow process. Meaning one c++ error, whole rhino crash. I really wish that I could directly load .pyd file instead of.

We also have multiple other libraries that use similar project configuration and do not have a proper workaround.

Ok this is taking a bit to setup and get ready. But I’ll look into it today and will update you. Thanks for sharing the setup info.

1 Like

Thank you, really looking forward for a support on this.

hitting this error when pip install-ing in editable mode. I am using python 3.9.10 installed with pyenv and latest pip. Is there anything else I need to setup to install this package?

Obtaining file:///C:/Users/ein/compas_wood
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... error
  error: subprocess-exited-with-error

  × Getting requirements to build editable did not run successfully.
  │ exit code: 1
  ╰─> [22 lines of output]
      Traceback (most recent call last):
        File "C:\Users\ein\.pyenv\pyenv-win\versions\3.9.10\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
          main()
        File "C:\Users\ein\.pyenv\pyenv-win\versions\3.9.10\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "C:\Users\ein\.pyenv\pyenv-win\versions\3.9.10\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 132, in get_requires_for_build_editable
          return hook(config_settings)
        File "C:\Users\ein\AppData\Local\Temp\pip-build-env-51sch7av\overlay\Lib\site-packages\setuptools\build_meta.py", line 441, in get_requires_for_build_editable
          return self.get_requires_for_build_wheel(config_settings)
        File "C:\Users\ein\AppData\Local\Temp\pip-build-env-51sch7av\overlay\Lib\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "C:\Users\ein\AppData\Local\Temp\pip-build-env-51sch7av\overlay\Lib\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "C:\Users\ein\AppData\Local\Temp\pip-build-env-51sch7av\overlay\Lib\site-packages\setuptools\build_meta.py", line 480, in run_setup
          super().run_setup(setup_script=setup_script)
        File "C:\Users\ein\AppData\Local\Temp\pip-build-env-51sch7av\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 100, in <module>
        File "<string>", line 42, in get_eigen_include
        File "C:\Users\ein\.pyenv\pyenv-win\versions\3.9.10\lib\ntpath.py", line 78, in join
          path = os.fspath(path)
      TypeError: expected str, bytes or os.PathLike object, not NoneType
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build editable did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

I’ll switch to pip in conda environment

This comes from:

Which says that conda environment is none:
image

If I understand correctly you are not running the setup.py file in conda.

This is what terminal prints, if I run it directly in python editor:

Ok manually setting CONDA_PREFIX to the conda environment seems to do the trick. Building now

1 Like

Ok this works. How does I make it test compas_wood functionality? is there an example code I can run? Looking into the repo right now

#! python 3
# env: C:\Users\ein\compas_wood\src

import compas_wood as cw
print(cw)
1 Like

Is this the problem you are seeing?

1 Like

Used you last suggestion from this thread How do i properly point rhino to an existing Anaconda env? - #22 by eirannejad

Still not able to make this work

image
image

Exactly.

Exactly:

from compas_wood.joinery import test

test()

Yes wood_pybind11.pyd, it gets build using setup tools:
image

The .dlls you see in screenshot I copied manually. But they do not have any effect. It is quite hard to debug the not found error you see. The .pyd is the one that is not linked properly.