出现ModuleNotFoundError的解决

今天,我为了让我的EasyGitTool能在命令行通过输入gt就可以运行,我决定在setup.py中添加如下代码

entry_points = {  
        'console_scripts': [  
            'gt = EasyGitTool.main:main'  
        ]  
    }  

当我输入python setup.py install后迫不及待地就输入gt要将它运行,结果出现了这样的问题

Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\Scripts\gt-script.py", line 33, in <module>
    sys.exit(load_entry_point('EasyGitTool==1.4', 'console_scripts', 'gt')())
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\Scripts\gt-script.py", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\importlib\metadata.py", line 77, in load
    module = import_module(match.group('module'))
  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 1030, in _gcd_import
  File "", line 1007, in _find_and_load
  File "", line 972, in _find_and_load_unlocked
  File "", line 228, in _call_with_frames_removed
  File "", line 1030, in _gcd_import
  File "", line 1007, in _find_and_load
  File "", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'EasyGitTool'

我愣是奇怪怎么会发生这样的问题,包明明是已经安装好了,为什么会显示ModuleNotFoundError: No module named 'EasyGitTool'
后来,我查了一下资料才知道——原来我忘记在EasyGitTool目录下添加__init__.py文件了。当我将__init__.py放入EasyGitTool目录后,一切恢复正常。

你可能感兴趣的:(#,久病成医,计算机大全,python,开发语言)