compas icon indicating copy to clipboard operation
compas copied to clipboard

Can't use compas in blender 2.92

Open tetov opened this issue 3 years ago • 20 comments

>>> import compas

Works fine.

>>> import compas_blender
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\compas_blender\__init__.py", line 22, in <module>
    from .utilities import *  # noqa: F401 F403
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\compas_blender\utilities\__init__.py", line 81, in <module>
    from .drawing import (
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\compas_blender\utilities\drawing.py", line 7, in <module>
    from compas.geometry import centroid_points
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\compas\geometry\__init__.py", line 635, in <module>
    from .transformations import (
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\compas\geometry\transformations\__init__.py", line 18, in <module>
    from .transformations_numpy import *  # noqa: F401 F403
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\compas\geometry\transformations\transformations_numpy.py", line 5, in <module>
    from numpy import asarray
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\numpy\__init__.py", line 143, in <module>
    from . import lib
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\numpy\lib\__init__.py", line 45, in <module>
    __all__ += type_check.__all__
NameError: name 'type_check' is not defined

Doesn't, because:

>>> import numpy
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\numpy\__init__.py", line 143, in <module>
    from . import lib
  File "C:\Users\a\scoop\apps\blender\current\2.92\python\lib\site-packages\numpy\lib\__init__.py", line 45, in <module>
    __all__ += type_check.__all__
NameError: name 'type_check' is not defined

Context

Windows==10
Python==3.7
compas==1.2.1

tetov avatar Mar 19 '21 16:03 tetov

I'll try to look into this a bit.

tetov avatar Mar 19 '21 17:03 tetov

In numpy/lib/__init__.py there's references to modules that were imported from using star import.

from .foo import *

__all__ = [foo.__all__]

I found some mentions of this quirk.

Adding "non-star" imports fixes this. E.g:

from .foo import *
from . import foo

__all__ = [foo.__all__]

After I added imports for all modules I could run the hello-world program in Getting Started - Blender.

from numpy.lib import (type_check,
                       index_tricks,
                       function_base,
                       nanfunctions,
                       shape_base,
                       stride_tricks,
                       twodim_base,
                       ufunclike,
                       histograms,
                       polynomial,
                       utils,
                       arraysetops,
                       npyio,
                       financial,
                       arraypad)
                       
import compas
import compas_blender
from compas.datastructures import Mesh
from compas_blender.artists import MeshArtist

compas_blender.clear()

mesh = Mesh.from_ply(compas.get('bunny.ply'))

artist = MeshArtist(mesh)
artist.draw_mesh()

image

I hope we can find a more elegant solution..

tetov avatar Mar 21 '21 16:03 tetov

In numpy/lib/__init__.py there's references to modules that were imported from using star import.

maybe just stating the obvious, but these imports haven't changed recently on numpy's side. And this also worked on Blender 2.91, so, I'm lost as to what could have changed that causes this.

gonzalocasas avatar Mar 22 '21 10:03 gonzalocasas

Yeah, they've been there for quite some time..

Just tried this with 2.91.0 and 2.91.2 and got the same error.

@brgcode Was this the problem you had with >=2.90? or was it something else?

tetov avatar Mar 22 '21 10:03 tetov

for me only 2.83 ever worked. and it still does btw.

the error for >=2.90 was not related to numpy in my case. i can check again in the afternoon...

tomvanmele avatar Mar 22 '21 10:03 tomvanmele

but i agree with @gonzalocasas that this doesn't look like a problem with COMPAS...

tomvanmele avatar Mar 22 '21 10:03 tomvanmele

have you tried importing numpy before switching to the COMPAS install? is there a difference between numpy versions before and after?

tomvanmele avatar Mar 22 '21 10:03 tomvanmele

just for the record, on a clean (as per our docs) install of blender 2.91.2 with compas 1.1.0, the example posted works:

image

However, I did notice just now that the console lists heaps of errors during start up, but I could not capture them, they start with a complaint about multiprocessing potentially not working. I'll try to get to that log and post here.

gonzalocasas avatar Mar 22 '21 10:03 gonzalocasas

correction: not entirely clean, I also installed Sverchok on it.

Here's the system console log, the messages don't sound very alarming:

Read prefs: C:\Users\gcasas\AppData\Roaming\Blender Foundation\Blender\2.91\config\userpref.blend
found bundled python: C:\Program Files\Blender Foundation\Blender 2.91\2.91\python
Unable to find the python binary, the multiprocessing module may not be functional!
sv: import settings
geomdl package is not available, some NURBS related nodes will not be available
SciKit-Image package is not available; SciKit-based implementation of Marching Cubes and Marching Squares will not be available
PyMCubes package is not available. PyMCubes-based implementation of Marching Cubes will not be available
Circlify package is not available. Circlify node will not be available
FreeCAD package is not available, Solids nodes will not be available
Dependencies available: pip, scipy, Cython.
C:\Users\gcasas\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\sverchok-master\settings.py:16: RuntimeWarning: Use 'sys.executable' instead of 'binary_path_python'!
  PYPATH = bpy.app.binary_path_python
sv: import all modules
C:\Users\gcasas\AppData\Roaming\Blender Foundation\Blender\2.91\scripts\addons\sverchok-master\settings.py:16: RuntimeWarning: Use 'sys.executable' instead of 'binary_path_python'!
  PYPATH = bpy.app.binary_path_python
sv: append app.handlers
sv: enable internal debug logging.
2021-03-22 11:21:04,332 [INFO] logging: log level, 20
 ______ _    _ _______  ______ _______ _     _  _____  _     _
/______  \  /  |______ |_____/ |       |_____| |     | |____/
______/   \/   |______ |    \_ |_____  |     | |_____| |    \_
initialized.

sv: version: 0.6.0.0

gonzalocasas avatar Mar 22 '21 10:03 gonzalocasas

i am testing this on mac btw. could also make a difference...

tomvanmele avatar Mar 22 '21 10:03 tomvanmele

I did a clean install of 2.92 (using official installer, removed Blender prefs from %APPDATA% and cleaned conda cache) and I get the same error. I'll try 2.91.2 next. Maybe there should be a note about "officially" supported blender version?

Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "C:\Program Files\Blender Foundation\Blender 2.92\2.92\python\lib\site-packages\numpy\__init__.py", line 143, in <module>
    from . import lib
  File "C:\Program Files\Blender Foundation\Blender 2.92\2.92\python\lib\site-packages\numpy\lib\__init__.py", line 45, in <module>
    __all__ += type_check.__all__
NameError: name 'type_check' is not defined

tetov avatar Mar 22 '21 10:03 tetov

I did a clean install of 2.92 (using official installer, removed Blender prefs from %APPDATA% and cleaned conda cache) and I get the same error. I'll try 2.91.2 next. Maybe there should be a note about "officially" supported blender version?

i agree. think it should be 2.83 because that is the current LTS version...

tomvanmele avatar Mar 22 '21 10:03 tomvanmele

just for the record, on a clean (as per our docs) install of blender 2.91.2 with compas 1.1.0, the example posted works:

image removed for readability

However, I did notice just now that the console lists heaps of errors during start up, but I could not capture them, they start with a complaint about multiprocessing potentially not working. I'll try to get to that log and post here.

I was able to reproduce this setup.

  • blender 2.91.2
  • compas 1.1.0
  • python 3.7.10

but only after downgrading numpy: 1.19.2-py37he804e03_1 --> 1.17.5-py37hd20adf4_1 like you did for Sverchok. Otherwise I got same error as described in start of this issue.

tetov avatar Mar 24 '21 07:03 tetov

ok, so, basically if you pin the numpy version to the same one that blender ships with, things work?

gonzalocasas avatar Mar 24 '21 07:03 gonzalocasas

Seems like it. I'm in the process of testing this finding in my other installations.

tetov avatar Mar 24 '21 08:03 tetov

would be cool if that consistently works. however, somehow a bit annoying that one needs to make a separate install for blender because of the restrictions. or perhaps it is a good thing to sandbox that install in a separate environment anyway...

should we modify the install instructions to add a specific version of numpy to the conda environment? or do we do this on the fly as part of the installation process? with a warning...

tomvanmele avatar Mar 24 '21 08:03 tomvanmele

I think an environment that is built specifically for blender makes sense, we could prepare a couple of environment.yml files, one for each version of Blender that we support, it's not a lot of work and we'd get into a more consistent situation for sure.

gonzalocasas avatar Mar 24 '21 08:03 gonzalocasas

image

And here's a working setup for latest compas and latest Blender.

  • Blender 2.92
  • compas 1.2.1
  • numpy 1.17.5
  • python 3.7.10

tetov avatar Mar 24 '21 09:03 tetov

I think an environment that is built specifically for blender makes sense, we could prepare a couple of environment.yml files, one for each version of Blender that we support, it's not a lot of work and we'd get into a more consistent situation for sure.

i can make a section in the docs with "predefined installs" or something like that...

tomvanmele avatar Mar 24 '21 09:03 tomvanmele

@tetov although the currently documented process of install for Blender is problematic, we've found that doing a pip install using Blender's python seems to work properly most of the times for versions before Blender 3.1 (support for 3.1 will come in a while).

In a nutshell, the process that works for me always as of today is:

$ cd BLENDER_FOLDER/3.0/python/bin
$ python -m pip install compas

gonzalocasas avatar Mar 28 '22 09:03 gonzalocasas

@tetov since Blender has advanced so significantly, would you be willing to consider updating whether this still is an issue? Blender is in such great shape that this issue still feels relevant.

jf--- avatar Apr 08 '24 18:04 jf---

the current instructions for using compas with Blender are here, and work very well afaik...

https://compas.dev/compas/latest/userguide/cad.blender.html

tomvanmele avatar Apr 08 '24 20:04 tomvanmele

@tomvanmele every time i see python + blender it just seems so shiny...

but since the release discussed and the current version are so vastly different + the encouraging message above -- 🔒 plz

jf--- avatar Apr 08 '24 21:04 jf---