Mac 版 pycharm python代码“踩坑”记录一

pycharm版本:2019.3.3 Mac 专业版

pycharm调试python代码出现了一个“奇葩”的错误,代码节选如下:第四行代码“from config.setting import config ”中,“config”显示红色波浪线

import unittest
import ddt

from xxx_xx_x.common.excel_handler import ExcelHandler
from xxx_xx_x.config.setting import config@ddt.ddt
class TestRegister(unittest.TestCase):

    # 读取数据
    excel_handler = ExcelHandler(config.data_path)
    data = excel_handler.read('register')

    @ddt.data
    def test_register(self, test_data):
        print(test_data)

右键运行该段代码出现如下错误:ModuleNotFoundError: No module named 'xxx_xx_x'

改动后代码如下:第四行代码“from config.setting import config ”中,“config”依旧显示红色波浪线

import unittest
import ddt

from common.excel_handler import ExcelHandler
from config.setting import config

@ddt.ddt
class TestRegister(unittest.TestCase):

    # 读取数据
    excel_handler = ExcelHandler(config.data_path)
    data = excel_handler.read('register')

    @ddt.data
    def test_register(self, test_data):
        print(test_data)

右键运行该段代码出现如下错误:ModuleNotFoundError: No module named 'xxx_xx_x'

把第行代码“from config.setting import config”注释掉,在第三行代码上面加上“import config”,改动后代码如下:

import unittest
import ddt
import config

from xxx_xx_x.common.excel_handler import ExcelHandler

@ddt.ddt
class TestRegister(unittest.TestCase):

    # 读取数据
    excel_handler = ExcelHandler(config.data_path)
    data = excel_handler.read('register')

    @ddt.data
    def test_register(self, test_data):
        print(test_data)

右键运行该段代码出现如下错误:

ModuleNotFoundError: No module named 'xxx_xx_x'

出在“config”上的报错依然没有解决,把代码拷贝只winsows平台,运行正常。

至此,可以肯定的是,不是代码的问题,而是pycharm工具的问题,在pycharm里面把相关模块和代码删了,然后重建和重写,最后右键运行,通过

发布了21 篇原创文章 · 获赞 21 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/a768818702/article/details/104766132
今日推荐