Run python script on Windows terminal

Hi,
I would like to run a Cubit python script without opening the graphical interface.
Here the code :

import numpy as np
import sys
sys.path.append(r'C:\Program Files\Coreform Cubit 2023.11\bin')
import cubit
cubit.init(['cubit','-nojournal'])

But I have the follow error:

Traceback (most recent call last): File “C:\Users\RoccoMORETTI\OneDrive - NAAREA\Documents\Projets\CouplageCFDNeutro\Circuit RCE\CircuitRCE6_CFD_manual_BLext_coin_pipe.py”, line 13, in import cubit File “C:\Program Files\Coreform Cubit 2023.11\bin\cubit.py”, line 44, in from cubit3 import * File “C:\Program Files\Coreform Cubit 2023.11\bin\cubit3.py”, line 12, in import _cubit3 ImportError: DLL load failed while importing _cubit3: %1 is not a valid Win32 application.

Is it possible do it ?
Thanks.
Best regards,

Rocco

Hi Rocco,

With this latest version we had to separate out the geometry engine to get translators to work properly. This requires an additional path.

Add the following before the import cubit statement.

sys.path.append(r'C:\Program Files\Coreform Cubit 2023.11\bin\acis\code\bin')

Karl

P.S. You can contact me directly at karl@coremesh.co

Hi Karl,

I tried it but I have the same error.
Glad to work with you again. :slight_smile:

Rocco

Here is what I did.

import sys
import numpy

sys.path.append(r'C:\Program Files\Coreform Cubit 2023.11\bin')
sys.path.append(r'C:\Program Files\Coreform Cubit 2023.11\bin\acis\code\bin')
import cubit
cubit.init(['cubit','-nojournal'])
cubit.cmd("brick x 10")
cubit.cmd("exit")

Does that fail for you as well?

Karl

Yes! Here the complete output :
PS C:\Users\RoccoMORETTI\OneDrive - NAAREA\Documents\Projets\CouplageCFDNeutro\Circuit RCE> python
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:21:31) [MSC v.1936 32 bit (Intel)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.
>>> import sys
>>> import numpy
>>>
>>> sys.path.append(r’C:\Program Files\Coreform Cubit 2023.11\bin’)
>>> sys.path.append(r’C:\Program Files\Coreform Cubit 2023.11\bin\acis\code\bin’)
>>> import cubit
Traceback (most recent call last):
File “”, line 1, in
File “C:\Program Files\Coreform Cubit 2023.11\bin\cubit.py”, line 44, in
from cubit3 import *
File “C:\Program Files\Coreform Cubit 2023.11\bin\cubit3.py”, line 12, in
import _cubit3
ImportError: DLL load failed while importing _cubit3: %1 is not a valid Win32 application.
>>> cubit.init([‘cubit’,’-nojournal’])
Traceback (most recent call last):
File “”, line 1, in

My setup should be similar to yours. I’m running Windows 11 and python 3.12 instead of 3.11.5 but that shouldn’t matter. This is a pretty new machine. I don’t have any development tools or cubit path settings.

I’ve tested both powershell and command shell with no admin privileges. It works on both for me.

You might try running with admin privileges in case there is something different with your installation, but that seems like a very bad guess.

Karl

Hi Karl,

do you have python 3.12 32bit or 64bit ?

Rocco

Hi Rocco,

I am running 3.12 64 bit on my machine. Here is the version info.

Python 3.12.0 (tags/v3.12.0:0fb18b0, Oct  2 2023, 13:03:39) [MSC v.1935 64 bit (AMD64)] on win32

Karl

Hi Karl,
I installed python 3.12.1 and now it works.
Thanks,

Rocco

That is a little troubling to me. We made changes so that Cubit was python version agnostic. This bears more investigation on our part.

Thanks,
Karl