pipreqs: Error while creating requirements.txt

Hello!

C:\Users\ipetrash\Desktop\PyScripts\hideme.ru-proxy-list>pipreqs C:\Users\ipetrash\Desktop\PyScripts\hideme.ru-proxy-list
Traceback (most recent call last):
  File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\Python34\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Python34\Scripts\pipreqs.exe\__main__.py", line 9, in <module>
  File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 178, in main
    init(args)
  File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 157, in init
    local = get_import_local(candidates)
  File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 112, in get_import_local
    local = get_locally_installed_packages()
  File "C:\Python34\lib\site-packages\pipreqs\pipreqs.py", line 105, in get_locally_installed_packages
    'version': package[1].replace(".dist", ""),
IndexError: list index out of range

Used for: https://github.com/gil9red/hideme.ru-proxy-list

Sincerely yours, gil9red

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 2
  • Comments: 23 (6 by maintainers)

Most upvoted comments

For others who might have similar problem. utf-8 have not worked for me, but with iso-8859-1 it worked: pipreqs --encoding=iso-8859-1 ./

–encoding=utf-8 worked. I’m still reviewing the .txt, I think it’s actually correct.

Can you post the generated requirements.txt? Can you try with --encoding=utf-8 options, and see if the error persists

Same issue for me in Linux Mint 17. Some debug info:

$ cat /etc/*issue*

Linux Mint 17 Qiana \n \l

Ubuntu 14.04.4 LTS \n \l

Linux Mint 17 QianaUbuntu 14.04.4 LTS
$ pipreqs --version
0.4.3

$ pipreqs --debug ~/Documents/scripts/
DEBUG: Found packages: set(['__future__', 'bs4', 'functools', 'datetime', 'contextlib', 'tldextract', 'io', 'xml', 'IPy', 'whois', 'urllib', 're', 'json', 'pandas', 'math', 'string', 'urllib2', 'sys', 'jinja2', 'subprocess', 'socket', 'signal', 'urlparse', 'itertools', 'time', 'os', 'multiprocessing'])
DEBUG: Found imports: IPy, beautifulsoup4, Jinja2, pandas, tldextract, whois
DEBUG: Getting packages information from Local/PyPI
Traceback (most recent call last):
  File "/usr/local/bin/pipreqs", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/pipreqs/pipreqs.py", line 253, in main
    init(args)
  File "/usr/local/lib/python2.7/dist-packages/pipreqs/pipreqs.py", line 228, in init
    local = get_import_local(candidates, encoding=encoding)
  File "/usr/local/lib/python2.7/dist-packages/pipreqs/pipreqs.py", line 167, in get_import_local
    local = get_locally_installed_packages()
  File "/usr/local/lib/python2.7/dist-packages/pipreqs/pipreqs.py", line 160, in get_locally_installed_packages
    'version': package[1].replace(".dist", "").replace(".egg",""),

@gil9red fix works for me. Patch below:

--- /usr/local/lib/python2.7/dist-packages/pipreqs/pipreqs.py.orig  2016-07-01 20:16:02.733618490 -0300
+++ /usr/local/lib/python2.7/dist-packages/pipreqs/pipreqs.py   2016-07-01 20:16:37.617619915 -0300
@@ -157,7 +157,7 @@
                             if ((i_item not in ignore) and
                                     (package[0] not in ignore)):
                                 packages[i_item] = {
-                                    'version': package[1].replace(".dist", "").replace(".egg",""),
+                                    'version': package[1].replace(".dist", "") if len(package) > 1 else None,
                                     'name': package[0]
                                 }
     return packages

This seems to have worked for me pipreqs --encoding=utf-8-sig ./

But it isn’t generating the correct requirements

Windows 10 x64, Python 3.5 x64. The same bug.