Install numpy so openpythonscad can see it?

7 views
Skip to first unread message

William Adams

unread,
Nov 16, 2025, 9:32:19 AM (12 days ago) Nov 16
to PythonSCAD
Added:

    import numpy as np

but got:

      File "<string>", line 3, in <module>
      ModuleNotFoundError: No module named 'numpy'

even after:

Screenshot 2025-11-16 092412.png

What is the magic incantation to get this working?

    print(sys.path)

yields:

    Running Python 3.12.9 without venv.

      ['C:\\Program Files\\libraries\\python',      'C:\\Users\\willa\\OneDrive\\Documents\\PythonSCAD\\libraries', 'C:\\Users\\willa\\OneDrive\\Documents\\OpenSCAD\\libraries', 'C:\\Users\\willa\\OneDrive\\Desktop\\Clutter', 'C:\\Users\\willa\\OneDrive\\Desktop', 'C:\\Program Files\\PythonSCAD\\python312.zip', 'C:\\Users\\willa\\AppData\\Local\\Programs\\Python\\Python312\\Lib', 'C:\\Users\\willa\\AppData\\Local\\Programs\\Python\\Python312\\DLLs', 'C:\\Program Files\\PythonSCAD', 'C:\\Program Files\\PythonSCAD\\Lib']

Apparently I need to add:

    c:\users\willa\appdata\local\programs\python\python312\lib\site-packages (2.2.3)

Ran the pip upgrade command, but still no go.....

so, I guess I'm going to be calculating the 3-dimensional length of a vector manually....

William



William Adams

unread,
Nov 16, 2025, 9:36:11 AM (12 days ago) Nov 16
to PythonSCAD
Actually, since math is already working, the calculation I needed was as simple as:

    distance = math.dist([self.xpos(), self.ypos(), self.zpos()], [ex, ey, ez])

William

Guenther Sohler

unread,
Nov 16, 2025, 10:05:49 AM (12 days ago) Nov 16
to William Adams, PythonSCAD
Did you try PythonSCAD's Virtual Env ?

1) create empty folder, label it somehow like virtual environment.
2) Use File->Python->Create Virtual Envirtonment
3) In dos box call <your-folder/bin/activate
4) install numpy from within this shell
5) back in pythonscad use File->Python->Select Virtual environment
6) Now you should be set to go


--
You received this message because you are subscribed to the Google Groups "PythonSCAD" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pythonscad+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/pythonscad/af8da152-3326-4bcc-9f2f-8965d75bbab9n%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

W W

