pythonpip

pip install of pyinstaller throws UnicodeEncodeError


I am trying to install PyInstaller and when I use pip install PyInstaller it doesn't work.

I also tried to download the ZIP and install the requirements with pip install -r requirements.txt but that didn't work either...

Collecting pyinstaller
  Using cached https://files.pythonhosted.org/packages/03/32/0e0de593f129bf1d1e77eed562496d154ef4460fd5cecfd78612ef39a0cc/PyInstaller-3.4.tar.gz
ERROR: Exception:
Traceback (most recent call last):
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\cli\base_command.py", line 178, in main
    status = self.run(options, args)
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\commands\install.py", line 352, in run
    resolver.resolve(requirement_set)
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\resolve.py", line 131, in resolve
    self._resolve_one(requirement_set, req)
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\resolve.py", line 294, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\resolve.py", line 242, in _get_abstract_dist_for
    self.require_hashes
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 362, in prepare_linked_requirement
    abstract_dist.prep_for_dist(finder, self.build_isolation)
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\operations\prepare.py", line 144, in prep_for_dist
    self.req.build_env = BuildEnvironment()
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\site-packages\pip\_internal\build_env.py", line 105, in __init__
    ).format(system_sites=system_sites, lib_dirs=self._lib_dirs))
  File "c:\users\Rom\appdata\local\programs\python\python37\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode characters in position 148-150: character maps to <undefined>

I expected it to work even though it had one exception because when I try again it says that all of the requirements are satisfied :P

I am sorry it's so messy, I just really don't know what to do :'(


Solution

  • Since you're on Windows, try installing the PyInstaller wheel from Christoph Gohlke's website: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyinstaller

    Unfortunately he has disabled linking directly to wheels on his website, so you have to physically go there and download the wheel yourself. You'll see a link to PyInstaller‑3.4‑py2.py3‑none‑any.whl when you visit the above link. Click on the link to download the wheel directly, then in the Command Prompt, navigate to where you downloaded it and do:

    pip install PyInstaller‑3.4‑py2.py3‑none‑any.whl
    

    This should get it installed!


    Edit

    It seems that the trouble you're facing once you install the package is a well-known one in Windows: https://github.com/pyinstaller/pyinstaller/issues/310

    The solution is to insert this code at the beginning before you do anything:

    import sys
    import codecs
    sys.stdout = codecs.getwriter('utf8')(sys.stdout) 
    

    It has something to do with the source code of PyInstaller where it's in an encoding scheme that is different on your machine from how it was originally developed.