python 单击 setuptools 集成问题
python click setuptools integration issue
我正在使用 python3.7.1 conda 虚拟环境遵循 python 单击文档 here 中的设置工具示例,但继续收到错误消息:
ModuleNotFoundError: No module named 'yourpackage.scripts'
我一定是遗漏了一些明显的东西,但不确定是什么。
yourpackage/
├── __init__.py
├── main.py
├── scripts
│ ├── __init__.py
│ └── yourscript.py
├── setup.py
└── utils.py
#scripts/yourscript.py
import click
@click.command()
def cli():
"""Example script."""
click.echo('Hello World!')
# setup.py
from setuptools import setup, find_packages
setup(
name='yourpackage',
version='0.1',
packages=find_packages(),
include_package_data=True,
install_requires=[
'Click',
],
entry_points='''
[console_scripts]
yourscript=yourpackage.scripts.yourscript:cli
''',
)
$ pip install -e .
Looking in indexes: https://InternalArtifactoryUrl
Obtaining file:///private/tmp/yourpackage
Requirement already satisfied: Click in /Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages (from yourpackage==0.1) (7.0)
Installing collected packages: yourpackage
Found existing installation: yourpackage 0.1
Uninstalling yourpackage-0.1:
Successfully uninstalled yourpackage-0.1
Running setup.py develop for yourpackage
Successfully installed yourpackage
$ which yourscript
/Users/myusername/miniconda3/envs/test_20190220/bin/yourscript
$ yourscript
Traceback (most recent call last):
File "/Users/myusername/miniconda3/envs/test_20190220/bin/yourscript", line 11, in <module>
load_entry_point('yourpackage', 'console_scripts', 'yourscript')()
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2793, in load_entry_point
return ep.load()
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2411, in load
return self.resolve()
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2417, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'yourpackage.scripts'
我还在我的包目录中尝试了以下内容:
export PYTHONPATH=/tmp/yourpackage/
并在 运行 yourscript
时继续收到错误
Python 路径应包括包含 yourpackage
的目录。在这种情况下,它将是 /tmp
.
但是,更好的方法可能是重新排列您的源代码,以便在使用 setuptools
时无需调整 python 路径。像这样:
yourpackage/
├── yourpackage/
| ├── __init__.py
| ├── main.py
| ├── scripts
│ ├── __init__.py
│ ├── yourscript.py
| └── utils.py
├── README.md
├── LICENSE
├── requirements.txt
└── setup.py
请参阅 github 上的 project 以获取基于 click
的更大项目的示例。
我正在使用 python3.7.1 conda 虚拟环境遵循 python 单击文档 here 中的设置工具示例,但继续收到错误消息:
ModuleNotFoundError: No module named 'yourpackage.scripts'
我一定是遗漏了一些明显的东西,但不确定是什么。
yourpackage/
├── __init__.py
├── main.py
├── scripts
│ ├── __init__.py
│ └── yourscript.py
├── setup.py
└── utils.py
#scripts/yourscript.py
import click
@click.command()
def cli():
"""Example script."""
click.echo('Hello World!')
# setup.py
from setuptools import setup, find_packages
setup(
name='yourpackage',
version='0.1',
packages=find_packages(),
include_package_data=True,
install_requires=[
'Click',
],
entry_points='''
[console_scripts]
yourscript=yourpackage.scripts.yourscript:cli
''',
)
$ pip install -e .
Looking in indexes: https://InternalArtifactoryUrl
Obtaining file:///private/tmp/yourpackage
Requirement already satisfied: Click in /Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages (from yourpackage==0.1) (7.0)
Installing collected packages: yourpackage
Found existing installation: yourpackage 0.1
Uninstalling yourpackage-0.1:
Successfully uninstalled yourpackage-0.1
Running setup.py develop for yourpackage
Successfully installed yourpackage
$ which yourscript
/Users/myusername/miniconda3/envs/test_20190220/bin/yourscript
$ yourscript
Traceback (most recent call last):
File "/Users/myusername/miniconda3/envs/test_20190220/bin/yourscript", line 11, in <module>
load_entry_point('yourpackage', 'console_scripts', 'yourscript')()
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2793, in load_entry_point
return ep.load()
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2411, in load
return self.resolve()
File "/Users/myusername/miniconda3/envs/test_20190220/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2417, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
ModuleNotFoundError: No module named 'yourpackage.scripts'
我还在我的包目录中尝试了以下内容:
export PYTHONPATH=/tmp/yourpackage/
并在 运行 yourscript
Python 路径应包括包含 yourpackage
的目录。在这种情况下,它将是 /tmp
.
但是,更好的方法可能是重新排列您的源代码,以便在使用 setuptools
时无需调整 python 路径。像这样:
yourpackage/
├── yourpackage/
| ├── __init__.py
| ├── main.py
| ├── scripts
│ ├── __init__.py
│ ├── yourscript.py
| └── utils.py
├── README.md
├── LICENSE
├── requirements.txt
└── setup.py
请参阅 github 上的 project 以获取基于 click
的更大项目的示例。