I am currently trying to get into the basics of PythonQt and encountered a strange error whilst trying out the examples:
whenever I try to evaluate a python file using the call mainModule.evalFile(":myfile.py"), nothing seems to happen, not even an error is thrown. However, removing the ":" from the file name (mainModule.evalFile("myfile.py")) results in an empty .pyc file being created and nothing else happening as well.
"evalScript()" works well.
I am on Windows 7, using Visual Studio 2013, Python 3.4. and Qt 5.4.
Any ideas?
Thanks in advance!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
: refers to the Qt resource files, if you want to load files from the resources, you need to add them to the qrc file.
If you want to read a file from disk, I recommend that you use an absolute file path and no :.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
using the absolute path behaves just like specifying the relative path: a zero-sized .pyc file is created and the program crashes.
I also tried "manual" compilation, and it yields a valid .pyc file.
Edit: after manually compiling a simplified myfile.py (not using PythonQt functionality nor the Pythonqt import) the evalFile() command is executed properly.
Yet that does not really help me, since this way I cannot share the Qt objects between python and c++...
Last edit: Malte Mueller 2015-06-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hm, maybe this is a Python 3 issue... I never tried parsing files with the Python 3 port, and I am not sure if any of the Python 3 users has.
Maybe you can step into evalFile with a debugger and see why the pyc file is not written correctly?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I still use Qt 4.8.6 and Python 2.7 ,But the call mainModule.evalFile(":myfile.py") is still unsuccessul,no error occur,I can not go next step.
could you help me please?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I can not reproduce it, for me both files (inside resource and on disk) work well.
Maybe you need to understand the Qt Resource system better? If you do:
mainModule.evalFile(":myfile.py");
then you need to make sure to add myfile.py to the PyGettingStarted.qrc:
and re-run qmake to recreate the project and rebuild the project.
Otherwise myfile.py will not be part of the executable.
On the other hand, if you are using a file on disk:
mainModule.evalFile("myfile.py");
then you need to make sure that the current application working directory is where myfile.py is located when you run the executable, otherwise the file will not be found.
An alternative is to use an absolute path to a file, which does not depend on the current
working directory.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Are you also using Windows 7 and VS2013 to test? The other things about the environment doesn't match, but Win7 and VS2013 does, and I get the same behavior.
In my callstack, the last frame of PythonQt which causes the crash is:
void PythonQtImport::writeCompiledModule(PyCodeObject *co, const QString& filename, long mtime)
Florian, I'm seeing the same problem on 2.7.9/10, so it's not only a Python3 problem.
What I do realize, though, is that I'm building PythonQt w/ 2.7.9, and it might've been picking up the binary for 2.7.10 during run-time. Could this have some impact?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can confirm the problem under Win10/MinGW53/Py2.7, but for me it was opposite: happened with disk files and working perfectly with resource ones. Sadly, can't trace the bug, having big problems with debug build under MinGW.
BUT the workaround works! Thank you! Though explicit python library linking is a bit meh for my project.
Actually, first time I thought it's just that anti-MinGW python comunity, that refuses to add official MinGW support, but as I can see here the problem resides smw else, in the hell of vcXX libraries.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am currently trying to get into the basics of PythonQt and encountered a strange error whilst trying out the examples:
whenever I try to evaluate a python file using the call mainModule.evalFile(":myfile.py"), nothing seems to happen, not even an error is thrown. However, removing the ":" from the file name (mainModule.evalFile("myfile.py")) results in an empty .pyc file being created and nothing else happening as well.
"evalScript()" works well.
I am on Windows 7, using Visual Studio 2013, Python 3.4. and Qt 5.4.
Any ideas?
Thanks in advance!
: refers to the Qt resource files, if you want to load files from the resources, you need to add them to the qrc file.
If you want to read a file from disk, I recommend that you use an absolute file path and no :.
using the absolute path behaves just like specifying the relative path: a zero-sized .pyc file is created and the program crashes.
I also tried "manual" compilation, and it yields a valid .pyc file.
Edit: after manually compiling a simplified myfile.py (not using PythonQt functionality nor the Pythonqt import) the evalFile() command is executed properly.
Yet that does not really help me, since this way I cannot share the Qt objects between python and c++...
Last edit: Malte Mueller 2015-06-23
Hm, maybe this is a Python 3 issue... I never tried parsing files with the Python 3 port, and I am not sure if any of the Python 3 users has.
Maybe you can step into evalFile with a debugger and see why the pyc file is not written correctly?
I don't have a Qt 5 / Python 3 setup at hand, since I switched to a new computer and we still use Qt 4.8 and Python 2.7 in our product.
I still use Qt 4.8.6 and Python 2.7 ,But the call mainModule.evalFile(":myfile.py") is still unsuccessul,no error occur,I can not go next step.
could you help me please?
bellow is the codes
Last edit: Alen.yang 2015-07-27
I can not reproduce it, for me both files (inside resource and on disk) work well.
Maybe you need to understand the Qt Resource system better? If you do:
mainModule.evalFile(":myfile.py");
then you need to make sure to add myfile.py to the PyGettingStarted.qrc:
and re-run qmake to recreate the project and rebuild the project.
Otherwise myfile.py will not be part of the executable.
On the other hand, if you are using a file on disk:
then you need to make sure that the current application working directory is where myfile.py is located when you run the executable, otherwise the file will not be found.
An alternative is to use an absolute path to a file, which does not depend on the current
working directory.
Hello Florian,
Are you also using Windows 7 and VS2013 to test? The other things about the environment doesn't match, but Win7 and VS2013 does, and I get the same behavior.
In my callstack, the last frame of PythonQt which causes the crash is:
at the call of
What I see is that it's using vc90's function to write the file, and it seems to fail at locking the file for writing.
I'm doing this instead to get around the issue:
-Taehee
Last edit: Taehee Kim 2017-06-10
Yes I test on VS2013 and win 7... But it may be a Python 3 problem, I am not working with Python 3 yet.
Florian, I'm seeing the same problem on 2.7.9/10, so it's not only a Python3 problem.
What I do realize, though, is that I'm building PythonQt w/ 2.7.9, and it might've been picking up the binary for 2.7.10 during run-time. Could this have some impact?
Can confirm the problem under Win10/MinGW53/Py2.7, but for me it was opposite: happened with disk files and working perfectly with resource ones. Sadly, can't trace the bug, having big problems with debug build under MinGW.
BUT the workaround works! Thank you! Though explicit python library linking is a bit meh for my project.
Actually, first time I thought it's just that anti-MinGW python comunity, that refuses to add official MinGW support, but as I can see here the problem resides smw else, in the hell of vcXX libraries.