Hi,
I am trying to embed Python in my Qt application, and PythonQt seems to be exactly what I need. I normally work in Linux, and I was able to get it to work with my Qt application.
Now I am trying to do the same thing in Windows XP, but it just crashes. In fact all examples that come with PythonQt also crash when I run them on Windows. I used Visual Studio Express 2008 to compile Qt and PythonQt. Unfortunately I cannot build PythonQt with debugging information because Visual Studio looks for "python25_d.lib", which I believe is python library with debugging symbols that does not come with standard Python distribution on Windows.
I expected that it will work the same as in Linux. The documentation for PythonQt says that it works on Windows as well.
Any hints what can be wrong?
Thanks.
Sergey.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You need to build Python with the same compiler that you use for PythonQt, which means that you need to download the source distrib of Python and build it on Windows using Visual Studio Express 2008.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Think I have a similar problem. I'm using qt creator, followed the build instructions using qmake on PythonQt.pro but I can't build.
I've downloaded Python25 and have all the headers and lib files, do I also need the source files (.cpp)?
Paths are set okay but I get undefined reference errors when I build, e.g. undefined reference to '_imp__PyModule_Type' in PythonQt.o:PythonQt.cpp. There are 96 of these when I build in release mode.
When I build in debug mode I just get 'collect2: Id returned 1 exit status', so not much help there.
Sounds like I missing something, any ideas?
Thanks very much,
steve
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Compiling PythonQt on Windows actually works like a charme and is as easy as compiling any other SDK yourself.
Here are basic steps:
1. Download the Python source package. Note: Even if you should be using the exact same compiler as the pre-built python package, there's no debug library available in that package and you cannot build the debug library from the pre-built version.
2. Compile Python with the compiler you used for building Qt.
3. Set the PYTHON_VERSION and PYTHON_PATH variables as described within the PythonQt readme.
4. Compile PythonQt with the same compiler you used to compile Qt and Python.
Keep in mind that using different compilers, or even different versions of the same compiler, will most likely produce incompatible binaries. MingW and VS, for example, produce very different binaries.
I guess there are no pre-compiled binaries available because of this very reason. But then again, PythonQt is so small that there shouldn't be any issues compiling it on your own.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi all
there is another way I found on web. I cant understand if works while I have still complation problems (not still linking ones).
there is a command line function called pexports in Mingw which is used with dlltols to create a pythonxx.a from a pythonxx.dll
May be it is interesting?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2010-07-05
Hi there,
Compiling PythonQt on with Visual Studio 2008 is not too hard. However following the HOWTO by the letter will not do the trick.
This is how it worked for me:
-Create a temporary environment variable with the command "set QMAKESPEC=win32-msvc2008" or invoke qmake with the "-spec" option and pass "win32-msvc2008" as argument.
-You need to invoke qmake with the -r option for it to iterate through all subfolders and create all necessary make files
-The path to nmake will not be known on your machine. cd to your MS-Toolkit's "bin"-folder and invoke the vcvars32 batch file. Now you will be able to use the Toolkit in this console instance. The environment will be lost if you close your console!!!
-Since you might not have the necessary debug libraries compiled on your system, call "nmake release" to build the release target.
-This will take a while to compile… have a cup of coffee.
regards
Martin
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello, I have some problems with bilding pythonqt on windows.
Windows(I have Windows 7 sp1 32). qt sdk 1.2 . Python 2.6.6 .PythonQt2.0.1
I make same steps.
1) Download qt sdk 1.2 ,install him C:\QtSDK. I download the final version of MinGw and instaled it C:\MinGW.
2) install Python 2.6.6 from http://www.python.org/ftp/python/2.6.6/python-2.6.6.msi to C:\Python26
3) I to bild pytonqt library I want to use pexports. I download pexports and install him to C:\pexports.
I add some path to system PATH(pexports, mingw adress).
Then I use Qt , Madde Terminal:
C:\windows\system32>cd C:\Python26\libs
C:\Python26\libs> pexports C:/Windows/System32/python26.dll >python26.def
C:\Python26\libs> dlltool -dllname python26.dll -def python26.def -output-lib libpython26.a
4) As result a have a lib,- libpython26.a
5) I change def-files in catalog C:\PythonQt2.0.1\build :
PythonQt.prf :
Code:
win32::LIBS += $$PWD/../lib/libPythonQt$${DEBUG_EXT}.a
PythonQt_QtAll.prf - то же самое:
Code:
win32::LIBS += $$PWD/../lib/libPythonQt_QtAll$${DEBUG_EXT}.a
I use this options for qt progect:
Pro Qt - Qt 4.7.4 for Desktop - MinGW 4.4 (Qt SDK);
Catalog for bilding pythonqt - C:\PythonQt2.0.1;
Bild all. I have 2 error:
1) C:\PythonQt2.0.1\src\PythonQtConversion.cpp:677: ошибка: invalid conversion from 'Py_UNICODE*' to 'const ushort*'
2) C:\PythonQt2.0.1\src\PythonQtConversion.cpp:1045: ошибка: invalid conversion from 'const ushort*' to 'const Py_UNICODE*'
Second error I solve by changing PythonQtConversion.cpp
PythonQtConversion.cpp:1045 в PythonQtConv::QStringToPyObject()
найти
#ifdef WIN32
//return PyString_FromString(str.toLatin1().data());
return PyUnicode_FromUnicode(str.utf16(), str.length());
нужно сделать так
#ifdef WIN32
return PyString_FromString(str.toLatin1().data());
// return PyUnicode_FromUnicode(str.utf16(), str.length());
It solve the second error and kill a lot of warning:
but I can't solve first error. I need your help
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
but you need to find out what the correct define for MINGW is.
Alternatively you can just do #IFDEF 0 instead of #IFDEF WIN32 on the places where you get errors,
the #else part should work for Mingw since it is for Linux/MacOs using gcc or clang.
regards,
Florian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am trying to embed Python in my Qt application, and PythonQt seems to be exactly what I need. I normally work in Linux, and I was able to get it to work with my Qt application.
Now I am trying to do the same thing in Windows XP, but it just crashes. In fact all examples that come with PythonQt also crash when I run them on Windows. I used Visual Studio Express 2008 to compile Qt and PythonQt. Unfortunately I cannot build PythonQt with debugging information because Visual Studio looks for "python25_d.lib", which I believe is python library with debugging symbols that does not come with standard Python distribution on Windows.
I expected that it will work the same as in Linux. The documentation for PythonQt says that it works on Windows as well.
Any hints what can be wrong?
Thanks.
Sergey.
Sorry for the late reply...
You need to build Python with the same compiler that you use for PythonQt, which means that you need to download the source distrib of Python and build it on Windows using Visual Studio Express 2008.
Hi,
Think I have a similar problem. I'm using qt creator, followed the build instructions using qmake on PythonQt.pro but I can't build.
I've downloaded Python25 and have all the headers and lib files, do I also need the source files (.cpp)?
Paths are set okay but I get undefined reference errors when I build, e.g. undefined reference to '_imp__PyModule_Type' in PythonQt.o:PythonQt.cpp. There are 96 of these when I build in release mode.
When I build in debug mode I just get 'collect2: Id returned 1 exit status', so not much help there.
Sounds like I missing something, any ideas?
Thanks very much,
steve
Im have so many problems compiling PythonQt on Windows.
Ive compiled Python in VS, but I cant get PythonQt to compile with VS using nmake. Instead of using clr, nmake is using (for some odd reason) gcc.
Also, since this is being compiled with VS, dosnt this mean I will have to use VS to compile my Qt program and not minGW?
Is there any reason why you guys do distribute pre-compiled binaries?
Compiling PythonQt on Windows actually works like a charme and is as easy as compiling any other SDK yourself.
Here are basic steps:
1. Download the Python source package. Note: Even if you should be using the exact same compiler as the pre-built python package, there's no debug library available in that package and you cannot build the debug library from the pre-built version.
2. Compile Python with the compiler you used for building Qt.
3. Set the PYTHON_VERSION and PYTHON_PATH variables as described within the PythonQt readme.
4. Compile PythonQt with the same compiler you used to compile Qt and Python.
Keep in mind that using different compilers, or even different versions of the same compiler, will most likely produce incompatible binaries. MingW and VS, for example, produce very different binaries.
I guess there are no pre-compiled binaries available because of this very reason. But then again, PythonQt is so small that there shouldn't be any issues compiling it on your own.
Hi all
there is another way I found on web. I cant understand if works while I have still complation problems (not still linking ones).
there is a command line function called pexports in Mingw which is used with dlltols to create a pythonxx.a from a pythonxx.dll
May be it is interesting?
Hi there,
Compiling PythonQt on with Visual Studio 2008 is not too hard. However following the HOWTO by the letter will not do the trick.
This is how it worked for me:
-Create a temporary environment variable with the command "set QMAKESPEC=win32-msvc2008" or invoke qmake with the "-spec" option and pass "win32-msvc2008" as argument.
-You need to invoke qmake with the -r option for it to iterate through all subfolders and create all necessary make files
-The path to nmake will not be known on your machine. cd to your MS-Toolkit's "bin"-folder and invoke the vcvars32 batch file. Now you will be able to use the Toolkit in this console instance. The environment will be lost if you close your console!!!
-Since you might not have the necessary debug libraries compiled on your system, call "nmake release" to build the release target.
-This will take a while to compile… have a cup of coffee.
regards
Martin
Hello, I have some problems with bilding pythonqt on windows.
Windows(I have Windows 7 sp1 32). qt sdk 1.2 . Python 2.6.6 .PythonQt2.0.1
I make same steps.
1) Download qt sdk 1.2 ,install him C:\QtSDK. I download the final version of MinGw and instaled it C:\MinGW.
2) install Python 2.6.6 from http://www.python.org/ftp/python/2.6.6/python-2.6.6.msi to C:\Python26
3) I to bild pytonqt library I want to use pexports. I download pexports and install him to C:\pexports.
I add some path to system PATH(pexports, mingw adress).
Then I use Qt , Madde Terminal:
C:\windows\system32>cd C:\Python26\libs
C:\Python26\libs> pexports C:/Windows/System32/python26.dll >python26.def
C:\Python26\libs> dlltool -dllname python26.dll -def python26.def -output-lib libpython26.a
4) As result a have a lib,- libpython26.a
5) I change def-files in catalog C:\PythonQt2.0.1\build :
python.prf
Code:
win32:INCLUDEPATH += c:/Python26/include C:/PythonQt2.0.1/src
win32:LIBS += c:/Python26/libs/libpython26.a
common.prf - uncomment:
Code:
CONFIG += debug_and_release build_all
PythonQt.prf :
Code:
win32::LIBS += $$PWD/../lib/libPythonQt$${DEBUG_EXT}.a
PythonQt_QtAll.prf - то же самое:
Code:
win32::LIBS += $$PWD/../lib/libPythonQt_QtAll$${DEBUG_EXT}.a
I use this options for qt progect:
Pro Qt - Qt 4.7.4 for Desktop - MinGW 4.4 (Qt SDK);
Catalog for bilding pythonqt - C:\PythonQt2.0.1;
Bild all. I have 2 error:
1) C:\PythonQt2.0.1\src\PythonQtConversion.cpp:677: ошибка: invalid conversion from 'Py_UNICODE*' to 'const ushort*'
2) C:\PythonQt2.0.1\src\PythonQtConversion.cpp:1045: ошибка: invalid conversion from 'const ushort*' to 'const Py_UNICODE*'
Second error I solve by changing PythonQtConversion.cpp
PythonQtConversion.cpp:1045 в PythonQtConv::QStringToPyObject()
найти
#ifdef WIN32
//return PyString_FromString(str.toLatin1().data());
return PyUnicode_FromUnicode(str.utf16(), str.length());
нужно сделать так
#ifdef WIN32
return PyString_FromString(str.toLatin1().data());
// return PyUnicode_FromUnicode(str.utf16(), str.length());
It solve the second error and kill a lot of warning:
but I can't solve first error. I need your help
I never tried building against Mingw. Since Mingw uses gcc, I think that sizeof PY_UNICODE == 4 instead of 2 (== sizeof(ushort) on VC++.
So you have to look for the #else part of the #ifdef WIN32 and write something like
#if defined(WIN32) && !(defined(MINGW))
#else
#endif
but you need to find out what the correct define for MINGW is.
Alternatively you can just do #IFDEF 0 instead of #IFDEF WIN32 on the places where you get errors,
the #else part should work for Mingw since it is for Linux/MacOs using gcc or clang.
regards,
Florian