CadQuery / cadquery

A python parametric CAD scripting framework based on OCCT
https://cadquery.readthedocs.io
Other
2.98k stars 281 forks source link

Import CadQuery into Blender with pip #1068

Open lawrence-dubowitz opened 2 years ago

lawrence-dubowitz commented 2 years ago

How would I go about installing CadQuery into Blenders preinstalled python distribution (3.10.2) with pip?

I want to integrate CadQuery into a Blender plugin for parametric modelling with geometry nodes similar to Rhino's Grasshopper.

Thanks in advance!

jmwright commented 2 years ago

I'm not sure how it works with Blender, but in the Godot-Python plugin you use the pip binary that's bundled with the plugin and the package installs into the directory structure of the plugin. So something like /path/to/plugin/pip install cadquery Are there instructions on how to install other PyPi packages in Blender that you can link to?

This is a temporary package while we work on getting the Python wheels onto our main PyPi account, but you can try installing CadQuery with pip install cadquery2 for now.

I'm tagging @roipoussiere on this as well.

lawrence-dubowitz commented 2 years ago

thanks for the quick response!

what other dependencies do I need to install manually? Its complaining that it cant find the module OCP...

The only link I can find that refers to importing external packages can be found here: https://b3d.interplanety.org/en/installing-python-packages-with-pip-in-blender-on-windows-10/

jmwright commented 2 years ago

Doing pip install cadquery2 should have installed the ocp-vtk wheel automatically, but that install process is fairly new, so there could be a bug in this use case. You could try pip install ocp-vtk separately to see what happens.

lawrence-dubowitz commented 2 years ago

Unfortunately no luck installing ocp-vtk. I'll continue trying to get it to work and I'll post the solution if I manage to get it working.

jmwright commented 2 years ago

@lawrence-dubowitz It seems like there might be an issue with the ocp-vtk wheel in Windows 10, so it will take time to fix that. You could try creating an Anaconda environment and then launching Blender from the command line with that environment activated. I'm not sure that will work for Blender, but I used to run Godot that way in Linux.

lawrence-dubowitz commented 2 years ago

Thanks, I'll give it a try and let you know how it goes...

On Thu, Apr 28, 2022 at 12:24 PM Jeremy Wright @.***> wrote:

@lawrence-dubowitz https://github.com/lawrence-dubowitz It seems like there might be an issue with the ocp-vtk wheel in Windows 10, so it will take time to fix that. You could try creating an Anaconda environment and then launching Blender from the command line with that environment activated. I'm not sure that will work for Blender, but I used to run Godot that way in Linux.

— Reply to this email directly, view it on GitHub https://github.com/CadQuery/cadquery/issues/1068#issuecomment-1112039088, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJITN2DVJN6W5HECS5QQ3LVHJROPANCNFSM5UQF2WQQ . You are receiving this because you were mentioned.Message ID: @.***>

jmwright commented 2 years ago

@lawrence-dubowitz The following should work as a way to test (it worked for me on Windows 11 and Python 3.8), and the community is working on a permanent solution that works seamlessly with PyPi.

If Blender is running Python 3.8:

pip install https://github.com/jmwright/ocp-build-system/releases/download/7.5.3/ocp_vtk-7.5.3.0-cp38-cp38-win_amd64.whl 'git+https://github.com/CadQuery/cadquery' ezdxf multimethod nlopt nptyping typish

If Blender is running Python 3.9:

pip install https://github.com/jmwright/ocp-build-system/releases/download/7.5.3/ocp_vtk-7.5.3.0-cp39-cp39-win_amd64.whl 'git+https://github.com/CadQuery/cadquery' ezdxf multimethod nlopt nptyping typish

If Blender is running Python 3.10:

pip install https://github.com/jmwright/ocp-build-system/releases/download/7.5.3/ocp_vtk-7.5.3.0-cp310-cp310-win_amd64.whl 'git+https://github.com/CadQuery/cadquery' ezdxf multimethod nlopt nptyping typish
lawrence-dubowitz commented 2 years ago

Wonderful, thank you very much!

I will give it a try as soon as I get a chance...

On 05 May 2022 12:46:52 SAST, Jeremy Wright @.> wrote: @. The following should work as a way to test (it worked for me on Windows 11 and Python 3.8), and the community is working on a permanent solution that works seamlessly with PyPi.

If Blender is running Python 3.8:

pip install https://github.com/jmwright/ocp-build-system/releases/download/7.5.3/ocp_vtk-7.5.3.0-cp38-cp38-win_amd64.whl 'git+https://github.com/CadQuery/cadquery' ezdxf multimethod nlopt nptyping typish

If Blender is running Python 3.9:

pip install https://github.com/jmwright/ocp-build-system/releases/download/7.5.3/ocp_vtk-7.5.3.0-cp39-cp39-win_amd64.whl 'git+https://github.com/CadQuery/cadquery' ezdxf multimethod nlopt nptyping typish

If Blender is running Python 3.10:

pip install https://github.com/jmwright/ocp-build-system/releases/download/7.5.3/ocp_vtk-7.5.3.0-cp310-cp310-win_amd64.whl 'git+https://github.com/CadQuery/cadquery' ezdxf multimethod nlopt nptyping typish

