我正在尝试使用此代码打开文件“ xml_to_csv.py”
from google.colab import drive
drive.mount('/content/gdrive')
!sys.path.append("/content/gdrive/My Drive/TFConfig/TFmodels/research/object_detection/")
!python xml_to_csv.py
我一直收到以下答复:
Drive already mounted at /content/gdrive; to attempt to forcibly remount, call drive.mount("/content/gdrive", force_remount=True).
/bin/bash: -c: line 0: syntax error near unexpected token `"/content/gdrive/My Drive/TFConfig/TFmodels/research/object_detection/"'
/bin/bash: -c: line 0: `sys.path.append("/content/gdrive/My Drive/TFConfig/TFmodels/research/object_detection/")'
python3: can't open file 'xml_to_csv.py': [Errno 107] Transport endpoint is not connected
该错误的原因可能是什么?谢谢。
答案 0 :(得分:0)
首先,sys.path.append
是python函数。在默认外壳程序(/bin/bash
)中执行它没有多大意义。接下来,如果要向系统的变量$PATH
添加内容,则不应使用sys.path.append
。此函数修改$PYTHONPATH
变量,该变量用于定义模块文件的默认搜索路径。 (如果您想使用import
导入一些代码,则python解释器将查看PYTHONPATH
中包含的所有文件夹。在documentation中详细了解PYTHONPATH
这说明,要使用默认解释器执行python代码,最简单的方法是使用绝对路径:
!python "/content/gdrive/My Drive/TFConfig/TFmodels/research/object_detection/xml_to_csv.py"