Setup.py安装。找不到程序包初始化文件“ graph \ __ init __。py”(或非常规文件)

时间:2019-10-23 10:29:09

标签: python setup.py

我的目录结构:

Projects/
|- VirtualEnv/
|- Graph/
   |- graph/
   |  |- __init__.py
   |  |- create_structure.py
   |- setup.py
   |- MANIFEST.in

setup.py:

from setuptools import setup, find_packages

import graph

if __name__ == "__main__":
    setup(
        name='MyGraph',
        version='1.0',
        packages = find_packages("graph"),
        entry_points={
            'console_scripts':
                ['start_graph = graph.create_structure:go']
            },
        install_requires = [
            "pandas>=0.25.1",
            "teradatasql>=16.20.0.50"
        ],
        include_package_data=True
    )

我创建了virtualenv

virtualenv VirtualEnv/env

然后我通过

安装软件包
VirtualEnv/env/Scripts/python Graph/setup.py install

此后,我激活了virtualenv

source VirtualEnv/env/Scripts/activate

然后运行“ start_graph”(来自setup.py的命令)并得到

Traceback (most recent call last):
  File "D:\Developers\kdnikish\Projects\VirtualEnv\env\Scripts\start_graph-script.py", line 11, in <module>
    load_entry_point('MyGraph==1.0', 'console_scripts', 'start_graph')()
  File "D:\Developers\kdnikish\Projects\VirtualEnv\env\lib\site-packages\pkg_resources\__init__.py", line 489, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "D:\Developers\kdnikish\Projects\VirtualEnv\env\lib\site-packages\pkg_resources\__init__.py", line 2852, in load_entry_point
    return ep.load()
  File "D:\Developers\kdnikish\Projects\VirtualEnv\env\lib\site-packages\pkg_resources\__init__.py", line 2443, in load
    return self.resolve()
  File "D:\Developers\kdnikish\Projects\VirtualEnv\env\lib\site-packages\pkg_resources\__init__.py", line 2449, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'graph'

为什么它不起作用?我的错误在哪里?

1 个答案:

答案 0 :(得分:0)

看起来像罪魁祸首可能是packages参数。它可能应该为packages=find_packages()或更明确地为:packages=find_packages(src='.')。参见setuptools documentation on "Using find_packages()"

另外,执行该脚本时最好与安装脚本位于同一目录中

cd Graph
../VirtualEnv/env/Scripts/python setup.py install

您还可以从import graph中删除setup.py指令,我看不到有任何需要,而且无论如何它通常会早晚中断。

然后进行调试,找到MyGraph.egg-info目录并查看top_level.txtSOURCES.txt文件。这些应该可以帮助您确定包装是否正确。