无法从不同文件夹导入模块

时间:2021-06-08 14:31:54

标签: python

对于一个项目,我有一个必须从不同文件夹导入模块的脚本。 我的文件结构如下:

enter image description here

script.py 中的代码如下:

import pandas as pd
import numpy as np
from algorithms.kmeans.kmeans import *

representatives = ["WestVlaanderen", "Hainaut", "Brussels", "BrabantWallon"]

representatives_info = pd.read_csv("data\\filtered_data\KMEANS.csv")

representatives_info = representatives_info[representatives_info["PROVINCE"].isin(representatives)]
representatives_info = representatives_info[["INFECTION_RATE", "HOSPITALISATION_RATE", "TEST_POS_PERCENTAGE"]].to_numpy()

kmeans = Kmeans("data\filtered_data\KMEANS.csv", 4, representatives_info)
kmeans.start_clustering()

文件夹算法和 kmeans 都有自己的 init.py 文件(空但我读到这无关紧要)。我仍然无法导入想要的文件。

我得到的错误是:

<块引用>

没有名为“算法”的模块

当我尝试在 bash 终端的 python 交互模式下使用相同的导入时,它可以正常工作。我不知道我做错了什么导致导入不起作用

0 个答案:

没有答案