[PyQt] Determining location of pyqtdeployed app at runtime

Phil Thompson phil at riverbankcomputing.com
Fri Aug 1 22:19:32 BST 2014

On 01/08/2014 7:59 pm, Dave Gradwell wrote:
> Hello,
> I would like to determine the location from which my pyqtdeployed
> application was executed.
> I have read this: 
> http://pyqt.sourceforge.net/Docs/pyqtdeploy/pyrcc.html
> but this:
>     QFileInfo(__file__).absolutePath()
> gives me this:
>     <frozen>
> ... when it's pyqtdeployed.  (Although it works fine when it's not 
> frozen.)

It should work (with v0.5, not earlier).

> This seems to work:
>     os.path.dirname(sys.executable)
> but is that inadvisable for some reason?  And would I be better off
> using the advised QFileInfo technique (maybe I have missed something)?

sys.executable will be correct (pyqtdeploy uses it internally). You can 
use sys.executable when you know that the location you are after *will 
not* be in the resource. You should use QFileInfo when the location 
*might* be in the resource.


More information about the PyQt mailing list