473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Get EXE (made with py2exe) path directory name

I need to get absolute path name of a file that's in the same dir as
the exe, however the Current Working Directory is changed to somthing
else.

I turn my script into an executable with py2exe, then I create a
shortcut to the EXE on the desktop. I change the "Start In" variable of
the shortcut "C:\somthing_else", so now the currect working directory
of the executable is not the same as the directory where the EXE is
located.

I need to load a file that's in the same directory as the EXE, so I do
the following:

dir = os.path.dirname(sys.argv[0])
filepath = os.path.join(dir, 'server.pkey')

however it doesn't seem to work.

Any idea?

thanks!

Jun 6 '06 #1
2 2440
try,

if hasattr(sys, 'frozen'): me = sys.executable
else: me = sys.argv[0]

Jun 6 '06 #2

Andrei B wrote:
I need to get absolute path name of a file that's in the same dir as
the exe, however the Current Working Directory is changed to somthing
else.


Use sys.path[0]

Jun 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Thomas Heller | last post by:
I'm currently working on a new version of py2exe, which will require Python 2.3 and later, because it uses the zipimport mechanism. Since py2exe is a distutils extension, and since C compilers...
5
by: Michael Peuser | last post by:
Hi, I should like to make a distribution (using Tkinter), with standard DLLs removed. pythonXX.dll is no problem. tcl und tk, which make the mass of mega bytes, cannot be removed because...
5
by: Rene Olsthoorn | last post by:
Dear readers, py2exe has a problem including libxml2. Not at building time, but at runtime. The libxml2.dll cannot be loaded... Is there anyone that NOT has the problem? (and can you drop me...
2
by: Anthony Baxter | last post by:
I'm trying to use py2exe and Inno Setup to build an installer for shtoom, which uses tkinter. If I take the py2exe generated directory, and run the executable from there, it works fine. If I...
3
by: Larry Bates | last post by:
I had occasion to look back at a project I did over a year ago and needed to make one small change. I use py2exe to package it for distribution via Inno Setup. After making my change I tried to...
11
by: Timothy Smith | last post by:
is it possible instead of py2exe putting all library's in a zip file, to just put them in a sub dir?
9
by: Grant Edwards | last post by:
I have several python apps (some wxPython, some plain text-mode stuff) that I distribute internally for installation on Win32 machines. They're bundled/installed using py2exe and inno setup. I...
4
true911m
by: true911m | last post by:
Here's a little walkthrough to get py2exe up and running. I'm not an expert, so I can't help much with any problems you might have. This is what worked for me. The result here will be to convert...
0
by: devnew | last post by:
I wrote an app that uses some Tix widgets and wanted to make an exe using py2exe .i used the setup script as given in http://www.py2exe.org/index.cgi/TixSetup and it copies the dlls into the dist...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.