오류

INFO: Not scanning for jupyter notebooks.
<unknown>:165: SyntaxWarning: invalid escape sequence '\S'
<unknown>:166: SyntaxWarning: invalid escape sequence '\['
<unknown>:207: SyntaxWarning: invalid escape sequence '\['
<unknown>:456: SyntaxWarning: invalid escape sequence '\S'
Traceback (most recent call last):
  File "/Users/bokyung/beautiful-connector/nnt/bin/pipreqs", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/bokyung/beautiful-connector/nnt/lib/python3.12/site-packages/pipreqs/pipreqs.py", line 609, in main
    init(args)
  File "/Users/bokyung/beautiful-connector/nnt/lib/python3.12/site-packages/pipreqs/pipreqs.py", line 533, in init
    candidates = get_all_imports(
                 ^^^^^^^^^^^^^^^^
  File "/Users/bokyung/beautiful-connector/nnt/lib/python3.12/site-packages/pipreqs/pipreqs.py", line 136, in get_all_imports
    contents = read_file_content(file_name, encoding)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bokyung/beautiful-connector/nnt/lib/python3.12/site-packages/pipreqs/pipreqs.py", line 181, in read_file_content
    contents = f.read()
               ^^^^^^^^
  File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 81: invalid start byte
  • 프로젝트에서 사용하는 라이브러리만 requirements.txt로 저장하기 위해 pipreqs . --force 명령어를 사용했는데 위 오류 발생

해결

가상환경 문제였음 !

  • 구글링 했을 때 --ignore bin,etc,include,lib,lib64 옵션을 추가하라는 글이 많았는데, 해당 옵션을 추가하면 오류는 발생하지 않지만 제대로 라이브러리가 저장되지 않았음
  • 가상환경 폴더 내에 bin, include, lib, share 폴더가 포함되어있어서 사실 유사한 해결 방식인 것 같긴 하지만..! 나는 가상환경 폴더를 ignore 했을 때 원하는 결과가 저장됨
pipreqs --encoding utf-8 . --force --ignore ./{venv}