setup.py中entry_points的ImportError

时间:2017-03-25 16:37:59

标签: python pip setuptools

当我尝试调用ImportError: No module named 'test.nested'中定义的控制台脚本入口点时,我得到setup.py

  • 项目结构:

    test
    ├── setup.py
    └── test
        ├── __init__.py
        └── nested
            ├── __init__.py
            └── testme.py
    
  • setup.py

    from setuptools import setup, find_packages
    
    setup(name='test',
          version='0.1',
          packages=find_packages(),
          entry_points = {
            'console_scripts': [
                'testme=test.nested.testme:main'
                ]
            },
          zip_safe=False)
    
  • testme.py

    def main():
        print('It works!')
    
    if __name__ == '__main__':
        main()
    

然而,我收到此错误:

> pip install .
Processing my_folders/test
Installing collected packages: test
  Running setup.py install for test ... done
Successfully installed test-0.1

> testme

Traceback (most recent call last):
  File "venv35/bin/testme", line 11, in <module>
    load_entry_point('test==0.1', 'console_scripts', 'testme')()
  File "venv35/lib/python3.5/site-packages/pkg_resources/__init__.py", line 560, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "venv35/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2648, in load_entry_point
    return ep.load()
  File "venv35/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2302, in load
    return self.resolve()
  File "venv35/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2308, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ImportError: No module named 'test.nested'

这里有什么问题?

注意:在python shell中,此代码有效:

>>> import test.nested.testme
>>> test.nested.testme.main()
It works!

1 个答案:

答案 0 :(得分:0)

好吧,显然我的名字使用了一个坏名字。事实上,将test重命名为my_test解决了这个问题。

我希望这对其他人有用。