jesterKing / import_3dm

Blender importer script for Rhinoceros 3D files
MIT License
311 stars 38 forks source link

Separate rhino3dm install and update #50

Closed tsvilans closed 5 months ago

tsvilans commented 5 years ago

Is your feature request related to a problem? Please describe.

Describe the solution you'd like

Describe alternatives you've considered Manually running python -m pip install -upgrade rhino3dm from the Blender Python executable.

tsvilans commented 5 years ago

@jesterKing I just tagged you because you were looking into the wider rhino3dm installation stuff! If you'd like, I can also tackle this, however.

jesterKing commented 5 years ago

@tsvilans yes thanks for logging the issue!

jesterKing commented 5 years ago

I'm running into a bit of a problem. Since rhino3dm is a non-pure Python module, using shared library in C/C++ it is impossible to update the module in-process. Currently I get this exception


Exception:
Traceback (most recent call last):
  File "C:\Users\Nathan\AppData\Roaming\Python\Python37\site-packages\pip\_internal\basecommand.py", line 228, in main
    status = self.run(options, args)
  File "C:\Users\Nathan\AppData\Roaming\Python\Python37\site-packages\pip\_internal\commands\install.py", line 381, in run
    options.target_dir, target_temp_dir, options.upgrade
  File "C:\Users\Nathan\AppData\Roaming\Python\Python37\site-packages\pip\_internal\commands\install.py", line 432, in _handle_target_dir
    shutil.rmtree(target_item_dir)
  File "c:\users\nathan\appdata\local\programs\python\python37\lib\shutil.py", line 507, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "c:\users\nathan\appdata\local\programs\python\python37\lib\shutil.py", line 391, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "c:\users\nathan\appdata\local\programs\python\python37\lib\shutil.py", line 389, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\Nathan\\AppData\\Roaming\\Blender Foundation\\Blender\\2.80\\scripts\\addons\\modules\\rhino3dm\\_rhino3dm.cp37-win_amd64.pyd'

I think I'll just make import_3dm always try to update rhino3dm when loaded.

tsvilans commented 4 years ago

Hey @jesterKing, I've done a similar thing for the SpeckleBlender add-on for dependency installation. This seems to work:

import os, subprocess
modulespath = os.path.normpath(os.path.join(bpy.utils.script_path_user(),"addons","modules"))
res = subprocess.run([bpy.app.binary_path_python, "-m", "pip", "install", "-q", "--upgrade", "-t", "{}".format(modulespath), "rhino3dm"])

It doesn't require admin privileges - since it puts it in the user data folder - or a Blender restart, so it seems like a safer bet. I'll try to update the dependency installation code and put it in a separate script file for a bit of clean-up.

tsvilans commented 4 years ago

Ah, and regarding your issue above, I ran into the same thing.. Only thing I could do was disable the add-on, reboot Blender, run the update code, and then all is well.

A clunky solution would be to have a sidecar rhino3dm updater add-on which just wraps that up into a button / Blender operator... I suppose that would just be the equivalent of an installer / updater script.

jesterKing commented 5 months ago

The rhino3dm module is now part of the release files.