天天看點

cx_freeze使得__file__路徑解析錯誤

IOError: [Errno 20] Not a directory: '/storage/workspace/mediaFileAnalyzer/build/exe.linux-x86_64-2.7/lib/library.zip/orig-prefix.txt'

解決辦法是,修改擷取目前目錄的方法 

def get__dir__():
    if getattr(sys, 'frozen', False):
        # frozen
        dir_ = os.path.dirname(sys.executable)
    else:
        # unfrozen
        dir_ = os.path.dirname(os.path.realpath(__file__))

    return dir_


def virtual_install_main_packages():
    #f = open(os.path.join(os.path.dirname(__file__), 'orig-prefix.txt'))
    f = open(os.path.join(get__dir__(), 'orig-prefix.txt'))