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

Doesn't work for me. Getting all sorts of errors. #412

Closed futuremotiondev closed 11 months ago

futuremotiondev commented 11 months ago

Here are my commands and output:

11-03 04:10:10 D:\Dev\Python\00 VENV\DomColors> .\Scripts\activate.ps1
(DomColors) 11-03 04:10:16 D:\Dev\Python\00 VENV\DomColors> pipreqs .
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Python\Python311\scripts\pipreqs.exe\__main__.py", line 7, in <module>
  File "C:\Python\Python311\Lib\site-packages\pipreqs\pipreqs.py", line 528, in main
    init(args)
  File "C:\Python\Python311\Lib\site-packages\pipreqs\pipreqs.py", line 455, in init
    candidates = get_all_imports(input_path,
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Python311\Lib\site-packages\pipreqs\pipreqs.py", line 115, in get_all_imports
    contents = f.read()
               ^^^^^^^^
  File "C:\Python\Python311\Lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 24359: character maps to <undefined>
(DomColors) 11-03 04:10:25 D:\Dev\Python\00 VENV\DomColors>

The VENV is using: Python 3.11.6 (tags/v3.11.6:8b6ee5b, Oct 2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)] on win32

Here are the dependencies from running pip list:

Package            Version
------------------ ------------
certifi            2023.7.22
charset-normalizer 3.3.2
colorama           0.4.6
colorclass         2.2.2
colorthief         0.2.1
contourpy          1.1.1
cycler             0.12.1
docopt             0.6.2
fonttools          4.43.1
idna               3.4
imageio            2.31.6
joblib             1.3.2
kiwisolver         1.4.5
lazy_loader        0.3
matplotlib         3.8.1
networkx           3.2.1
numpy              1.26.1
opencv-python      4.8.1.78
packaging          23.2
pandas             2.1.2
Pillow             10.0.1
pip                23.3.1
pip-upgrader       1.4.15
pyparsing          3.1.1
python-dateutil    2.8.2
pytz               2023.3.post1
PyWavelets         1.4.1
requests           2.31.0
scikit-image       0.22.0
scikit-learn       1.3.2
scipy              1.11.3
setuptools         68.2.2
six                1.16.0
terminaltables     3.1.10
threadpoolctl      3.2.0
tifffile           2023.9.26
tzdata             2023.3
urllib3            2.0.7
wheel              0.41.3

Any way to get this working properly? Can I help with reproducing this error? Any assistance would be warmly welcomed.

Thanks, Jay

alan-barzilay commented 11 months ago

You have to figure out your file encoding to fix this issue, it is using a character not recognized by the default encoding. A good first attempt is to try utf-8

futuremotiondev commented 11 months ago

I don't exactly understand how to do that. Do you mean use the --encoding flag for pipreqs and set it to UTF-8? Or is there another setting for python itself that I need to change? I thought I was using UTF-8 for everything.

Also, how can I find out exactly what character is not being recognized?

I apologize, but can you give me just a little more information?

alan-barzilay commented 11 months ago

Do you mean use the --encoding flag for pipreqs and set it to UTF-8?

yes, --encoding="utf-8". No idea why this isnt the default but it will be starting from next release

Also, how can I find out exactly what character is not being recognized?

Sadly this error message wasnt that helpful, the character is this one: byte 0x81 in position 24359. But that doesn't really help us haha maybe if you knew the file that is raising this issue.

btw, from your output I guess you are using this encoding at the moment: cp1252

Sorry I cant be of more help :/ maybe running with skip-errors could give you at least a partial requirements file if changing the encoding doesn't work? I'm out of ideas haha but good luck