使用“导入python模块目录”;“空间”;烧焦

使用“导入python模块目录”;“空间”;烧焦,python,python-import,python-module,Python,Python Import,Python Module,我想导入当前文件目录中名为DataGenerator的类: /content/gdrive/My Drive/mrcnn_fire/ssd/python_files/object_detection_2d_data_generator.py 我导入的内容如下: from content.gdrive.My Drive.mrcnn_fire.ssd.python_files.object_detection_2d_data_generator import DataGenerator 它给了我

我想导入当前文件目录中名为DataGenerator的类:

/content/gdrive/My Drive/mrcnn_fire/ssd/python_files/object_detection_2d_data_generator.py
我导入的内容如下:

from content.gdrive.My Drive.mrcnn_fire.ssd.python_files.object_detection_2d_data_generator import DataGenerator
它给了我以下错误:

File "<ipython-input-3-7d861f8abbeb>", line 4
    from content.gdrive.My Drive.mrcnn_fire.ssd.python_files.object_detection_2d_data_generator import DataGenerator
                               ^
SyntaxError: invalid syntax
文件“”,第4行
从content.gdrive.My Drive.mrcnn_fire.ssd.python_files.object_detection_2d_data_generator导入数据生成器
^
SyntaxError:无效语法

您也可以这样尝试:

# object_detection_2d_data_generator.py
import sys
sys.path.insert(0, '/content/gdrive/My Drive/mrcnn_fire/ssd/python_files')

from object_detection_2d_data_generator import DataGenerator

您可以通过以下方式导入它:

# object_detection_2d_data_generator.py
import sys
sys.path.insert(0, '/content/gdrive/My Drive/mrcnn_fire/ssd/python_files')

from object_detection_2d_data_generator import DataGenerator
DataGenerator=\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu

主脚本是否也在
/content/gdrive/My Drive/mrcnn\u fire/ssd/python\u文件中?如果是这样,请尝试在不使用路径的情况下导入:
from object\u detection\u 2d\u data\u generator import DataGenerator
主脚本的可能副本不在同一目录下文件名是模块名,但这意味着文件名必须遵守Python的模块名规则:不允许使用空格。您可以导入模块,而不是任意文件。