pmneila / PyMCubes

Marching cubes (and related tools) for Python
BSD 3-Clause "New" or "Revised" License
692 stars 87 forks source link

blender import error #8

Closed nortikin closed 7 years ago

nortikin commented 7 years ago

https://github.com/nortikin/sverchok/issues/1549#issuecomment-295823624 here all description can load in bash, but not in blender:

  File "/home/ololo/.config/blender/2.78/scripts/addons/sverchok/nodes/generator/script1_lite.py", line 348, in process_script
    exec(self.script_str, locals(), locals())
  File "<string>", line 16, in <module>
ImportError: No module named 'mcubes._mcubes'

PS installed as sudo pip3.5 install cython pymcubes etc...

pmneila commented 7 years ago

Hi.

Blender is bundled with its own Python distribution. It does not share libraries, modules or packages with system's Python. When you used pip to install PyMCubes, it was installed in system's Python and therefore it cannot be directly used in Blender.

There are two possible solutions:

  1. Add the folder where PyMCubes is installed to Blender's sys.path. You can get the folder where mcubes is running this in a terminal:
    $ python -c "import mcubes; print(mcubes.__file__)"
    /home/username/anaconda3/lib/python3.5/site-packages/mcubes/__init__.py

    In this case, the path with the mcubes folder is /home/username/anaconda3/lib/python3.5/site-packages/ (your path might be different). You should append this path to the Blender Python sys.path. In your Blender script, write something like

    
    import sys
    sys.path.append("/home/username/anaconda3/lib/python3.5/site-packages") # Change this to your path
    import mcubes

The rest of your script...


Note that this is a workaround, it might not work if the system Python and the Blender Python have different versions, and it should not be used in any production environment. Use this only if it is for personal use.

2. Install PyMCubes directly in Blender's Python distribution. As far as I know, installing external packages with compilable C++ code is not officially supported in Blender, although you can do it manually. I do not recommend this.
pmneila commented 7 years ago

I've just found that you already did what I said.

I've seen that your Blender version is blender-2.78-linux-glibc211-i686. This is a 32-bit build. However, your system Python is 64-bit. The library you compiled is _mcubes.cpython-35m-x86_64-linux-gnu.so (note the x86_64). Those two versions are incompatible: you cannot load a 64-bit library in a 32-bit environment.

Change your Blender version to a 64-bit build (one with x86_64 in the name instead of i686). It should work then.

nortikin commented 7 years ago

Omg. Thank you!

pmneila commented 7 years ago

@nortikin You're welcome. :)

Let me know if it worked so I can close the issue.

nortikin commented 7 years ago

thanks, i found two things lost - system path $PYTHONPATH was not exported as my system site-packages folder for python in /usr/lib/python3.5 also your suggestion for 64 bit works. Thanks!!!!

BJMayer commented 4 years ago

Hi, I am having the same problem as @nortikin my blender and python are 64bits but I receive the same message error, how can I fix? @pmneila thank you in advance!