Pymex compiling

2 次查看(过去 30 天)
Edward Umpfenbach
Edward Umpfenbach 2011-10-19
Not sure if this is the best forum to ask a question about something from the file exchange, but here I go:
I am trying to solve a mixed integer problem with Cplex, and want to use the callback functions in Python (which aren't implemented in Matlab).
Pymex (from the file exchange) looks like it could be helpful. I already have all the parameters/matrices built in Matlab, so I want to be able to automate transferring them to Python. My question:
I am not the greatest linux programmer. Pymex has this included as instructions for compiling:
Compile with: g++ pymex.cpp -o pymex.mexglx -I/opt/matlab/2009A/extern/include/ -Wl,-rpath-link,/opt/matlab/2009A/bin/glnx86 -L/opt/matlab/2009A/bin/glnx86 -lmx -lmex -lmat -lm -I/usr/include/python2.6 -I/usr/include/python2.6 -L/usr/lib/python2.6/config -lpthread -ldl -lutil -lm -lpython2.6 -rdynamic -shared
I am using Matlab 2011B. I have python 2.6. I have updated the matlab paths in the code. However, I still get a whole bunch of errors:
pymex.cpp:45:17: error: mex.h: No such file or directory
pymex.cpp:46:20: error: matrix.h: No such file or directory
pymex.cpp:48:30: error: python2.6/Python.h: No such file or directory
pymex.cpp:61: error: expected initializer before ‘*’ token
pymex.cpp:62: error: expected initializer before ‘*’ token
pymex.cpp:63: error: expected initializer before ‘*’ token
pymex.cpp:64: error: expected initializer before ‘*’ token
pymex.cpp:65: error: expected initializer before ‘*’ token
pymex.cpp:66: error: expected initializer before ‘*’ token
pymex.cpp:67: error: variable or field ‘recursive_matlab_fill’ declared void
pymex.cpp:67: error: PyObjectwas not declared in this scope
pymex.cpp:67: error: objectwas not declared in this scope
pymex.cpp:67: error: expected primary-expression before ‘double’
pymex.cpp:67: error: expected primary-expression before ‘const’
pymex.cpp:67: error: expected primary-expression before ‘const’
pymex.cpp:68: error: PyObjectwas not declared in this scope
pymex.cpp:68: error: objectwas not declared in this scope
pymex.cpp:69: error: PyObjectwas not declared in this scope
pymex.cpp:69: error: objectwas not declared in this scope
pymex.cpp:70: error: variable or field ‘nudge_object’ declared void
pymex.cpp:70: error: PyObjectwas not declared in this scope
pymex.cpp:70: error: objectwas not declared in this scope
pymex.cpp:71: error: variable or field ‘guess_dims’ declared void
pymex.cpp:71: error: PyObjectwas not declared in this scope
pymex.cpp:71: error: tuplewas not declared in this scope
pymex.cpp:71: error: mwSizewas not declared in this scope
pymex.cpp:71: error: num_dimswas not declared in this scope
pymex.cpp:71: error: mwSizewas not declared in this scope
pymex.cpp:71: error: dimswas not declared in this scope
pymex.cpp:72: error: PyObjectwas not declared in this scope
pymex.cpp:72: error: tuplewas not declared in this scope
pymex.cpp:72: error: expected primary-expression before ‘const’
pymex.cpp:72: error: expected primary-expression before ‘const’
pymex.cpp:72: error: initializer expression list treated as compound expression
pymex.cpp:73: error: expected initializer before ‘*’ token
pymex.cpp:153: error: PyMethodDefdoes not name a type
pymex.cpp:160: error: expected initializer before ‘*’ token
pymex.cpp:164: error: expected initializer before ‘*’ token
Not really sure what to do. Help would be appreciated.
  1 个评论
Kaustubha Govind
Kaustubha Govind 2011-10-19
Do you see mex.h and matrix.h in /opt/matlab/2009A/extern/include/? Typically these files exist in $matlabroot/extern/include, where $matlabroot is the MATLAB installation directory.

请先登录,再进行评论。

回答(3 个)

Edward Umpfenbach
Edward Umpfenbach 2011-10-19
To add to this, I was unaware of mex files when I originally posted. I have set them up now. I still get this error:
pymex.cpp:48:30: error: python2.6/Python.h: No such file or directory
The documentation says I should supply as an input /usr/lib/libpython2.6.so, but I have /usr/lib/libpython2.6.so.1 and /usr/lib/libpython2.6.so.1.0 on my computer. Not sure what the extra numbers represent, if these are the wrong files, etc.
I tried reinstalling python 2.6, nothing changed.

Tim Perkins
Tim Perkins 2011-10-19
Hi Ed,
I would not use the command above, I would try to use the install.m script. The line in the source starting with "compile with:" was intended to be a reminder to myself while I was debugging. It is not portable.
Unfortunately the install script is also somewhat fragile. You will still need to feed it the location of the shared library, libpython2.6.so. It will probably be in /usr/lib/.
The numbers after the .so are version numbers. Typically the names without version numbers are just simlinks to the names with version numbers. Bottom line: libpython2.6.so.1.0 should be the same thing as libpython2.6.so, so it's ok to use it.
Anyway, it seems that you are missing a header. Try running this command to find the header's location:
find /usr/include/ -name Python.h
If that doesn't show anything, then you probably haven't installed the Python development packages. On Ubuntu, you will need the python-dev package:
sudo apt-get install ptyhon-dev -y
Now that I think about it, the install script should probably check for this. I'll add it to the next version.
  1 个评论
Walter Roberson
Walter Roberson 2011-10-19
-I/usr/include/python2.6 appears twice in the include path, but because python2.6/Python.h is being looked for, it needs -I/usr/include

请先登录,再进行评论。


Edward Umpfenbach
Edward Umpfenbach 2011-10-19
Yeah, I didn't have the python development packages.
Installed with no errors. Haven't used it yet though.
Thanks!

类别

Help CenterFile Exchange 中查找有关 Python Package Integration 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by