Trying to access data files as relative paths off dirname(__file__)
is a really bad idea, unless you only want to run the program in the build tree. If you want to be able to install and run the program—whether using py2exe or any other mechanism—you're just asking for trouble.
If you're trying to package files with the executable, the right way to do this is with either the data_files
mechanism from py2exe
, or, if you can install and use setuptools
, the more powerful and flexible Package Resources mechanism.
If, on the other hand, you want the user to supply the CSV files after installing your app, you almost certainly don't want to make him put them into your app's directory. The usual thing to do is access them as relative paths off the current working directory. In other words, just use .
, not dirname(__file__)
.
But, if you really want to do this… the problem is that __file__
is the filename of your main script—which of course isn't useful when you're running a bundled executable. You can use sys.argv[0]
or sys.executable
, depending on your use case.