unread,
Nov 16, 2025, 11:37:07 PM (12 days ago) Nov 16
to PythonSCAD
/1/ I can sadly confirm the sys.path "trick" I wrote up here (https://www.reddit.com/r/OpenPythonSCAD/comments/1ijhpy5/what_do_i_need_to_do_to_import_python_modules/mbjdykm/) no longer works. 

I am getting this stack trace on import now:

```

sys.path ['C:\\Program Files\\libraries\\python', 'C:\\Users\\willy\\Documents\\PythonSCAD\\libraries', 'C:\\Users\\willy\\Documents\\OpenSCAD\\libraries', 'C:\\Users\\willy\\workspace\\prog-splitz\\openscad\\bug_fixes\\divmatrix', 'C:\\Program Files\\PythonSCAD\\python312.zip', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\Lib', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\DLLs', 'C:\\Program Files\\PythonSCAD', 'C:\\Program Files\\PythonSCAD\\Lib', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages']

ERROR: Traceback (most recent call last):

File "<string>", line 16, in <module>

File "C:\Users\willy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\__init__.py", line 132, in <module>

from . import _core

File "C:\Users\willy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\_core\__init__.py", line 99, in <module>

from . import (

File "C:\Users\willy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\_core\_internal.py", line 19, in <module>

import ctypes

File "ctypes\__init__.py", line 157, in <module>

AttributeError: class must define a '_type_' attribute

```

/2/ I just tried the new Virtual Environment support. Several problems:

/a/ Doing "File->Python->Create Virtual Envirtonment" fails with an error dialog.

11.png

/b/ I went to cmd and tried the whole setup chain of:
- Creating the venv `python -m vent my_venv_name`, 
- Activating it `my_venv_name\Scripts\activate`, 
- pip install numpy under the venv `pip install numpy`

Now, if I launch pythonscad and do File -> Python -> Select Virtual Environment, it will do a pop up dialog saying restart PythonScad. Once I restart, numpy will still fail to load, but with a diff stack trace:

```

sys.path ['C:\\Program Files\\libraries\\python', 'C:\\Users\\willy\\Documents\\PythonSCAD\\libraries', 'C:\\Users\\willy\\Documents\\OpenSCAD\\libraries', 'C:\\Users\\willy\\workspace\\prog-splitz\\openscad\\bug_fixes\\divmatrix', 'C:\\Program Files\\PythonSCAD\\python312.zip', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\Lib', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\DLLs', 'C:\\Program Files\\PythonSCAD', 'C:\\Program Files\\PythonSCAD\\Lib']


ERROR: Traceback (most recent call last):

File "<string>", line 16, in <module>

ModuleNotFoundError: No module named 'numpy'

```

I manually confirmed in the venv folder, pip install did indeed work:

22.png


@gsohler were you able to have this working on a Windows install? 

Guenther Sohler

unread,
Nov 17, 2025, 2:39:09 PM (11 days ago) Nov 17
to W W, PythonSCAD
Hi,

if the sys.path trick no longer works in windows, it very likely mismatched python versions between pythonscad and windows.

Recent Versions of PythonSCAD use Python Embeddable package 3.12.9  and Version for r windows should be the same.
I just uninstalled my old python 3.11 and installed 3.12.9, it works at least for me:


If it does not work for you, maybe bisect is another option. Do you still have the valid list of installers ?

And I need to admit: My procedure with the virtualenv works very well in linux, but also fails with the same error in windows.
(I should probably work on that soon)

And as for manual setup of the virtual environment ... i still believe its due to a version mismatch between windows and pythonscad.

IF that's the case, I just have to rectify the GUI procedure.

let me know ...










W W

unread,
Nov 18, 2025, 12:31:19 AM (11 days ago) Nov 18
to Guenther Sohler, PythonSCAD
> Recent Versions of PythonSCAD use Python Embeddable package 3.12.9  and Version for r windows should be the same. I just uninstalled my old python 3.11 and installed 3.12.9, it works at least for me

I used windows installer from https://www.python.org/downloads/release/python-3129/ . I could try the Windows embeddable package 64 bit when time permits. I suppose it comes with pip too?

You received this message because you are subscribed to a topic in the Google Groups "PythonSCAD" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pythonscad/_ZzvEmW_8TM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pythonscad+...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/pythonscad/CAASeUHqJMqUb%3D7cMvSyXZK5SatXc8v8DDax37K9U_moPUOW%3DvQ%40mail.gmail.com.

Guenther Sohler

unread,
Nov 18, 2025, 1:44:41 AM (11 days ago) Nov 18
to W W, PythonSCAD
Sorry, you misunderstood me apparently.
PythonSCAD does use Python embeddable  3.12.9.
But It matches Windows Python (WITHOUT embeddable ) 3.12.9.

This does have PIP, just make sure that you enable adding it to the path during installing.
Hope this helps.
Right now I am debugging the Virtual Environment for Windows. Hopefully i can spot the error soon



W W

unread,
Nov 27, 2025, 12:02:11 PM (yesterday) Nov 27
to PythonSCAD
Hey Guenther,

What does it say up top if you ran your Windows installed Python 3.12.9 version?

I am using site-packages from a Python 3.12.9 install.

To be specific, this is the detailed version number I am using. I already fetched numpy from pip in the Windows Python 3.12.9 version:

```
Python 3.12.9 (tags/v3.12.9:fdb8142, Feb  4 2025, 15:27:58) [MSC v.1942 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> import numpy as np
>>> np.matrix
<class 'numpy.matrix'>
```

Within Pythonscad, if I do this bit:

```py
import sys, os

def sys_path_site_pkg():
    '''
    Make pip installs from OS level python accessible to PythonScad. Requires matching version (3.12.9)
    '''
    SITE_PKG = rf"C:\Users\{os.getlogin()}\AppData\Local\Programs\Python\Python312\Lib\site-packages"
   
    if SITE_PKG not in sys.path:
        sys.path.append(SITE_PKG)
       

sys_path_site_pkg()
print('sys.path', sys.path)

import numpy as np
```

This would be the stdout in PythonScad after hitting F5:

```

Parsing design (AST generation)...

Running Python 3.12.9 without venv.

sys.path ['C:\\Program Files\\libraries\\python', 'C:\\Users\\willy\\Documents\\PythonSCAD\\libraries', 'C:\\Users\\willy\\Documents\\OpenSCAD\\libraries', 'C:\\Users\\willy\\workspace\\prog-splitz\\openscad\\bug_fixes\\divmatrix', 'C:\\Program Files\\PythonSCAD\\python312.zip', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\Lib', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\DLLs', 'C:\\Program Files\\PythonSCAD', 'C:\\Program Files\\PythonSCAD\\Lib', 'C:\\Users\\willy\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages']


ERROR: Traceback (most recent call last):

File "<string>", line 16, in <module>

File "C:\Users\willy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\__init__.py", line 125, in <module>

from numpy.__config__ import show_config

File "C:\Users\willy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\__config__.py", line 4, in <module>

from numpy._core._multiarray_umath import (

File "C:\Users\willy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\_core\__init__.py", line 99, in <module>

from . import (

File "C:\Users\willy\AppData\Local\Programs\Python\Python312\Lib\site-packages\numpy\_core\_internal.py", line 19, in <module>

import ctypes

File "ctypes\__init__.py", line 157, in <module>

AttributeError: class must define a '_type_' attribute

```

It is able to "load" numpy, just that there seem to be some collision on the Python type for "ctypes"? 

Is there a ctypes in PythonScad?

I am also extremely curious why you didn't run into the same thing :D 

-W

W W

unread,
Nov 27, 2025, 12:22:36 PM (yesterday) Nov 27
to PythonSCAD
Found the culprit.

This works now, after explicitly removing two folders PythonScad added to sys.path on my behalf? I bolded the line diff compare to my last post.

It got rid of the ctypes.py conflict between numpy and the "built in" from  AppData\Local\Programs\Python\Python312.

@gsohler: Were  AppData\Local\Programs\Python\Python312\Lib and  AppData\Local\Programs\Python\Python312\DLLs added deliberately by you? Or, does PythonScad does a sys.path inheritance (which means, it must have been added by the Windows installation of Python 3.12.9!!!)

```py
import sys, os

def sys_path_site_pkg():
    '''
    Make pip installs from OS level python accessible to PythonScad. Requires matching version (3.12.9)
    '''
    SITE_PKG = rf"C:\Users\{os.getlogin()}\AppData\Local\Programs\Python\Python312\Lib\site-packages"
   
    if SITE_PKG not in sys.path:
        sys.path.append(SITE_PKG)
       
    # Unwind some default folder adds by PythonScad that seem to conflict!!
    # Specifically: ctypes.
    unwinds = set([
        rf"C:\Users\{os.getlogin()}\AppData\Local\Programs\Python\Python312\Lib",
        rf"C:\Users\{os.getlogin()}\AppData\Local\Programs\Python\Python312\DLLs"
    ])
   
    sys.path = [path for path in sys.path if path not in unwinds]

       

sys_path_site_pkg()
print('sys.path', sys.path)

import numpy as np
```

Guenther Sohler

unread,
Nov 27, 2025, 4:23:10 PM (23 hours ago) Nov 27
to W W, PythonSCAD
Hii Willy,

Glad you found the issue

Nope, I don't explicitly add those paths, but i put many ...


.. But I like the python syntax to filter pathes...

But yes, it looks like a conflict. 
With the windows python embedded python package, pythonscad should run even without windows installed python theoretically.

However, you would not want that because its minimalistic and probably won;t support fancy stuff like ctypes

ctypes are cool, i am wondering how it interacts with pythonscad in your place.



Reply all
Reply to author
Forward
0 new messages