首页 > 解决方案 > Google Colab 没有此类文件或目录错误

问题描述

您好,我正在尝试在 google colab 上开始 tensorflow 训练过程。我正在尝试在 google colab 的集成笔记本中运行此代码块。代码块是:

!apt-get install protobuf-compiler python-pil python-lxml python-tk
!pip install Cython
%cd '/content/gdrive/My Drive/models/research/'
!protoc object_detection/protos/*.proto --python_out=.

import os
os.environ['PYTHONPATH'] += ':/content/gdrive/My Drive/models/research/:/content/gdrive/My Drive/models/research/slim'

!python setup.py build
!python setup.py install

它给出了这个输出:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
protobuf-compiler is already the newest version (3.0.0-9.1ubuntu1).
python-lxml is already the newest version (4.2.1-1ubuntu0.4).
python-pil is already the newest version (5.1.0-1ubuntu0.6).
python-tk is already the newest version (2.7.17-1~18.04).
0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
Requirement already satisfied: Cython in /usr/local/lib/python3.7/dist-packages (0.29.23)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
/content/gdrive/My Drive/models/research
python3: can't open file 'setup.py': [Errno 2] No such file or directory
python3: can't open file 'setup.py': [Errno 2] No such file or directory

我想我无法正确设置 python 路径。任何人都可以帮助我吗?

标签: pythontensorflowgoogle-colaboratory

解决方案


你必须先挂载你的谷歌驱动器:

from google.colab import drive
drive.mount('/content/gdrive')

试着做

import os
os.listdir(os.getcwd())

这应该返回

['.config', 'sample_data']

在安装驱动器之前,以及

['.config', 'gdrive', 'sample_data']

安装驱动器后。


推荐阅读