In the past two days, I wrote a small tool in Python and used eyed3. When I packed it with pyinstaller, I was prompted that libmagic could not be found.
Version: Python 3.6.5pyinstaller 3.4python-magic-bin 0.4.14eyed3 0.88 wxpython 4.0.3
- When eyed3 is used in windows, garbled characters are displayed when the file name contains Chinese characters, prompting that the file cannot be found. solution (about magic. py 230 lines ):
if is_unicode: return filename.encode(‘utf-8‘)else: return filename
Change
if is_unicode: import locale lan, encoding = locale.getdefaultlocale() return filename.encode(encoding)else: return filename
2. How to package a resource file in pyinstall:
First, generate the spec configuration file, including the-F and-W parameters to be specified. Add Pyi-makespec [Options] myscript here. py and then edit myscript. SPEC --> datas tag, format: datas = [('res/My. ICO ', 'res'), ('file path', 'Storage path')] Final: pyinstaller myscript. spec
If getattr (sys, 'frozen ', false): respath = OS. path. join (sys. _ meipass, 'res') myicopath = OS. path. join (respath, 'My. ICO ') Note: SYS. _ meipass is the runtime path of the program after the pyinstaller package exe
- Libmagic cannot be found when the pyinstall package contains the eyed3 Module
First, pack libmagic into the EXE file datas = [('C:/users/xxxx/Python/lib/Site-packages/magic/libmagic ', 'libmagic '), (other resources)], and then modify magic. PY, about 155 rows: bin_dist_path = OS. path. join (OS. path. dirname (_ file _), 'libmagic ') to: If getattr (sys, 'frozen', false): bin_dist_path = OS. path. join (sys. _ meipass, 'libmagic ') else: bin_dist_path = OS. path. join (OS. path. dirname (_ file _), 'libmagic ')
If you are worried that modifying this file will affect the use of other projects, copy the magic. py file to the project root directory and then modify it. During packaging, the magic. py file under the project will be preferentially used.
Libmagic cannot be found when pyinstaller packages resource files and contains the eyed3 Module