Python 我需要帮助将模块从同级文件夹导入测试

Python 我需要帮助将模块从同级文件夹导入测试,python,python-3.x,jupyter-notebook,Python,Python 3.x,Jupyter Notebook,当我尝试导入模块时,出现导入错误“无法导入模块” 文件结构 src modules __init__.py authenticate_developer twttier_importer notebooks main.ipynb unit_tests test_authenticate_developer 在测试中\u验证\u开发人员 import requests from nose.tools

当我尝试导入模块时,出现导入错误“无法导入模块”

文件结构

src
    modules
    __init__.py
        authenticate_developer
        twttier_importer
    notebooks
        main.ipynb
    unit_tests
        test_authenticate_developer
在测试中\u验证\u开发人员

import requests
from nose.tools import assert_true
import os
import sys
sys.path.append(os.path.abspath('../modules'))
import settings
import twitter_importer #returns import error
import authenticate_developer #returns import error
import os,sys,inspect
sys.path.append(os.path.abspath('../modules'))
#This is to access the parent folder in order to import config
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)

import config
from modules.authenticate_developer import Authenticate
然而,当我在笔记本中使用相同的语法时,它是成功的

import sys
import os
sys.path.append(os.path.abspath('../modules'))
sys.path.append(os.path.abspath('../'))
import twitter_importer
import authenticate_developer
import settings

我已经查看了现有答案,并尝试了它们,即从根文件夹中删除init.py,然后将init.py删除或添加到tests文件夹。似乎没有一个对我有效。

我设法找人帮我解决这些问题,这就是我们解决问题的方法

 src
    modules
    __init__.py
        authenticate_developer
        twttier_importer
    notebooks
        main.ipynb
    unit_tests
    __init__.py
        test_authenticate_developer
在测试中\u验证\u开发人员

import requests
from nose.tools import assert_true
import os
import sys
sys.path.append(os.path.abspath('../modules'))
import settings
import twitter_importer #returns import error
import authenticate_developer #returns import error
import os,sys,inspect
sys.path.append(os.path.abspath('../modules'))
#This is to access the parent folder in order to import config
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)

import config
from modules.authenticate_developer import Authenticate

我无法解释为什么我必须在测试文件中做不同的操作,但这是我的工作

请将代码作为文本而不是图像发布。这使我们更容易复制问题。@Sid感谢您的反馈。我用文字编辑过