Using msolve API
Hi all,
I want to use msolve api in Pyhton. But, I didn't define msolve library correctly.
At first, When I tried use msolve library, I got the following error message.
I found the msolve library on this file path 'C:\Program Files\Altair\2020\hwsolvers\motionsolve\msolve' and copy to this path 'C:\Program Files\Anaconda3\Lib'. I solved this problem, but I got the new error message. You can see below.
How can I define ms_modelapi35 and run correctly msolve api ?
Thanks for the replies.
Answers
-
Did you try? C:\Users\rajivr\Desktop\lugre> python Python 2.7 (r27:82500, Apr 5 2012, 14:38:31) [MSC v.1600 64 bit (AMD64)] on win32 Type 'help', 'copyright', 'credits' or 'license' for more information. >>> from msolve import * >>> import math >>>
If this doesn't work as expected, you may need to set your environment variables.
Python uses PYTHONPATH environment variable to modules for importing. If the interpreter raises a ModuleNotFound traceback upon the command ‘from msolve import *’ then it means that the msolve module was not found. In order to ensure that ‘msolve’ is found, what you can do is to define PYTHONPATH to point to the location on your filesystem where the msolve folder (and its __init__.py) are located.
For example on my system, msolve is located in:
\p4\mbd\qa\python\msolve
In order to be able to invoke ‘from msolve import *’ or ‘import msolve’ from anywhere the interpreter is invoked, I set the PYTHONPATH environment variable to point to that location:
set PYTHONPATH= \p4\mbd\qa\python\msolve\python
If you have multiple folders containing modules that you want to import, you can set PYTHONPATH to multiple values separated by semicolons, e.g.:
set PYTHONPATH= \p4\mbd\qa\python\msolve\python;%NUSOL_DLL_DIR%
0 -
Hi Chris,
Sorry for late reply. I tried define msolve folder but I didn't solve my problem.
I defined this folder path in PYTHONPATH environment variable. But again, I faced the error message ms_modelapi35.
I found that the file '__Init__' has the extension '.pyc'. You can see above. Am I using the correct library to define the msolve library? Do I need to install another library?
0 -
Have you tried the initial tutorials for using the motionsolve Python API we have in our installation? If those do not work, I would suggest contacting Altair support. This could be related to your installation, and might be difficult to troubleshoot here.
0 -
I tried, but it didn't work. Thank you for your suggestions.
0 -
By the way, Chris.
Who is this Jenkins guy mentioned in the bad words coming from MSolve?
Is that a dir. on de development server of MSolve?
Is that Py code frozen in the Pyc files?
Interesting traces, if you ask me.
Just a stupid remark/question..
Kind regards,
Chris
0 -
Hi Chris-
I believe 'Jenkins' is just the name of one of the development servers. I'm more focused on the application side, rather than software development. The code I posted previously was from an internal email from one of our developers when someone internally was having a similar issue. I'm not a regular user of the .py methods in motionsolve (yet!!). Always learning!
0 -
Chris,
I guessed that indeed. Just looks like such a funny glitch to me.
Digging in the Py stuff around MV has become my daily activity since we (Altair + CM-Labs + Sayfield) have
made a model export from MV to Vortex.
This allows MV users you to perform a Real-Time simulation of an MV model in less than an hour. /emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />
Keep posted for more news on this side.
I also hope to expect some more news on the Python side of MV in the near future.
Kind regards,
Chris
0 -
Is the problem solved? I am also facing the same error. My installation is server based.
I am using Spyder IDE installed with anaconda. I am running it with python 3.5 interpreter.
I have setup all the environment variables mentioned on Altair website. PYTHONPATH is also defined in Spyder IDE. I am using Altair MotionSolve/View 2020.1
0 -
The MotionSolve Python API has a handful of dependencies. The first one is related to the version of the interpreter used: it is necessary to use the Python interpreter that is packaged with HyperWorks or Inspire. You cannot use an older version of Python (e.g. 2.7) or a newer version (3.10) because the msolve python API relies on a mixed Python/C++ set of libraries and the version of Python libraries linked and used during the compilation of those libraries must be the same version of the Python running the msolve API.
In order to run msolve API you need to use a command prompt that runs the correct Python version. This is generally achieved by ensuring that the correct Python folder appears as the first occurrence on your system Path.
I do that by setting this (on Windows):
set Path="C:\Program Files\Altair\2022.3\common\python\python3.8\win64";%Path%
The line above says: prepend the location of the python interpreter as the first folder the system will look to find the python.exe.
Once that is done there is another dependencies that need to be satisfied: the ImportError traceback you see tells us that msolve doesn't know where MotionSolve is installed and it cannot load one of the libraries it depends upon.
In order to let the python interpreter know all the locations it should look for when trying to resolve all the various dependencies we can use (at least) two mechanisms:
- properly define a variable called PYTHONPATH before we invoke the Python executable
- amend the Python interpreter path by appending values to the sys.path list from the REPL
So let's consider the first method: you need to set the PYTHONPATH environment variable in your system to point to (at least) two values:
1. the location of the folder that contains msolve package
2. the location of the MS binaries
On Windows we do that like this:
- open the command prompt (the one that has the correct python version from the discussion above)
- type: set PYTHONPATH=<location of the folder that contains the msolve package>;<location of the folder that contains the MS binaries>
Hope this helps you and other users that end up here.
Andrea
1 -
Andrea Pertosa_21891 said:
The MotionSolve Python API has a handful of dependencies. The first one is related to the version of the interpreter used: it is necessary to use the Python interpreter that is packaged with HyperWorks or Inspire. You cannot use an older version of Python (e.g. 2.7) or a newer version (3.10) because the msolve python API relies on a mixed Python/C++ set of libraries and the version of Python libraries linked and used during the compilation of those libraries must be the same version of the Python running the msolve API.
In order to run msolve API you need to use a command prompt that runs the correct Python version. This is generally achieved by ensuring that the correct Python folder appears as the first occurrence on your system Path.
I do that by setting this (on Windows):
set Path="C:\Program Files\Altair\2022.3\common\python\python3.8\win64";%Path%
The line above says: prepend the location of the python interpreter as the first folder the system will look to find the python.exe.
Once that is done there is another dependencies that need to be satisfied: the ImportError traceback you see tells us that msolve doesn't know where MotionSolve is installed and it cannot load one of the libraries it depends upon.
In order to let the python interpreter know all the locations it should look for when trying to resolve all the various dependencies we can use (at least) two mechanisms:
- properly define a variable called PYTHONPATH before we invoke the Python executable
- amend the Python interpreter path by appending values to the sys.path list from the REPL
So let's consider the first method: you need to set the PYTHONPATH environment variable in your system to point to (at least) two values:
1. the location of the folder that contains msolve package
2. the location of the MS binaries
On Windows we do that like this:
- open the command prompt (the one that has the correct python version from the discussion above)
- type: set PYTHONPATH=<location of the folder that contains the msolve package>;<location of the folder that contains the MS binaries>
Hope this helps you and other users that end up here.
Andrea
Hi. Thanks for the reply Andrea. Altair solved it. I forgot to update it. There was some issue setting up MS_USERSUBDLL. They gave me batch file. I have attached it.
Step-1: Download the file and rename the file extension with setup.bat
Step-2: Open the setup.bat file in text editor and change the directory in Line No. 3
Step-3: Change the python version in line no. 7
Step-4: Open the Command Prompt and drag the file into command prompt and click on enter
Step-5: Type python and click on enter (It has to show Active Python)
Step-6: Type python (Your python file path)
0