简体   繁体   中英

Setup.py install. Package init file 'graph\__init__.py' not found (or not a regular file)

My directory's structure:

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
    )

I created virtualenv

virtualenv VirtualEnv/env

Then I install package by

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

After this I activated virtualenv

source VirtualEnv/env/Scripts/activate

And run "start_graph" (command from setup.py) and got

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'

Why it is not working? Where is my mistake?

Looks like the culprit might be the packages parameter. It probably should be packages=find_packages() or more explicitly: packages=find_packages(src='.') . See the setuptools documentation on "Using find_packages()" .

Also it is probably better to be in the same directory as the setup script when executing it:

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

You can also remove the import graph instruction from your setup.py , I don't see any need for it, and anyway it usually breaks sooner or later.

Then for debugging, locate the MyGraph.egg-info directory and look inside the top_level.txt and SOURCES.txt files. These should help you figure out if the packaging has been done right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM