0

I have an windows service made in Python. This is working fine. But I need get the file path where my service are installed. I have tried to use these codes bellow:

os.get getcwd()

Returns:

Windows System32 folder

os.path.realpath(__file__)

Returns:

NameError: global name 'file' is not defined

How can I get the file path to my windows service application?

Eduardo
  • 1,698
  • 4
  • 29
  • 48
  • To access the absolute path use os.path.abspath() [http://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python](http://stackoverflow.com/questions/51520/how-to-get-an-absolute-file-path-in-python) – Oblio Nov 18 '15 at 17:28
  • 1
    What do you get if you `print sys.prefix` ? – Martin Evans Nov 18 '15 at 17:30
  • Possible duplicate of [What directory does a Windows Service run in?](http://stackoverflow.com/questions/884963/what-directory-does-a-windows-service-run-in) – Torxed Nov 18 '15 at 17:32
  • Thanks @MartinEvans! This tip works. – Eduardo Nov 18 '15 at 17:40

1 Answers1

1

Use sys.prefix to obtain the folder used for the EXE. This holds the EXE's folder when a utility such as py2exe has been used to create it.

sys.path for example will hold the path to python24.zip

Martin Evans
  • 45,791
  • 17
  • 81
  • 97