3

Feel free to check codes in my repository.

Command attempted: pyinstaller -y file.py

What happened: I've been trying to make .exe file from .py. Kinda big project, everything has worked, but then, even though I didn't change a thing, it stopped working. Having tried million possible solutions (updating all packages, installing dev version of pyinstaller, modifying command, reinstalling matplotlib, restarting computer ...), after ~5h of research, I decided to post problem here. As I said, it was working... Directories to files seem fine as well, original .py code works without issues, even if I place them in different directory. It's multiple files and multiple packages all imported to this one file I'm compiling (code). Having run .exe file, I received such an output: (in repository). Sorry for putting screenshot, not code, but it shows for half a send before it closes.

The problem almost definitely is within matplotlib, because even when I don't use it (tried in different program), but include import matplotlib.pyplot as plt, program doesn't launch as well, as the same program (this other one), without the inclusion runs smoothly. I'm talking about .exe files of course, because .py always works.

Extra info: I'm using: Python 32bit, 3.8.2. Matplotlib 3.2.1 Pyinstaller 4.0.dev0+3010fdfaa0 (every package latest, I updated all on today - 02.05.2020)

Repository with files and error shown when launching .exe file: https://github.com/jakubedzior/MyPortfolio/tree/master/Koronawirus

(code):

# Packages that are used in files below
from bs4 import BeautifulSoup
import requests
from pathlib import Path
import csv
import glob
import os
from time import sleep
from pathlib import Path
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
from datetime import date, timedelta

# My files I import (functions):
from Wiki_update import *
from Csv_edit import *
from Reproduction import *
from Predictions_weekly import *

PS: File's name is Koronawirus.py (/exe).

Output that I get from pyinstaller

PS C:\Users\jakub\Desktop\Programming\Python files\Koronawirus> pyinstaller -y Koronawirus.py                  78 INFO: PyInstaller: 4.0.dev0+3010fdfaa0
78 INFO: Python: 3.8.2
78 INFO: Platform: Windows-10-10.0.18362-SP0
78 INFO: wrote C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\Koronawirus.spec
78 INFO: UPX is not available.
78 INFO: Extending PYTHONPATH with paths
['C:\\Users\\jakub\\Desktop\\Programming\\Python files\\Koronawirus',
 'C:\\Users\\jakub\\Desktop\\Programming\\Python files\\Koronawirus']
93 INFO: checking Analysis
93 INFO: Building Analysis because Analysis-00.toc is non existent
93 INFO: Initializing module dependency graph...
93 INFO: Caching module graph hooks...
109 INFO: Analyzing base_library.zip ...
5179 INFO: Processing pre-find module path hook distutils from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
5181 INFO: distutils: retargeting to non-venv dir 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib'
8786 INFO: Caching module dependency graph...
8944 INFO: running Analysis Analysis-00.toc
8966 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
  required by c:\users\jakub\appdata\local\programs\python\python38-32\python.exe
9081 INFO: Analyzing C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\Koronawirus.py
10333 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
12449 INFO: Processing pre-find module path hook site from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
12450 INFO: site: retargeting to fake-dir 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\fake-modules'
15004 INFO: Processing pre-safe import module hook setuptools.extern.six.moves from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-setuptools.extern.six.moves.py'.
20241 INFO: Processing pre-safe import module hook six.moves from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-six.moves.py'.
22307 INFO: Processing module hooks...
22307 INFO: Loading module hook 'hook-certifi.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22307 INFO: Loading module hook 'hook-Crypto.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22323 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22323 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22445 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22454 INFO: Loading module hook 'hook-lxml.etree.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
22456 INFO: Loading module hook 'hook-matplotlib.backends.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 562, in _get_xdg_config_dir
    return os.environ.get('XDG_CONFIG_HOME') or str(Path.home() / ".config")
AttributeError: type object 'Path' has no attribute 'home'
22929 INFO: Loading module hook 'hook-matplotlib.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 1015, in <module>
    rcParams = rc_params()
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 878, in rc_params
    return rc_params_from_file(matplotlib_fname(), fail_on_error)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 731, in matplotlib_fname
    for fname in gen_candidates():
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 728, in gen_candidates
    yield os.path.join(get_configdir(), 'matplotlibrc')
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 276, in wrapper
    ret = func(**kwargs)
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 609, in get_configdir
    return _get_config_or_cache_dir(_get_xdg_config_dir())
  File "c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\matplotlib\__init__.py", line 562, in _get_xdg_config_dir
    return os.environ.get('XDG_CONFIG_HOME') or str(Path.home() / ".config")
AttributeError: type object 'Path' has no attribute 'home'
23633 INFO: Loading module hook 'hook-numpy.core.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
23756 INFO: Loading module hook 'hook-numpy.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
23758 INFO: Loading module hook 'hook-PIL.Image.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24366 INFO: Loading module hook 'hook-PIL.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24382 INFO: Import to be excluded not found: 'PyQt4'
24382 INFO: Import to be excluded not found: 'PySide'
24382 INFO: Excluding import 'tkinter'
24401 INFO:   Removing import of tkinter from module PIL.ImageTk
24404 INFO: Import to be excluded not found: 'FixTk'
24404 INFO: Excluding import 'PyQt5'
24426 INFO:   Removing import of PyQt5 from module PIL.ImageQt
24429 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24429 INFO: Import to be excluded not found: 'FixTk'
24449 INFO: Excluding import 'tkinter'
24463 INFO: Loading module hook 'hook-pkg_resources.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
24987 INFO: Processing pre-safe import module hook win32com from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-win32com.py'.
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
25088 INFO: Processing pre-safe import module hook win32com from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-win32com.py'.
Traceback (most recent call last):
  File "<string>", line 2, in <module>
