0

I want to extract data from csv for python practice.

I wrote about 30 lines of code and tried to convert .ipynb-> .py-> .exe in that order. However, UnicodeDecodeError occurred when compiling to .py-> .exe.

I commented out all the descriptions and investigated the cause, It turns out that this problem occurs just by importing pandas.

Could you tell me how to solve this problem?

=========================

[Development environment]

・jupyter notebook ・PyInstaller 3.5 ・Python 3.7.1

[Steps to reproduce]

  1. Create an empty file with jupyter notebook.
  2. Write only [import pandas as pd] in the first line.
  3. Convert to [Test001.py]. Command line: jupyter nbconvert --to script Test001.ipynb
  4. Compile. Command line: pyinstaller Test001.py --onefile --noconsole

[Error]

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 130: invalid start byte

[Test001.py]

#!/usr/bin/env python
# coding: utf-8

# In[ ]:

import pandas as pd

[Traceback]

Traceback (most recent call last):
    File "c:\programdata\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
    File "c:\programdata\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
    File "C:\ProgramData\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 111, in run
run_build(pyi_config, spec_file, **vars(args))
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 844, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 791, in build
exec(code, spec_namespace)
    File "C:\Users\******\python_workspace\Test001.spec", line 17, in <module>
noarchive=False)
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 243, in __init__
self.__postinit__()
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
self.assemble()
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 502, in assemble
module_hook.post_graph()
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
self._load_hook_module()
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
self.hook_module_name, self.hook_filename)
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\compat.py", line 793, in importlib_load_source
return mod_loader.load_module()
    File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
    File "<frozen importlib._bootstrap_external>", line 907, in load_module
    File "<frozen importlib._bootstrap_external>", line 732, in load_module
    File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
    File "<frozen importlib._bootstrap>", line 696, in _load
    File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 728, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\hooks\hook-zmq.py", line 18, in <module>
hiddenimports = ['zmq.utils.garbage'] + collect_submodules('zmq.backend')
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 624, in collect_submodules
repr(pkg_dir), package))
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 83, in exec_statement
return __exec_python_cmd(cmd)
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 72, in __exec_python_cmd
txt = exec_python(*cmd, env=pp_env)
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\compat.py", line 637, in exec_python
return exec_command(*cmdargs, **kwargs)
    File "c:\programdata\anaconda3\lib\site-packages\PyInstaller\compat.py", line 427, in exec_command
out = out.decode(encoding)
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x83 in position 130: invalid start byte

=========================

Thanks,

Hisa

Hisa
  • 11
  • 1
  • What does the Test001.py file look like when you open it in Notepad? – KWx Oct 01 '19 at 00:45
  • https://stackoverflow.com/questions/41570359/how-can-i-convert-a-py-to-exe-for-python – P.hunter Oct 01 '19 at 00:47
  • 1
    always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Oct 01 '19 at 00:56
  • @KWx I added the contents of the file to the question text. – Hisa Oct 01 '19 at 01:21
  • @furas, I added the contents of Traceback to the question text. – Hisa Oct 01 '19 at 01:22
  • @P.hunter, I tried the method you taught me. The exe file was successfully generated. This topic will be closed. – Hisa Oct 01 '19 at 05:53

1 Answers1

0

I continued to investigate PyInstaller issues for solutions.

There was a report that it was solved by rewriting a part of 'compat.py', so I tried it. As a result, the executable file was output normally. (I confirmed that it works properly on another computer)

The link of the site which became reference is as follows.

https://qiita.com/mamon/items/01e5dc5c24cf9e81b689

Thank you for your comments.

Hisa

Hisa
  • 11
  • 1