次の形式の Python パッケージがあります。
mypackage
├── README.md
├── doc
│ └── README.md
├── examples
│ └── README.md
├── setup.py
└── src
├── __init__.py
├── core
│ ├── __init__.py
│ └── main.py
└── test
└── README.md
付随する setup.py ファイルがあります。
import os
from setuptools import setup, find_packages
def read(fname):
"""
Reads the README functions are prints them into the long_description in
the setup routine.
Parameters
----------
fname : README file name
Returns
-------
Rendered README
"""
return open(os.path.join(os.path.dirname(__file__), fname)).read()
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Programming Language :: Python",
]
def run_setup():
"""
This functions holds the setup command. Rather than running setup directly,
it is wrapped in a 'try-except' that will print out errors if they occur.
"""
setup(
name='My Package',
version='0.1',
description='My package',
long_description=read('README.md'),
long_description_content_type='text/markdown',
classifiers=classifiers,
packages=['src', 'src.core'],
python_requires='>=2.7.9',
entry_points="""
[console_scripts]
my_package = src.core.main:main
""",
)
try:
run_setup()
except SystemExit as e:
print(e)
python setup.py develop
またはを実行するpip install -e .
と、パッケージは正常にインストールされたと表示されます。ただし、実行するmy_package
と、次のエラーが表示されます。
Traceback (most recent call last):
File "/Users/mm/opt/anaconda3/bin/my_package", line 33, in <module>
sys.exit(load_entry_point('My-Package', 'console_scripts', 'my_package')())
File "/Users/mm/opt/anaconda3/bin/my_package", line 25, in importlib_load_entry_point
return next(matches).load()
File "/Users/mm/opt/anaconda3/lib/python3.7/site-packages/importlib_metadata/__init__.py", line 105, in load
module = import_module(match.group('module'))
File "/Users/mm/opt/anaconda3/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'src.core'
適切な場所に__init__.py
ファイルがあります。setuptools
'明示的なfind_packages
ルーチンを使用してみました。ここで何が間違っていますか?