6

I'm using PyInstaller to compile a program and keep coming across the error "No module named 'charset_normalizer.md__mypyc.'" The Charset-Normalizer package is installed.

As a test, I tried re-compiling a program that I had previously created in early September without issue, but now receive the same error. I thought that maybe there is an issue with the versions of either PyInstaller or Charset-Normalizer so I've experimented with different versions, but cannot get it to work.

PythonNewbie
  • 61
  • 1
  • 1
  • 2

7 Answers7

11

You are probably missing the "chardet" library I installed it and it worked.

pip install chardet
CodeMed
  • 9,527
  • 70
  • 212
  • 364
Dragon Kush
  • 121
  • 4
  • Your comment says "Charted" but your code sample says "Chardet" I assume one is correct and the other is not? – Kevon Nov 03 '22 at 22:29
  • Chardet is LGPL, so bundling it with pyinstaller means you should release the source code of your app. charset-normalizer is not LGPL and replaces chardet, so there's a good reason not to install chardet. – Carl Walsh May 18 '23 at 22:03
4

I had the EXACT problem. Scripts that I was able to make into executables using Pyinstaller before I could no longer do so again. In my script I used the pdfplumber package, which when you install it also installs other packages like pillow, wand, charset-normalizer, etc.

Since the error was regarding charset-normalizer for me as well, I tried different versions of it. For me it was version 2.1.0 that made the executable work again. Install it with the "pip install charset-normalizer==2.1.0" command: https://pypi.org/project/charset-normalizer/2.1.0/.

If it does not work, go to "Release history" on that link and try another version. Try to remember when was the last time you created a working executable and get the version you think will work for you.

Alina
  • 41
  • 1
4

This worked for me:

I just added

from charset_normalizer import md__mypyc

to the top of my python script.

https://stackoverflow.com/a/58449206/20576777

If you don't have the charset-normalizer library installed, then you should install it using the following command:

pip install charset-normalizer
BlaziWazi
  • 41
  • 1
3

Pyinstaller may sometimes miss your dependency. In such a case run pyinstaller with the --collect-all option. In this case --collect-all charset_normalizer should force pyinstaller to include the dependency.

Oron Port
  • 467
  • 3
  • 11
1

This error is expected because of the way pyinstaller works.

To fix it, pass the pyinstaller CLI flag: --hidden-import charset_normalizer.md__mypyc

Or, if using SPEC file, set the hiddenimports param passed to Analysis:

     a = Analysis(['minimal.py'],
         pathex=['/Developer/PItests/minimal'],
         binaries=None,
         datas=None,
         hiddenimports=["charset_normalizer.md__mypyc"],
         hookspath=None,
         runtime_hooks=None,
         excludes=None,
         cipher=block_cipher)

See https://github.com/Ousret/charset_normalizer/blob/master/docs/community/faq.rst#i-cant-build-standalone-executable for more context.

Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
0

I got it to work by installing older versions of PyInstaller and Charest-Normalizer. Anytime this messages pops-up, consider installing an older version of the package.

PythonNewbie
  • 61
  • 1
  • 1
  • 2
0

I have already installed chardet and charset-normalizer, but I still had the problem. Then I saw this Github issue. As suggested by IsraelAbebe, I solved the problem by

python -m pip install charset-normalizer==2.1.0
Wey Shi
  • 1,552
  • 1
  • 9
  • 15