-- Reply to this email directly or view it on GitHub: https://github.com/CadQuery/cadquery/issues/1068#issuecomment-1118412506 You are receiving this because you were mentioned.

Message ID: @.***>

jmwright commented 2 years ago

@lawrence-dubowitz We'll have a release on PyPi sometime in the near future, but you can now install the latest CadQuery commit via pip from the git repo. You'll need a fairly recent version of pip first.

python3 -m pip install --upgrade pip

And then you can run this line.

pip install git+https://github.com/CadQuery/cadquery.git

Let us know if this works in Blender.

lawrence-dubowitz commented 2 years ago

Unfortunately it failed with the following output when installing and trying to use in blender:

*C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\bin>python.exe

-m pip install git+https://github.com/CadQuery/cadquery.git https://github.com/CadQuery/cadquery.git*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*Collecting git+https://github.com/CadQuery/cadquery.git

https://github.com/CadQuery/cadquery.git*

Collecting cadquery-ocp

  • WARNING: Retrying (Retry(total=4, connect=None, read=None,

    redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org http://files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/e6/85/e4231752aacc17cb8f6233f4859b549cac5964c21ee8836c92c883e40504/cadquery_ocp-7.5.3-cp310-cp310-win_amd64.whl*

  • Downloading cadquery_ocp-7.5.3-cp310-cp310-win_amd64.whl (85.3 MB)*

  • |████████████████████████████████| 85.3 MB 595 kB/s*

*Requirement already satisfied: ezdxf in c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages (from cadquery==2.2.dev454+g3032e0f) (0.17.2)*

*Requirement already satisfied: multimethod in c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages (from cadquery==2.2.dev454+g3032e0f) (1.8)*

*Requirement already satisfied: nlopt in c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages (from cadquery==2.2.dev454+g3032e0f) (2.7.1)*

*Requirement already satisfied: nptyping>=2 in c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages (from cadquery==2.2.dev454+g3032e0f) (2.0.0)*

Collecting typish

  • Using cached typish-1.9.3-py3-none-any.whl (45 kB)*

Collecting casadi

  • WARNING: Retrying (Retry(total=4, connect=None, read=None,

    redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org http://files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/16/07/867767f011cd92b79da421a774fd8305fb3e69fd342b79fea990a95a9b8a/casadi-3.5.6.pre2-cp310-none-win_amd64.whl*

  • WARNING: Retrying (Retry(total=3, connect=None, read=None,

    redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='files.pythonhosted.org http://files.pythonhosted.org', port=443): Read timed out. (read timeout=15)")': /packages/16/07/867767f011cd92b79da421a774fd8305fb3e69fd342b79fea990a95a9b8a/casadi-3.5.6.pre2-cp310-none-win_amd64.whl*

  • Downloading casadi-3.5.6.pre2-cp310-none-win_amd64.whl (26.4 MB)*

  • |████████████████████████████████| 26.4 MB 409 kB/s*

Collecting path

  • Downloading path-16.4.0-py3-none-any.whl (26 kB)*

*Requirement already satisfied: numpy>=1.20.0 in c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages (from nptyping>=2->cadquery==2.2.dev454+g3032e0f) (1.21.6)*

*Requirement already satisfied: pyparsing>=2.0.1 in c:\program

files\blender foundation\blender 3.1\3.1\python\lib\site-packages (from ezdxf->cadquery==2.2.dev454+g3032e0f) (3.0.8)*

Collecting typing-extensions

  • Using cached typing_extensions-4.2.0-py3-none-any.whl (24 kB)*

Building wheels for collected packages: cadquery

  • Building wheel for cadquery (setup.py) ... done*

  • Created wheel for cadquery:

    filename=cadquery-2.2.dev454+g3032e0f-py3-none-any.whl size=139070 sha256=ce57e2d5aba9619a51837b484f4097b653d14dd304deac6f68e3c28b959024a4*

  • Stored in directory:

    C:\Users\lawre\AppData\Local\Temp\pip-ephem-wheel-cache-h1plc_2t\wheels\f6\bd\11\9f4461324b9afde1e7af02edd50dd6c7ce6613e86665b55920*

Successfully built cadquery

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*Installing collected packages: typing-extensions, typish, path, casadi,

cadquery-ocp, cadquery*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*Successfully installed cadquery-2.2.dev454+g3032e0f cadquery-ocp-7.5.3.0

casadi-3.5.6rc2 path-16.4.0 typing-extensions-4.2.0 typish-1.9.3*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: Ignoring invalid distribution -umpy (c:\program files\blender

foundation\blender 3.1\3.1\python\lib\site-packages)*

*WARNING: You are using pip version 22.0.4; however, version 22.1.1 is

available.*

*You should consider upgrading via the 'C:\Program Files\Blender

Foundation\Blender 3.1\3.1\python\bin\python.exe -m pip install --upgrade pip' command.*

Running in blender...

import cadquery as cq

RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery__init.py", line 22, in from .occ_impl import exporters File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\occ_impl\exporters\init.py", line 10, in from ...cq import Workplane File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\cq.py", line 61, in from .sketch import Sketch File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\sketch.py", line 28, in from .occ_impl.sketch_solver import ( File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\occ_impl\sketch_solver.py", line 10, in import nlopt File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\nlopt\init__.py", line 1, in from .nlopt import * File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\nlopt\nlopt.py", line 20, in from . import _nlopt ImportError: numpy.core.multiarray failed to import

On Mon, May 23, 2022 at 5:40 PM Jeremy Wright @.***> wrote:

@lawrence-dubowitz https://github.com/lawrence-dubowitz We'll have a release on PyPi sometime in the near future, but you can now install the latest CadQuery commit via pip from the git repo. You'll need a fairly recent version of pip first.

python3 -m pip install --upgrade pip

And then you can run this line.

pip install git+https://github.com/CadQuery/cadquery.git

Let us know if this works in Blender.

— Reply to this email directly, view it on GitHub https://github.com/CadQuery/cadquery/issues/1068#issuecomment-1134832771, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJITN32Y2LTWLJBMJ7RE73VLORFRANCNFSM5UQF2WQQ . You are receiving this because you were mentioned.Message ID: @.***>

jmwright commented 2 years ago

Looks like Blender may be bundling an older version of Python than we can support with the wheels at this time. What does C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\bin>python.exe show?

lawrence-dubowitz commented 2 years ago

C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\bin>python.exe Python 3.10.2 (main, Jan 27 2022, 08:34:43) [MSC v.1928 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>

On Sat, May 28, 2022 at 11:44 PM Jeremy Wright @.***> wrote:

Looks like Blender may be bundling an older version of Python than we can support with the wheels at this time. What does C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\bin>python.exe show?

— Reply to this email directly, view it on GitHub https://github.com/CadQuery/cadquery/issues/1068#issuecomment-1140333351, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJITN7WQTYZAVQY7LY6TKTVMKHTJANCNFSM5UQF2WQQ . You are receiving this because you were mentioned.Message ID: @.***>

jmwright commented 2 years ago

The installation works for me if I force pip to run with the bundled version of Python.

"C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\bin\python.exe" -m pip install git+https://github.com/CadQuery/cadquery.git

I didn't even upgrade pip since it was already at version 21, which is good enough to install our packages.

"C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\bin\python.exe" -m pip --version

There were a couple of warnings during the install, but they didn't keep CadQuery from working. I was able to do import cadquery after running python.exe to get the REPL.

jmwright commented 2 years ago

@lawrence-dubowitz Following up on the last comment. Are you running the command from cmd or PowerShell? I ran mine from cmd, and although I didn't run it in administrator mode, that might be worth a try.

I show the same Python version and platform information on my Windows system that you have, so I expect there's something minor that is still keeping this from working.

lawrence-dubowitz commented 2 years ago

Thanks, I'm still struggling to get it working with cmd (also with admin privileges), but at least I know that it's working on your side, so it must be something on my side. I will persist and update the thread once I find out what's going on.

Everything seems to be installing correctly, but I get the following error when running 'import cadquery' inside the Blender REPL:

>>> import cadquery RuntimeError: module compiled against API version 0xf but this version of numpy is 0xe Traceback (most recent call last): File "", line 1, in File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery__init.py", line 22, in from .occ_impl import exporters File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\occ_impl\exporters\init.py", line 10, in from ...cq import Workplane File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\cq.py", line 61, in from .sketch import Sketch File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\sketch.py", line 28, in from .occ_impl.sketch_solver import ( File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\cadquery\occ_impl\sketch_solver.py", line 10, in import nlopt File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\nlopt\init__.py", line 1, in from .nlopt import File "C:\Program Files\Blender Foundation\Blender 3.1\3.1\python\lib\site-packages\nlopt\nlopt.py", line 20, in from . import _nlopt ImportError: numpy.core.multiarray failed to import*

On Mon, May 30, 2022 at 2:25 PM Jeremy Wright @.***> wrote:

@lawrence-dubowitz https://github.com/lawrence-dubowitz Following up on the last comment. Are you running the command from cmd or PowerShell? I ran mine from cmd, and although I didn't run it in administrator mode, that might be worth a try.

I show the same Python version and platform information on my Windows system that you have, so I expect there's something minor that is still keeping this from working.

— Reply to this email directly, view it on GitHub https://github.com/CadQuery/cadquery/issues/1068#issuecomment-1141095706, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEJITN7FNUAQ2SFLEQCZVVTVMSXU3ANCNFSM5UQF2WQQ . You are receiving this because you were mentioned.Message ID: @.***>

jmwright commented 2 years ago

Is there anything special about your Blender installation? What's your full Blender version number? I installed it this morning on a Windows system that's never had Blender installed before. I downloaded it from here (version 3.1.2). You could start the Python REPL and try the following just to see if at least OCP is working: from OCP import *. If OCP is not installed, you can do pip.exe install cadquery-ocp.

You could also try pip.exe install numpy --upgrade but I don't know if that will break other things in your Blender install. Try at your own risk.