简体   繁体   English

如何修复 python 3.6 中的 ModuleNotFoundError

[英]How to fix ModuleNotFoundError in python 3.6

I am getting this error我收到此错误

ModuleNotFoundError: No module named 'tests' ModuleNotFoundError:没有名为“测试”的模块

This is a common error but I don't know what have don't wrong.这是一个常见的错误,但我不知道什么没有错。

This is how my file hierarchy is:这就是我的文件层次结构:

backend
   |
   '----> __init__.py
   '----> server.py
tests
   |
   '----> __init__.py
   '----> linearregression.py

I am calling predict function in linearregression.py from server.py我在server.py的 linearregression.py 中调用predict linearregression.py

This is my linearregression.py这是我的linearregression.py

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model


def predict():

    .
    .
    .

    return_this  = []
    return_this.append(price_is)
    return_this.append(gradient_is)
    return_this.append(intercept_is)
    return_this.append(str(predicted_value))

    return return_this

if __name__ == '__main__':

    returned_values = predict()

    price_is = returned_values[0]
    gradient_is = returned_values[1]
    intercept_is = returned_values[2]
    predicted_value = returned_values[3]

and here is my server.py这是我的server.py

from flask import Flask
app = Flask(__name__)

from tests.linear_regression.linearregression import predict //importing predict function here

PORT = 8083


returned_values = predict()

price_is = returned_values[0]
gradient_is = returned_values[1]
intercept_is = returned_values[2]
predicted_value = returned_values[3]

def price():
    return price_is
def gradient():
    return gradient_is
def intercept():
    return intercept_is
def predicted_value():
    return predicted_value

@app.route('/')
def hello_world():
    name = price()
    gradient = gradient()
    intercept = intercept()
    predicted_value = predicted_value()()
    return "<h1>Price is: </h1><p>"+price+"</p><br><h1>Gradient is: </h1><p>"+gradient+"</p><br><h1>Intercept is: </h1><p>"+intercept+"</p><br><h1>Predicted value is: </h1><p>"+predicted_value+"</p>"

@app.route('/banuka')
def hi():
    return "Hi Jananath"

if __name__ == '__main__':
   app.run(host='0.0.0.0', port=8083)

I am using python3.6我正在使用python3.6

Can someone help me what have I done wrong?有人可以帮我做错什么吗?

Did you installed the "scikit-learn" library correctly?您是否正确安装了“scikit-learn”库?
If not them install it by using pip by running pip install scikit-learn .如果不是,他们通过运行pip install scikit-learn使用 pip 安装它。
And this should resolve the error.这应该可以解决错误。
If still throws an error, then try to reinstall it, by first uninstalling by running pip uninstall scikit-learn and then installing it again, by pip install scikit-learn .如果仍然抛出错误,则尝试重新安装它,首先通过运行pip uninstall scikit-learn然后再次安装它,通过pip install scikit-learn

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM