bndr / pipreqs

pipreqs - Generate pip requirements.txt file based on imports of any project. Looking for maintainers to move this project forward.
Apache License 2.0
6.38k stars 388 forks source link

SyntaxError: invalid non-printable character #282

Closed oguh43 closed 2 years ago

oguh43 commented 3 years ago

Code can not contain characters with diacritics (á,é,ô,ň), else pipreqs breaks.

oguh43 commented 3 years ago

Example line: https://github.com/oguh43/bilicka/blob/master/2021_inf/2021_inf_2.py#L66

fzeiser commented 2 years ago

The line you link does not have diacritics (you link to master, probably another line now.) Did you try to provide the correct encoding via the command line option of pipreqs?

Some useful commands: In my case, the error was SyntaxError: invalid non-printable character U+FEFF, which hint to a (unnecessary) BOM character for UTF-8. Instead of providing UTF-8-SIG as encoding, I changes the file(s) to remove the BOM.

# Detect char encoding
> chardetect myfile.py
myfile.py: UTF-8-SIG with confidence 1.0

# Remove BOM of one file
> sed -i '1s/^\xEF\xBB\xBF//'  myfile.py

# Or of all python files (this might require zsh?, but you can find ways around using find, xarg, ...
> sed -s -i '1s/^\xEF\xBB\xBF//'  **/*.py

# check encoding again'
> chardetect myfile.py
myfile.py: utf-8 with confidence 0.99

`