Could re-compiling Python using Visual Studio 2010 be avoid?
Dynamic Python binding for Qt Applications
Brought to you by:
florianlink,
marcusbarann
Greetings,
Is there a way to use PythonQt with VS 2010 that would not require to distribute a re-compiled version of Python?
As I understand, Python 2.7.x on Windows uses VS 2008 compiled libraries and using those libraries with VS 2010 is probably not recommended but I got around this quite nicely by not using FILE::open and use python file system instead:
I tried to modify PythonQt accordingly but without success. I'm getting a crash with PythonQtObjectPtr::evalFile (while generating the pyc files I believe) that I do not know how to solve.
Any hint on the subject would be very appreciated.
Last edit: Neosettler 2013-05-28
Mixing DLLs from different VC compiler versions is not recommended and can have bad side effects because the CRT runtimes do not mix well, especially if the code uses cross DLL allocations. Mixing debug and release is also troublesome.
So if it crashes on you now and you find the reason, it will crash somewhere else later on.
Embedding Python in a C++ application is somewhat different to just extending an installed Python with some extensions. We built Python ourself for all compilers that we support and I think it is a requirement for a clean deployment
I definitely agree, somehow replacing Python with a compiled one is mind boggling. I'm looking forward to get my hands on JC's blog on this topic.
Meanwhile, if it is not too much to ask, lets say we have not installed Python on a client PC and we'd like to rely on our own version of Python that would reside in our API root folder. Any idea where I could get a "how to" I could chew on?
I'm sorry if I'm stretching it but I can almost see the light at the end of the tunnel after many days of darkness. I compiled Python2.7.5 successfully but I'm still not sure what to do with it. Is it possible to link my dev project to the compiled Pyhton27.lib and use the installed Python27 executable and modules to launch my python scripts or I can't rely on the default installation of python at all? In that case, I'll need to compile the executable as well and any other library that I'm using in conjuncture with PythonQt like ctypes for instance?
Last edit: Neosettler 2013-05-29
Hi,
You might want to have a look at some of the information out there about embedding Python, which might answer some of your questions - e.g.:
http://docs.python.org/2/extending/embedding.html
http://docs.python.org/2/extending/index.html
In essence, though, you'll need to compile all of Python and the libraries that you need (including ctypes), though it's not really all that bad. Once that's done, you can link your application to python27.lib or such, drop python27.dll next to your application, put the libraries including os.py in a subdirectory of your application's folder called "lib\python27", put the "DLLs" folder (the one with the .pyd files) alongside your application, and hopefully that should do it. I might have some of the file names wrong, though, as I haven't built on Windows for a while. Anyway, you don't need any python.exe when you're embedding it in your own application.
Cheers,
Oh Genius!
Here is my steps:
When launching my app I evalFile a script that use ctypes and I'm getting :
File "root\Python27\Lib\ctypes__init__.py", line 10, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes
Any idea what am I missing?
Last edit: Neosettler 2013-05-29
Sounds like you're missing _ctypes.pyd/.dll I think (but I can't remember which - not on Windows now). This should go in your "DLLs" folder. If it's in there already, have a look at your Python sys.path and check that it's looking where you expect. If it's not there, you'll probably find that it went to a different folder when you built Python - I remember it putting some things in different places; I'm not sure why - so have a look in your build directory tree, and it should be there somewhere.