Error in pipreqs due to Python 2-style print statements when running in Google Colab #8

Closed
opened 2025-04-09 14:58:29 +00:00 by tcsenpai · 0 comments
Owner

Originally created by @harichselvamc on 3/29/2025

I encountered an issue while trying to generate a requirements.txt file using pipreqs in Google Colab. The tool fails due to a SyntaxError in one of the Python files that uses Python 2-style print statements (without parentheses). This issue arises when pipreqs tries to parse files in the project that are not fully compatible with Python 3.

ERROR: Failed on file: ./path/to/your/script.py
Traceback (most recent call last):
  File "/usr/local/bin/pipreqs", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pipreqs/pipreqs.py", line 609, in main
    init(args)
  File "/usr/local/lib/python3.11/dist-packages/pipreqs/pipreqs.py", line 533, in init
    candidates = get_all_imports(
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/pipreqs/pipreqs.py", line 153, in get_all_imports
    tree = ast.parse(contents)
           ^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 45
    print "\n"
    ^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? 


Image

*Originally created by @harichselvamc on 3/29/2025* I encountered an issue while trying to generate a requirements.txt file using pipreqs in Google Colab. The tool fails due to a SyntaxError in one of the Python files that uses Python 2-style print statements (without parentheses). This issue arises when pipreqs tries to parse files in the project that are not fully compatible with Python 3. ``` ERROR: Failed on file: ./path/to/your/script.py Traceback (most recent call last): File "/usr/local/bin/pipreqs", line 8, in <module> sys.exit(main()) ^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pipreqs/pipreqs.py", line 609, in main init(args) File "/usr/local/lib/python3.11/dist-packages/pipreqs/pipreqs.py", line 533, in init candidates = get_all_imports( ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/pipreqs/pipreqs.py", line 153, in get_all_imports tree = ast.parse(contents) ^^^^^^^^^^^^^^^^^^^ File "<unknown>", line 45 print "\n" ^^^^^^^^^^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? ``` ![Image](https://github.com/user-attachments/assets/2baf3f6e-fc79-4982-ba2f-d533a67866aa)
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/pipreqs#8
No description provided.