ModuleNotFoundError: No module named 'win32com'
25410 INFO: Excluding import '__main__'
25414 INFO:   Removing import of __main__ from module pkg_resources
25415 INFO: Loading module hook 'hook-pycparser.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
25432 INFO: Loading module hook 'hook-setuptools.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26113 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26129 INFO: Loading module hook 'hook-xml.dom.domreg.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26129 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26144 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26144 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks'...
26383 INFO: checking Tree
26389 INFO: Building Tree because Tree-00.toc is non existent
26397 INFO: Building Tree Tree-00.toc
26542 INFO: checking Tree
26542 INFO: Building Tree because Tree-01.toc is non existent
26545 INFO: Building Tree Tree-01.toc
26654 INFO: Looking for ctypes DLLs
26732 INFO: Analyzing run-time hooks ...
26732 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
26748 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
26780 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
26786 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_mplconfig.py'
26797 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_mpldata.py'
26814 INFO: Including run-time hook 'c:\\users\\jakub\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_certifi.py'
26851 INFO: Looking for dynamic libraries
27717 INFO: Looking for eggs
27717 INFO: Using Python library c:\users\jakub\appdata\local\programs\python\python38-32\python38.dll
27717 INFO: Found binding redirects:
[]
27748 INFO: Warnings written to C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\warn-Koronawirus.txt
28024 INFO: Graph cross-reference written to C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\xref-Koronawirus.html
28169 INFO: checking PYZ
28170 INFO: Building PYZ because PYZ-00.toc is non existent
28172 INFO: Building PYZ (ZlibArchive) C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\PYZ-00.pyz
30186 INFO: Building PYZ (ZlibArchive) C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\PYZ-00.pyz completed successfully.
30223 INFO: checking PKG
30223 INFO: Building PKG because PKG-00.toc is non existent
30226 INFO: Building PKG (CArchive) PKG-00.pkg
30265 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
30269 INFO: Bootloader c:\users\jakub\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\bootloader\Windows-32bit\run.exe
30277 INFO: checking EXE
30279 INFO: Building EXE because EXE-00.toc is non existent
30284 INFO: Building EXE from EXE-00.toc
30297 INFO: Appending archive to EXE C:\Users\jakub\Desktop\Programming\Python files\Koronawirus\build\Koronawirus\Koronawirus.exe
30322 INFO: Building EXE from EXE-00.toc completed successfully.
30336 INFO: checking COLLECT
30337 INFO: Building COLLECT because COLLECT-00.toc is non existent
30345 INFO: Building COLLECT COLLECT-00.toc
36861 INFO: Building COLLECT COLLECT-00.toc completed successfully.
PS C:\Users\jakub\Desktop\Programming\Python files\Koronawirus>
Brett Cannon
  • 14,438
  • 3
  • 45
  • 40
  • Try renaming your file to `main.py` and if you have any second level imports correct that as well – kaktus_car May 06 '20 at 12:57
  • What do you mean by correcting second level imports? – Jakub Kędzior May 07 '20 at 13:55
  • Here is explained in detail https://stackoverflow.com/questions/7436132/pyinstaller-spec-file-importerror-no-module-named-blah – kaktus_car May 07 '20 at 15:14
  • 1
    Thanks for your answer but it's not that. Clearly the problem lays within matplotlib. It had worked before and other imports work. All these programs of mine work but without the plots part. Also when I create a new project and include just matplotlib but code simple print('hello world') it doesn't launch/work as well. – Jakub Kędzior May 09 '20 at 18:13
  • No problem, I hope you will find a way to achieve your goal. – kaktus_car May 09 '20 at 18:35

3 Answers3

0

I had the exact same error as you.

When execute exe file, it shut down without any errorcode

I can fix it by removing anaconda environment

If it is an anaconda development environment, replace it to common python environment.

0

Check if you have Visual C++ Redistributable Package (vc_redist.x64.exe) installed on the machine where you use pyinstaller before you build the executable. See Error after using PyInstaller for script with Matplotlib

user2380383
  • 174
  • 1
  • 8
0

I was able to fix this problem by performing pip uninstall pathlib while in the environment from which I use pyinstaller.

This should work for anyone using python >=3.5

The cause of the problem is that from python 3.5 and later, pathlib comes bundled with all the standard libraries of python. This will be the newer version that has Path.home(). However, if for some reason, like me, you have pathlib also installed as an independent package via pip, it will be the older version that doesn't have pathlib.Path.home(), and therefore breaks when home() is called.

Before uninstalling pathlib with pip uninstall pathlib make sure that:

  1. You actually have python >= 3.5 by running python --version.
  2. That you actually have a redundant installation of the "old" pathlib by running pip show pathlib
Dharman
  • 30,962
  • 25
  • 85
  • 135
Elegant Code
  • 678
  • 6
  • 18