java.lang.NoClassDefFoundError with JModelica2.14 - python-2.7

I am new to the Modelica world and installed JModelica2.14 on win10 via the binary file provided from the offical webpage. From the console I call setenv.bat, start the 64bit python envrionment and import '.\install\Python_64'. However, running the example files already throws an error. The minimal code example throwing the error is provided below. I assume that the binaries do not have a bug without anyone mentioning it. It would be great if someone could give a hint about what I am missing. Thanks a lot!
import modelicacasadi_wrapper
modelicacasadi_wrapper.OptimicaOptionsWrapper()
RuntimeError Traceback (most recent call last)
<ipython-input-11-ce2bcdfa3f06> in <module>()
----> 1 modelicacasadi_wrapper.OptimicaOptionsWrapper()
C:\JModelica.org-2.14\install\Python_64\modelicacasadi_wrapper\modelicacasadi_wrapper.pyc in __init__(self, *args)
3472 __init__(ModelicaCasADi::OptimicaOptionsWrapper self, OptimicaOptionsWrapper other) -> OptimicaOptionsWrapper
3473 """
-> 3474 this = _modelicacasadi_wrapper.new_OptimicaOptionsWrapper(*args)
3475 try:
3476 self.this.append(this)
RuntimeError: java.lang.NoClassDefFoundError org/jmodelica/optimica/compiler/ModelicaCompiler
Caused by: java.lang.ClassNotFoundException: org.jmodelica.optimica.compiler.ModelicaCompiler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
This function is only given in binary format compiled from c++ code. therefore, I can not change the function without recompiling the library (I already tried). To me it seems like the org.jmodelica.optimica.compiler.ModelicaCompiler should have been a org.jmodelica.optimica.compiler.OptimicaCompiler. This would mean that I have to install the package from source and I haven't been sucessful with that yet.

I still use JModelica 2.14 in Python 2 and then have installed virtual environment with Conda to create a Python 3 environment where I then run the FMUs with the latest PyFMI package in Python 3.10 and Jupyter notebook. It all works very fine, but as Imke Kreuger indicated you have MSL 3.2.2 build 3 and there has been development in the Modelica Standard Library since then.
During installation you are asked whether you want "Graybox OPC Automation wrapper" and I usually say "NO" there. You may have said "YES" though, right? See Chapter 2.2.1 in the User guide.
The JModelica installation actually provide you with two different compilers.
One is for standard Modelica brings as output an FMU of CS or ME type. The other compiler is for Modelica extended with Optimica and does not bring any FMU and you are bound to work in Python 2.
Tried to reproduce your error (with my installation without the "Graybox OPC..."). If I (in the Python 2 environment) literally do the two commands, I get "Press any key to continue...." and when I press key the IPython window collapse.
However if you skip the two brackets at the end of the second command, then it is accepted!
If you write a question mark at the end you get information about what arguments you should have.
If you describe better what you want to do, we likely can help you better.
Note, it seems you want to use Optimica and that is an extension of Modelica that is only partially supported by OpenModelica, what I understand. The Optimica extension is well integrated in JModelica and originated in this context. For "ordinary" Modelica use I do not think you need to use this wrapper.

Related

No module named 'numpy.core._multiarray_umath'

I am trying to use matploitlib_cpp on Windows 11 with Numpy 1.24.2 and Python 3.11, but I keep running in to the following error.
Original error was: No module named 'numpy.core._multiarray_umath'
I know this has been posted at a million different places on the internet and I have tried following all the guides that says reinstalling numpy and whatever, it does not work for me. What I can see in my path ..\Python3.11\Lib\site-packages\numpy\core is that I have a file named _multiarray_umath.cp311-win_amd64.pyd but no file named _multiarray_umath. I also tried to use a virtual environement from Anaconda but I am not sure how to build matploitlib_cpp against such virtual enviornment.
I got it working by using the release binaries instead of debug binaries.

Pabot - Unable to run parallel robotframework tests

So, I'm working on a robotframework test project, and the goal is to run several test suites in parallel. For this purpose, pabot was chosen as the solution. I am trying to implement it, but with little success.
My issue is: after installing Pabot (which, I might say, I did by cloning the project and running "setup.py install", instead of using pip, since the corporate proxy I'm behind has proven an obstacle I can't overcome), I created a new directory in the project tree, moved some suites there, and ran:
pabot --processes 2 --outputdir pabot_results Login*.robot
Doing so results in the following error message:
2018-10-10 10:27:30.449000 [PID:9676] [0] EXECUTING Suites.LoginAdmin
2018-10-10 10:27:30.449000 PID:400 EXECUTING Suites.LoginUser
2018-10-10 10:27:30.777000 PID:400 FAILED Suites.LoginUser
2018-10-10 10:27:30.777000 [PID:9676] [0] FAILED Suites.LoginAdmin
WARN: No output files in "pabot_results\pabot_results"
Output:
[ ERROR ] Reading XML source '' failed: invalid mode ('rb') or filename
Try --help for usage information.
Elapsed time: 0 minutes 0.578 seconds
Upon inspecting the stderr file that was generated, I have this message:
Traceback (most recent call last):
File "C:\Python27\Lib\site-packages\robotframework-3.1a2.dev1-py2.7.egg\robot\running\runner.py", line 22, in
from .context import EXECUTION_CONTEXTS
ValueError: Attempted relative import in non-package
Apparently, this has to do with something from the runner.py script, which, if I'm not mistaken, came with the installation of robotframework. Since manually modifying that script does not seem to me the optimal solution, my question is, what am I missing here? Did I forget to do anything while setting this up? Or is this an issue of compatibility between versions?
This project is using Maven as the tool to manage dependencies. The version I am running is 3.5.4. I am using a Windows 10, 64bit system; I have Python 2.7.14, and Robot Framework 3.1a2.dev1. The Pabot version is 0.44. Obviously, I added C:\Python27 and C:\Python27\Scripts to the PATH environment variable.
Edit: I am also using robotframework-maven-plugin version 1.4.0.8, if that happens to be relevant.
Edit 2: added the error messages in text format.
I believe I've come across an issue similar when setting up parallel execution on my machine. Firstly I would confirm that pabot is installed using pip show robotframework-pabot.
Then you should define the directory your results are going to using -d.
I then modified the name of the -o to Output.xml to make it easy to identify.
This is a copy of the code I use. Runs optimally with 8 processes
pabot --processes 8 -d results -o Output.xml Tests
Seems that you stumbled on a bug in the prerelease version of robot framework (3.1a2.dev1).
Please install a release version of robot framework. For example 3.0.4.
Just in case anyone happens to stumble upon this issue in the future:
Since I can't use pip, and I tried a good deal of workarounds that eventually made things more unstable, I ended up saving my project and removing everything Python-related from my system, so as to allow me to install everything from scratch. In a Windows 10, 64bit system, I used:
Python 2.7.14
wxPython 2.8.12.1, win64, unicode, for py27
setuptools 40.2.0 (to allow me to use the easy_install command)
Robot Framework 3.0.4
robotremoteserver 1.1
Selenium2Library 3.0.0
and Pabot version 0.45.
I might add that, when installing the Selenium2Library the way I described above, it eventually tries to download some things from the pip repositories - which, if you have a proxy, will cause you trouble. I solved this problem by browsing https://pypi.org/simple/selenium/, manually downloading the 2.53.6 .tar.gz file, then extracting it and running setup.py install on the command line.
PS: Ideally, though, anyone should be able to use proxy settings from the command line (--proxy http://user:password#server:port) to get pip and then use it; however, for some reason, probably related to network security configurations that I didn't want to lose time with, this didn't work in my case.

Using pyinstaller on parmap causes a tkinter matplotlib import error. Why?

Update
If I try downgrading from Pyinstaller 3.2 to 3.1 I instead get the following traceback when I try to run the executable.
I tried adding --hidden-import=collect_submodules('pkg_resources._vendor') to pyinstaller as noted here but it had no effect. Same error. This appears to be due to an issue with setuptools. I'm using 26.0.0. Downgrading to 19.3 that many sources say fixes the issue does indeed fix this issue but then I'm back to the issue I have below.
I have a python 2.7 pyqt4 project I'm trying to turn into an .exe using pyinstaller. I use:
pyinstaller --additional-hooks-rir=. --clean --win-private-assemblies pipegui.py
pipegui.py can be found on github here
I get a working executable and the app appears functional. Here is what the terminal spits while pyinstaller is freezing. However the app crashes when I run particular parts of my program. It crashes and the terminal goes in a loop continually outputting the same traceback below with "Poolworker-X" at the very top continually incrementing:
As you can see tkinter is implicated, despite the word "tkinter" appearing nowhere in my project (using pyqt4). I am making use of matplotlib though and from answers discussed here and here I have added the following to the top of pipegui.py my main script:
from Tkinter import *
import Tkinter
import FileDialog
This however seems to be a step in the wrong direction because after freezing with this (and the same flags as before) my executable wont even open and instead I get this:
Here is pyinstaller's pretty-much identical output while freezeing. Remember all I did was add those 3 import statements above. That's it.
I also tried pyinstaller --additional-hooks=. --clean --win-private-assemblies --hidden-import=Tkinter pipegui.py and it made no difference. I'm completely perplexed as to why trying to import tkinter is doing this. Will fixing this traceback lead me closer to solving the other?
I only figured out after trying all this that the only parts of my executable that are crashing are parts that make use of parmap multiprocessing. Classes that make use of matplotlib but not parmap are working fine.
So please note my question is how the first traceback can be fixed and also why are both matplotlib and tkinter popping up in the traceback despite my code where the crash occurs making use of niether?
Extra notes
I use --clean --win-private-assemblies to fix error code 14001 as per here
Repiklis provided the solution in the comments. Further note that as of January 15 2017 Pyinstaller version 3.2.1 was released. I now use this and it solves this issue along with others like this and this that I could previously only solve by using the developer version. So I highly recommend upgrading to the latest version if you haven't already.

%%cython_pyximport ImportError: Building module function failed: ['DistutilsPlatformError: Unable to find vcvarsall.bat\n']

In the iPython Notebook I am trying to use the notebook function %%cython_pyximport to write a cython function that I can call later on in my notebook.
I want to use this command as opposed to %%cython because there seems to be quite a bit of overhead with it. For example when I profile my code I get this:
168495 function calls in 4.606 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1 3.234 3.234 4.605 4.605 {_cython_magic_0ef63e1ad591c89b73223c7a86d78802.knn_alg}
11397 0.326 0.000 0.326 0.000 {method 'reduce' of 'numpy.ufunc' objects}
987 0.152 0.000 0.266 0.000 decomp.py:92(eig)
987 0.118 0.000 0.138 0.000 function_base.py:3112(delete)
I'm hoping that using %%cython_pyximport will cut down time spent calling this function. If there is a better way please let me know.
So getting to my actual question - When I use %%cython_pyximport I get this error:
ImportError: Building module function failed: ['DistutilsPlatformError: Unable to find vcvarsall.bat\n']
Maybe it's related to something not being on my PATH but I'm not sure. What do I have to do to fix this?
I'm using Windows 7, Python 2.7.6 (Installed with Anaconda), Cython 0.20.1, iPython Notebook 2.1.0
EDIT:
So after following #IanH 's suggestion I now have this error:
fatal error: numpy/arrayobject.h: No such file or directory
It seems like additional header files need to be included for numpy to work with pyximport. On this page https://github.com/cython/cython/wiki/InstallingOnWindows there is a mention of this error and how to solve it but am lost at how to apply this so that the %%cython_pyximport command will work in my notebook.
There are two different issues here.
I'll first address the one you seem to care about.
Using pyximport instead of the cython magic function should not increase speed at all.
Given your profiling results, it appears that the real problem here is that you are calling a NumPy function on the inside of a loop.
In Cython you have to keep track of which function calls are done in C, and which are done in Python.
Numpy universal functions are Python functions and they require the cost of calling a Python function.
How you would want to fix this depends entirely on what you are doing.
If you can cleverly vectorize away the loop using NumPy operations, that is probably the best way, but not all problems can easily be solved that way.
There are ways to call LAPACK routines from Cython, as described in this answer.
If you are doing simpler operations (like summing along axes, etc), you can write a function that uses cython memoryviews to pass slices around internally in your Cython module.
There is some discussion on the proper way to do that in this blog post.
Doing these sorts of operations is usually a little harder in Cython, but it is still a very approachable problem.
Now, though I'm not convinced that pyximport will actually do what you want it to, I will still tell you how to get it working.
The error you are seeing happens when distutils tries to use the Visual Studio compiler even when you haven't gotten everything set up for it.
Anaconda, by default uses MinGW for Cython extensions, but for some reason it isn't set up to use MinGW with pyximport.
That's easy to fix though.
In your Python installation directory, (probably C:\Anaconda or something along those lines), there should be a file Anaconda\Lib\distutils\distutils.cfg. (Create it if it doesn't exist.)
Modify it so that its contents contain both of the following options:
[build]
compiler=mingw32
[build_ext]
compiler = mingw32
If I remember correctly, the first is already included in Anaconda.
As of this writing, the second is not.
You will need it there to make pyximport work.
I had this same exact problem, so my solution was instead to use:
[build]
compiler=mingw32
[build_ext]
compiler = mingw32
In the answer by IanH, I just chose to call gcc and cython directly.
I figured I'd literally just circumnavigate around all the possible errors
Firstly, you need to compile cython using:
cython_commands = ['cython', '-a', '-l', '-p', '-o', c_file_name, file_path]
cython_feedback = subprocess.call(cython_commands)
Then you need to take that .c file and compile it by telling the compiler where to look for the python libraries.
gcc_commands = ['gcc', '-shared', '-Wall', '-O3', '-I', py_include_dir, '-L', py_libs_dir, '-o', output_name,
c_file_name, '-l', a_lib]
gcc_error = subprocess.call(gcc_commands)
py_include_dir: The path to the directory in python installation labeled 'include'
py_libs_dir: The path to the directory in python installation labeled 'libs'
c_file_name: The path to which you wish to ave the middleman c file
a_lib: The name of your python installation (ex. 'python34' or 'python35' or 'python27')
Since I have VS2015 installed, had to add new environment variable
SET VS90COMNTOOLS=%VS140COMNTOOLS%
Source https://stackoverflow.com/a/10558328/625189

Install pycairo or py2cairo using buildout

Does anyone have any experience with trying to install cairo for django using buildout?
It will install pycairo or py2cairo (the first is for python >3.0, the latest is for python 2.6, which I Am using)
I found 2 recipes to use for installation, both of them gives me errors, in buildout.cfg I have them as 2 parts (of course tried them seperately, not thogether).
The errors are totally different, but the result is the same: I can't get cairo installed using buildout.......
based on: http://pypi.python.org/pypi/tl.buildout_gtk/
[cairo_tl]
recipe = tl.buildout_gtk
#pycairo-url = http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2
pycairo-url = http://cairographics.org/releases/py2cairo-1.8.10.tar.gz
pycairo-md5sum = http://cairographics.org/releases/py2cairo-1.8.10.tar.gz.md5
based on: https://bitbucket.org/lgs/yaco.recipe.pycairo
[cairo_yaco]
recipe = yaco.recipe.pycairo
find-links = http://pypi.python.org/pypi/yaco.recipe.pycairo/0.1.1
#find-links = http://pypi.python.org/pypi/yaco.recipe.pycairo/0.1
# pkg-config-path ?
Both need a local install of cairo (pycairo and py2cairo depend on this):
so use on the server:
sudo apt-get install libcairo2-dev
The part jusing tl.buildout_gtk:
Either using the py2cairo-1.10.0 or pycairo-1.8.2 gives me a MD5 checksum mismatch
(see for available releases: http://cairographics.org/releases/)
e.g:
Error: MD5 checksum mismatch downloading 'http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2'
or:
Error: MD5 checksum mismatch downloading 'http://cairographics.org/releases/py2cairo-1.8.10.tar.gz'
The part jusing yaco:
I Am pretty sure this part is not configured correctly (pkg-config-path refering to the local cairo package), but I do not even get to that point.
It gives an error:
DistributionNotFound: zc.recipe.cmmi
However, this is installed in the eggs
By the way, I had the same kind of headache trying to install PIL by buildout, which I solved combining a lot of options and posts on the internet, together with a lot of time and trials and errors.
If anyone want to know how I finally got it working, just ask, and I will publish it.
(I consider myselve still a django starter, so I do not know for sure if anyone is interested in the solution)
PIL does not have all the options I found in cairo, so I started using cairo. On my local PC everything works fine (ubuntu desktop), on my server (Ubuntu server) I can't getting it to work......
Any other options for making drawings on the fly..... (like matplotlib...) let me know.
Pretty sure you have to give the real md5 hash to the pycairo-md5 option instead of a string with some url in it.
I would avoid specialized recipes like those two whenever possible. There are some cases when a specialized recipe really is needed, but those are cases where the dependency is so egregiously eccentric that no common build/install pattern is usable. I don't know pycairo so that may be the case.
But before assuming it is, try the following. Always try using an egg first by adding it to the eggs option of the relevant buildout part. If that doesn't work, update your question with those details, and then try adding a separate zc.recipe.egg part with build options that may help the distribution build successfully. If that doesn't work or the distribution uses a ./configure && make && make install (AKA "CMMI") build system, update your question with those details, and then try using zc.recipe.cmmi to build the package after which you can use the extra-paths option of your zc.recipe.egg part to include the relevant bits of the CMMI part (extra-paths = ${cmmi-part:location}/weird/path/to/python/modules).
This is the general dance for getting poorly/oddly behaved distributions. If this doesn't work, then a specialized recipe may be in order but in general there's a way to get it to work with the above and that will be much more maintainable.