使用如下命令查看当前文件目录
print __file__
print os.path.realpath(__file__)
print 'using sys.executable:',repr(os.path.dirname(os.path.realpath(sys.executable)))
print 'using sys.argv[0]:',repr(os.path.dirname(os.path.realpath(sys.argv[0] )))
print sys.argv[0]
print sys.path[0]
在工程文件中运行的结果
E:\PycharmProjects\untitled\test.py
E:\PycharmProjects\untitled\test.py
using sys.executable: 'D:\\Program Files (x86)\\Python27'
using sys.argv[0]: 'D:\\Program Files (x86)\\JetBrains\\PyCharm Community Edition 4.5.3\\helpers\\pycharm'
D:\Program Files (x86)\JetBrains\PyCharm Community Edition 4.5.3\helpers\pycharm\utrunner.py
E:\PycharmProjects\untitled
使用Pyinstaller生成一个单一的EXE文件之后的结果
E:\PycharmProjects\untitled> dist\test.exe
C:\Users\ABC\AppData\Local\Temp\_MEI66522\ApoManager.pyc
C:\Users\ABC\AppData\Local\Temp\_MEI66522\ApoManager.pyc
using sys.executable: 'E:\\PYCHAR~1\\untitled\\dist'
using sys.argv[0]: 'E:\\PYCHAR~1\\untitled\\dist'
E:\PYCHAR~1\untitled\dist\test.exe
C:\Users\ABC\AppData\Local\Temp\_MEI66522