1

When using py2exe, I've found that os.path.dirname(__file__) is giving me a filepath with the exe file in it, which is not what I am looking for. I've done some research and found that I should replace it with sys.argv[0] or sys.path[0], but both of those only get the top-level directory of the program. If I have sub-directories in the program, and I don't know the names of them at compile time, what can I do to find their directories?

For example, suppose there's a file, /stages/arena.py and I need to get /arena/ from it. What can I do to find this in a py2exe executable file? dirname gets me /main.exe/stages/ and sys.argv[0] and sys.path[0] get me /

What can I replace my os.path.dirname(__file__) calls with?

Matthew Fournier
  • 1,077
  • 2
  • 17
  • 32
  • if you know that it gives you `main.exe` in path then you can remove it manually `replace('main.exe', '')` – furas Jan 24 '16 at 15:32

1 Answers1

-1

You should make sure that you are using correctly in your source code relative imports. Have a look this answer and it will solve your problem.

Community
  • 1
  • 1
mabe02
  • 2,676
  • 2
  • 20
  • 35