問題描述
我在 Windows 10 上,我安裝了 anaconda,但我想使用 python 3.5 在一個新的、干凈的最小環(huán)境中獨立創(chuàng)建一個可執(zhí)行文件.所以我做了一些測試:
I am on Windows 10, I have anaconda installed but I want to create an executable independently in a new, clean minimal environment using python 3.5. So I did some tests:
測試1:我在 testenv 文件夾中創(chuàng)建了一個 python 腳本 test1.py,只有:
TEST1: I created a python script test1.py in the folder testenv with only:
print('Hello World')
然后我創(chuàng)建了環(huán)境,安裝了pyinstaller并創(chuàng)建了可執(zhí)行文件
Then I created the environment, installed pyinstaller and created the executable
D: estenv> python -m venv venv_test
...
D: estenvvenv_testScripts>activate.bat
...
(venv_test) D: estenv>pip install pyinstaller
(venv_test) D: estenv>pyinstaller --clean -F test1.py
它會創(chuàng)建大約 6 Mb 的 test1.exe
And it creates my test1.exe of about 6 Mb
測試2:我修改test1.py如下:
TEST 2: I modified test1.py as follows:
import pandas as pd
print('Hello World')
我在環(huán)境中安裝了 pandas 并創(chuàng)建了新的可執(zhí)行文件:
I installed pandas in the environment and created the new executable:
(venv_test) D: estenv>pip install pandas
(venv_test) D: estenv>pyinstaller --clean -F test1.py
Ant 它創(chuàng)建了我的 test1.exe,它現(xiàn)在是 230 Mb!!!
Ant it creates my test1.exe which is now of 230 Mb!!!
如果我運行命令
(venv_test) D: estenv>python -V
Python 3.5.2 :: Anaconda custom (64-bit)
當(dāng)我運行 pyinstaller 時,我收到一些我不理解的消息,例如:
when I am running pyinstaller I get some messages I do not understand, for example:
INFO: site: retargeting to fake-dir 'c:\users\username\appdata\local\continuum\anaconda3\lib\site-packages\PyInstaller\fake-modules'
我還收到有關(guān) matplotlib 和其他與我的代碼無關(guān)的模塊的消息,例如:
Also I am getting messages about matplotlib and other modules that have nothing to do with my code, for example:
INFO: Matplotlib backend "pdf": added
INFO: Matplotlib backend "pgf": added
INFO: Matplotlib backend "ps": added
INFO: Matplotlib backend "svg": added
我知道有一些相關(guān)的問題:減小pyinstaller exe的大小, 使用 pyinstaller 和 numpy 的可執(zhí)行文件的大小但我無法解決問題,我擔(dān)心我在 anaconda 方面做錯了什么.
I know there are some related questions: Reducing size of pyinstaller exe, size of executable using pyinstaller and numpy but I could not solve the problem and I am afraid I am doing something wrong with respect to anaconda.
所以我的問題是:我究竟做錯了什么?我可以減小可執(zhí)行文件的大小嗎?
So my questions are: what am I doing wrong? can I reduce the size of my executable?
推薦答案
問題是你不應(yīng)該使用虛擬環(huán)境,尤其是 anaconda.請下載默認(rèn)的 32 位 python 并僅使用必要的模塊.然后按照鏈接中提供的步驟進行操作,這肯定會解決它.
The problem is that you should not be using a virtual environment and especially not anaconda. Please download default python 32 bit and use only necessary modules. Then follow the steps provided in the links, this should definitely fix it.
雖然您創(chuàng)建了一個虛擬環(huán)境,但您確定您的規(guī)范文件沒有鏈接到舊的 Anaconda 條目嗎?
Although you created a virtual env, are you sure your spec file is not linking to old Anaconda entries?
如果這一切都失敗了,那么提交一個錯誤,因為這很奇怪.
If all this fails, then submit a bug as this is very strange.
這篇關(guān)于如何使用 pyinstaller 創(chuàng)建最小大小的可執(zhí)行文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!