找不到文件(.json)

问题描述 投票:0回答:1

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 json python-requests ocr google-vision
1个回答
0
投票

这可能是因为Python进程的“工作文件夹”与文件所在的位置不同。有一种很小的(尽管很复杂)的方法来生成文件名,该文件名将始终有效:

© www.soinside.com 2019 - 2024. All rights reserved.