Libmagic cannot be found when pyinstaller packages resource files and contains the eyed3 Module

Source: Internet
Author: User
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
  1. 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
  1. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.