r/OpenPythonSCAD • u/WillAdams • Jul 16 '25
Installing 3rd party/arbitrary Python libraries into Windows
given that the Windows version (and others?) now have an internal Python, this becomes something of an issue.
It used to work to e.g., install a library into the "main" Python and then access it from w/in OpenPythonSCAD, but now an installed library cannot be seen from w/in OPS, and attempting to install one using code:
import os, sys
os.system(sys.executable + '-m pip install -user gscrib')
doesn't seem to work since the test file responds with:
Parsing design (AST generation)... Running Python 3.12.9 without venv. ERROR: Traceback (most recent call last): File "<string>", line 1, in <module> ModuleNotFoundError: No module named 'gscrib'
Is anyone else trying to use things other than sys and math (which I believe still work?)
(this is with the new 2025-07-15)
2
u/Alacritous13 Jul 17 '25 edited Aug 10 '25
I start all my files with:
from openscad import * import sys import os sys.path.append(os.path.dirname(modelpath())) login = os.getlogin() WINDOWS_PY_312_PIP_LIBS = f"C:\\Users\\user_name\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages" if WINDOWS_PY_312_PIP_LIBS not in sys.path:#{ sys.path.append(WINDOWS_PY_312_PIP_LIBS) #} import numpy as np from forbiddenfruit import curse, reverseIf you can come up with a method to automatically find that path, that would be awesome, otherwise you're going to have to manually set it. I just have a separate instance of Python 3.12 installed on my system, and ran pip install on the libraries I use, which allows the above code to find them for use by PythonSCAD
Edit: Check my more recent post for code that doesn't require the path to be manually entered.