This is my directory where i have activated a virtual environment
我正在研究一个烧瓶项目,以创建一个Rest API,并且我有一个JSON凭证文件(谷歌视觉文件),但是当我运行代码时,它说即使在同一目录中也找不到文件。我已经为此特定项目激活了virtualenv。 mainone.py
是我要运行的代码。
这是我得到的错误:
"File {} was not found.".format(filename)
google.auth.exceptions.DefaultCredentialsError: File date_scanner.json was not found.
这是我用来访问特定文件的代码块:
from flask import Flask,request,jsonify
import os,io,re,glob,base64
from google.cloud import vision
from google.cloud.vision import types
from PIL import Image
os.environ['GOOGLE_APPLICATION_CREDENTIALS']=r'date_scanner.json'
client=vision.ImageAnnotatorClient()
这可能是因为Python进程的“工作文件夹”与文件所在的位置不同。有一种很小的(尽管很复杂)的方法来生成文件名,该文件名将始终有效: