import GeneticAlgorithm ModuleNotFoundError: No module named 'libs.GeneticAlgorithm'

import GeneticAlgorithm ModuleNotFoundError: No module named 'libs.GeneticAlgorithm'

我一直在尝试 运行 找到一个代码,但我遇到了这种错误。我不知道如何处理这个问题,因为我是 python 的新手,正在尝试理解 TSP 问题的概念。 任何帮助,将不胜感激 下面的代码

from libs.GeneticAlgorithm import GeneticAlgorithm

def main():
    poland = Country()
    poland.add([
        City('Gorlice', (49.655299, 21.159769)),
        City('Sosnowiec', (50.286263, 19.104078)),
        City('Łódź', (51.760229, 19.457209)),
        City('Wrocław', (51.108314, 17.037802)),
        City('Poznań', (52.406376, 16.925167)),
        City('Toruń', (53.013790, 18.598444)),
        City('Zielona Góra', (51.935619, 15.506186)),
        City('Szczecin', (53.428543, 14.552812)),
        City('Rzeszów', (50.041187, 21.999121)),
        City('Kraków', (50.049683, 19.944544)),
        City('Olsztyn', (53.770226, 20.490189)),
        City('Lublin', (51.245376, 22.568278))
    ])
    print('Cities:', end=' ')
    print(*(city for city in poland.cities), sep=', ')
    ga = GeneticAlgorithm(100, mutation_rate=0.5, ptype=Route, args=(poland.cities,))
    ga.run(seconds=10)
    fittest = ga.alltime_best
    best_fitness = fittest.fitness
    print('Best route:', fittest)
    print('Best fitness:', best_fitness)
    print('Generations:', ga.generation)


if __name__ == '__main__':
    main()

如果你 "found" 这个代码(最有可能在互联网上?)那么发布这个的人在他的机器上有一个 libs 文件夹,里面有一个 GeneticAlgorhythm.py 模块,所以您要么找到这个 GeneticAlgorhythm 模块,要么您将无法 运行 此代码成功。

当你看到,在python from baz.bar import Foo中,Python将在baz文件夹中寻找bar模块,并导入class Foo 来自它。所以你需要在你的PC上安装baz模块,否则会出现这个错误

它来自这个存储库:https://github.com/reconndev/Genetic-Algorithm-TSP。要获得它 运行ning,只需克隆或下载存储库即可。然后,在主(根)文件夹中,运行 python TSP-Text.py

python TSP-Text.py 
Cities: Gorlice, Sosnowiec, Łódź, Wrocław, Poznań, Toruń, Zielona Góra, Szczecin, Rzeszów, Kraków, Olsztyn, Lublin
Best route: Toruń->Olsztyn->Łódź->Lublin->Rzeszów->Gorlice->Sosnowiec->Kraków->Wrocław->Zielona Góra->Szczecin->Poznań
Best fitness: 0.4219619417258425
Generations: 807