【发布时间】:2020-04-11 22:06:32
【问题描述】:
我正在尝试在 google colab 上运行 main.py 文件,但由于我放置的目录而出现错误。我已将路径作为包含 .py 文件的文件夹。我已将该目录作为包含图像的文件夹,但我收到此错误。
python3: can't open file '/content/gdrive/My': [Errno 2] No such file or directory
代码:
import os
path = '/content/gdrive/My Drive/picture-scraper' #Where the .py files are located
os.chdir(path)
directory = '/content/gdrive/My Drive/Car Dataset' #Where the images are located
files = ['scrape', 'tag', 'save', 'select']
if __name__ == '__main__':
if not os.path.isdir(directory):
os.mkdir(directory)
[os.system('python ' + path + f'{file}.py ' + directory) for file in files]
【问题讨论】:
-
尝试使用
path = r"/content/gdrive/My Drive/picture-scraper"和directory = r"/content/gdrive/My Drive/Car Dataset" -
和以前一样的错误
-
如果你读到错误(
can't open file '/content/gdrive/My'),它只会抱怨部分路径,所以我猜,它无法读取完整路径,因为空间。 -
试试
'"/content/gdrive/My Drive/picture-scraper"'(注意双引号)
标签: python path google-colaboratory