Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipreqs: SyntaxError: invalid non-printable character U+FEFF

Tags:

python

pip

When I try to run pipreqs /path/to/project it comes back with

  File "<unknown>", line 1
    # !/usr/bin/env python3
    ^
SyntaxError: invalid non-printable character U+FEFF

my project contains a number of files and all of them contain their own imports. I read somewhere that it could be an issue to create a requirements.txt for a number of files so I tried to move the main file into a new dir and run pipreqs on there but again no success.

my imports look like so:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#######################################################
# Initialise Wikipedia agent
#######################################################
import requests
import json
import aiml
import wikipedia
import numpy as np
from nltk.sem.logic import *
from nltk.inference.resolution import *
from nltk.inference import ResolutionProver
from nltk.inference.nonmonotonic import *
from nltk import *
from nltk.sem import logic
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import pandas as pd
from fuzzywuzzy import fuzz
import tkinter as tk
from tkinter import filedialog
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
from msrest.authentication import CognitiveServicesCredentials
import tensorflow_hub as hub

Anyone has any ideas on what it could be? Any help would be much appreciated :)

Edit:

Forgot to specify: Running Python 3.9.10 and pipreqs was installed using pip3

like image 525
jaykay Avatar asked Sep 03 '25 03:09

jaykay


1 Answers

The character U+FEFF is the byte order marker, or BOM.

You can save a text file in UTF encoding with or without BOM, and the error message seems to suggest your system can deal with UTF, but doesn't like the BOM, so you should try rewriting the file without BOM.

Alternatively, there's ways to tell Python to expect a different encoding on the command line with environment variables, but I wouldn't go there unless you absolutely must and have no control over the encoding of the file yourself.

like image 121
Grismar Avatar answered Sep 04 '25 15:09

Grismar