2017-04-16 494 views
1

我想將.py文件轉換爲exe。我的文件hello.py的內容如下:如何更改Python版本使用pyinstaller

print "Hello, World!" 

我目前正在嘗試使用pyinstaller。然而,當我運行命令

pyinstaller hello.py 

我收到錯誤消息「的元組索引超出範圍」,我被告知我的意思Python版本不支持。特別是它的情況似乎是pyinstaller認爲我正在試圖將python 3.6代碼編譯成exe文件。但我已經安裝了python 2.7和python 3.6。我如何讓它知道我希望它將代碼視爲Python 2.7代碼?

+0

有可能是從PyInstaller支持機制更好的反應。 http://www.pyinstaller.org/support.html – lit

回答

0

假如你python2下的路徑上有python 2.x你可以做

python2 -m pyinstaller hello.py 
0

我跑了幾件事情。 如果您卸載python3,它可以與python2一起使用。 如果你已經安裝了python3(並且它是主要的),並且python3安裝了pyinstaller,它不會工作(使用python3 pyinstaller)。 如果你安裝了python3,但沒有安裝python3或卸載它(pip3卸載pyinstaller),pyinstaller的作品。

檢查環境變量(Windows 10)PATH先有python3。這可能是問題,並且可能無法解決,因爲它先檢查python3目錄,然後爲python3啓動pyinstaller。 pyinstaller不檢查文件(#!/ usr/env/bin python2)。

除非pyinstaller提出與此問題相關的選項,否則暫時可能沒有解決方法,無法從python3中卸載pyinstaller。

也可以使用py2exe,使用py2exe對python2,pyinstaller爲python3