2

I have been trying to build .exe file using pyinstaller in windows 10. It worked, but the size of the exe file is ~212 MB, even by using a venv (as in here). I thought it might be because I am using python by anaconda!

Then I installed a separate version of Python so not to use anaconda! But it did not work (still large file).

Then I uninstalled anaconda to test it. Pyinstaller is still trying to access Python in 'C:\Program Files\anaconda3\python.exe' (this error: No Python at 'C:\Program Files\anaconda3\python.exe'). However I have removed all path to anaconda. Probably it has always tried to reach anaconda, and this is why I haven't been successful to build a small size .exe file.

How can I clearly indicate paths for pyinstaller and python?

AMC
  • 2,642
  • 7
  • 13
  • 35
mah65
  • 578
  • 10
  • 20
  • 1
    What modules are you using in the project? Some modules like pandas for example depend on lots and lots of libraries and the resulting .exe is usually huge. As to your question: is your separate python installation in system PATH? Are you certain that you've removed Anaconda from PATH? – NotAName Dec 30 '19 at 00:39
  • Yes, I need pandas only... but do you think it should come to 200 MB?! It seems others have reached around 30 MB) Yes. The new python locations are in system variables. I have removed all anaconda paths as well. – mah65 Dec 30 '19 at 00:44
  • 1
    Sorry, can't help you here. I've had very little success using pyinstaller with any script that uses pandas and/or matplotlib. Last time I tried I got 700+ Mb file for quite a simple script. But I don't think it has anything to do with Anaconda. Python in Anaconda is just your regular Python, it just comes with lots of preinstalled packages for data science. – NotAName Dec 30 '19 at 00:50
  • _I thought it might be because I am using python by anaconda!_ What makes you think that? Also, I'm not sure I understand your environment. You're using Anaconda and venv? Why not just use Conda? – AMC Dec 30 '19 at 01:41
  • Thanks. Based on other posts I found it can be related to the way that anaconda python works and builds the file. I used venv. I am not aware of Conda. – mah65 Dec 30 '19 at 01:53
  • @mah65 _I used venv. I am not aware of Conda._ I'm confused, since your post mentions Anaconda multiple times. – AMC Apr 16 '20 at 00:15
  • Relevant post: https://stackoverflow.com/q/43886822/11301900. – AMC Apr 16 '20 at 00:26

2 Answers2

8

Finally, after a lot of researching, could solve my problem:

  • Uninstalled all pythons and anaconda from my PC
  • Removed all Path from the system variables
  • Restarted the windows
  • Installed a fresh Python from its website
  • Installed Pyinstaller using pip install pyinstaller
  • Tested my .py code in cmd. It showed me all the packages that are missing.
  • Installed all required packages by using pip install name-of-package
  • Ran final command by pyinstaller -F -w --clean file.py
  • (Optional) Install Anaconda if you need (don't add Anaconda Python as the default python. Also don't add its path to the system variables).

Note: You can build virtualenv and do pyinstaller in them.

My previous tries which used anaconda resulted in file of 212 MB in size. This process generated a .exe file of size 27 MB (Importing only pandas module).

mah65
  • 578
  • 10
  • 20
0

I ran into a similar problem and found PyCharms virtualenv manager very helpful. https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html

This just necessitated downloading python from python.org and linking the virtual environment to this interpreter, rather than the conda interpreter (otherwise it will throw strange SSL errors).

This seems to allow neat parallel use of conda and virtualenv.

Joseph
  • 578
  • 3
  • 15