Python 导入错误,即使文件明显位于路径中

Python 导入错误,即使文件明显位于路径中,python,ubuntu,amazon-ec2,import,python-import,Python,Ubuntu,Amazon Ec2,Import,Python Import,我正在运行一个脚本,并收到错误信息: Traceback (most recent call last): File "common/tensorflow/run_tf_benchmark.py", line 30, in <module> from common.base_benchmark_util import BaseBenchmarkUtil ModuleNotFoundError: No module named 'common' 注意,目录中还有其他文件,

我正在运行一个脚本,并收到错误信息:

Traceback (most recent call last):
  File "common/tensorflow/run_tf_benchmark.py", line 30, in <module>
    from common.base_benchmark_util import BaseBenchmarkUtil
ModuleNotFoundError: No module named 'common'
注意,目录中还有其他文件,但这些是相关的python文件。 目前,run_tf_benchmark.py顶部的导入是

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


import sys
sys.path.append('/home/ubuntu/benchmark_models/benchmarks/common')
print(sys.path)
from argparse import ArgumentParser
from common.base_benchmark_util import BaseBenchmarkUtil
打印的sys.path为

['/home/ubuntu/benchmark_models/benchmarks/common/tensorflow', '/home/ubuntu/src/cntk/bindings/python',
 '/home/ubuntu/benchmark_models/models/image_recognition/tensorflow/mobilenet_v2', '/home/ubuntu/models',
 '/home/ubuntu/models/research', '/home/ubuntu/models/research/slim', 
'/home/ubuntu/anaconda3/lib/python36.zip', '/home/ubuntu/anaconda3/lib/python3.6', 
'/home/ubuntu/anaconda3/lib/python3.6/lib-dynload', '/home/ubuntu/anaconda3/lib/python3.6/site-packages',
 '/home/ubuntu/benchmark_models/benchmarks/common']


我可以清楚地看到python路径中的常见错误,但是导入错误仍然会发生。我做错了什么?

导入时只需删除“common”,因为您已经在“common”目录中

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


import sys
sys.path.append('/home/ubuntu/benchmark_models/benchmarks/common')
print(sys.path)
from argparse import ArgumentParser
from base_benchmark_util import BaseBenchmarkUtil

好吧,我解决了这个问题。问题是我添加了/home/ubuntu/benchmark\u models/benchmarks/common,而不是/home/ubuntu/benchmark\u models/benchmarks/。通过导入基准测试,它还允许我的所有其他代码导入公共代码

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


import sys
sys.path.append('/home/ubuntu/benchmark_models/benchmarks/common')
print(sys.path)
from argparse import ArgumentParser
from base_benchmark_util import BaseBenchmarkUtil