mcneel / rhino3dm

Libraries based on OpenNURBS with a RhinoCommon style
MIT License
582 stars 135 forks source link

import rhino3dm fails #438

Closed KeithSloan closed 2 years ago

KeithSloan commented 2 years ago

I have tried to install rhino3dm in a library where FreeCAD will find it with

pip3 install -t /Applications/FreeCAD_19.2.app/Contents/Resources/lib/python3.8/site-packages rhino3dm --upgrade --force

But import rhino3dm fails with

import rhino3dm as r3
  File "/Applications/FreeCAD_19.2.app/Contents/Resources/lib/python3.8/site-packages/rhino3dm/__init__.py", line 5, in <module>
    from ._rhino3dm import *
<class 'ModuleNotFoundError'>: No module named 'rhino3dm._rhino3dm'

init.py looks like

import sys
if sys.version_info.major==2:
    from _rhino3dm import *
else:
    from ._rhino3dm import *

__version__ = '7.7.0'

Point2d.__str__ = lambda self: "{},{}".format(self.X, self.Y)
Point3d.__str__ = lambda self: "{},{},{}".format(self.X, self.Y, self.Z)
Vector2d.__str__ = lambda self: "{},{}".format(self.X, self.Y)
Vector3d.__str__ = lambda self: "{},{},{}".format(self.X, self.Y, self.Z)

And the directory does not contain any such files

keithsloan@Keiths-iMac rhino3dm % ls
__init__.py         _rhino3dm.cpython-39-darwin.so
__init__.pyi            py.typed
__pycache__
jesterKing commented 2 years ago

According your logs you are using Python 3.8, but the rhino3dm module you're loading is for Python 3.9 - that will not work, you need to have the correct version installed.

The Python 3.8 version of rhino3dm for MacOS (Intel) is https://files.pythonhosted.org/packages/0e/4d/65a142a09099807df640479585467751df9f1cc26851039ef05f718e8ab6/rhino3dm-7.11.1-cp38-cp38-macosx_11_0_x86_64.whl

Note that we don't have Apple Silicon compatible builds yet.

KeithSloan commented 2 years ago

Okay (Although it says experimental) I can see what versions are available to install with pip using pip index versions rhino3dm Is there some way/where I can check which versions go with which python?

KeithSloan commented 2 years ago

I am trying to document the install requirements for my FreeCAD workbench that uses rhino3dm. FreeCAD runs on Windows, Linux, MacOS and different versions of FreeCAD use different versions of Python. It is not very satisfactory to have specific links to wheels.

I just tried installing 7.6.0 and then 0.16.0 and still have the same problem.

jesterKing commented 2 years ago

I am not sure why you are trying older builds instead of the new that I linked. 7.11.0 is current most up-to-date.

To install the rhino3dm for the correct version you'll have to use the same Python version as used if FreeCAD, in your case on MacOS that would be Python 3.8. I believe at the moment Python 3 would default to Python 3.9, so you'll have to ensure you use pip that goes with the correct Python version 3.8.

KeithSloan commented 2 years ago

I was trying older versions as I thought they might have been built with older python.

Okay I tried

python3.8 -m ensurepip --default-pip
pip install -t /Applications/FreeCAD_19.2.app/Contents/Resources/lib/python3.8/site-packages rhino3dm --upgrade --force
Collecting rhino3dm
  Using cached rhino3dm-7.7.0-cp39-cp39-macosx_10_15_x86_64.whl (3.7 MB)
Installing collected packages: rhino3dm

Still does not work.

KeithSloan commented 2 years ago

Okay I got it to work with

python3.8 -m pip install -t /Applications/FreeCAD_19.2.app/Contents/Resources/lib/python3.8/site-packages rhino3dm --upgrade --force 
Collecting rhino3dm
  Downloading rhino3dm-7.7.0-cp38-cp38-macosx_10_15_x86_64.whl (3.7 MB)
     |████████████████████████████████| 3.7 MB 5.2 MB/s 
Installing collected packages: rhino3dm
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>
distutils: /private/var/folders/cj/z259fmwd41dgzl8mq8nppwd40000gn/T/pip-target-c7__qqn1/include/python/UNKNOWN
sysconfig: /private/var/folders/cj/z259fmwd41dgzl8mq8nppwd40000gn/T/pip-target-c7__qqn1/include/python
WARNING: Additional context:
user = False
home = '/private/var/folders/cj/z259fmwd41dgzl8mq8nppwd40000gn/T/pip-target-c7__qqn1'
root = None
prefix = None
Successfully installed rhino3dm-7.7.0
WARNING: Value for scheme.headers does not match. Please report this to <https://github.com/pypa/pip/issues/9617>
distutils: /private/var/folders/cj/z259fmwd41dgzl8mq8nppwd40000gn/T/pip-target-c7__qqn1/include/python/UNKNOWN
sysconfig: /private/var/folders/cj/z259fmwd41dgzl8mq8nppwd40000gn/T/pip-target-c7__qqn1/include/python

But lots of WARNINGS

jesterKing commented 2 years ago

So this now works for you in FreeCAD on MacOS as well?

KeithSloan commented 2 years ago

Yes using the last approach.

Are the warnings okay to ignore?

jesterKing commented 2 years ago

They look like warnings from PIP, not from our code. You could report it to the link mentioned in the log.

So yes, I think it is safe to ignore these warnings from rhino3dm point of view.