控制台脚本未执行?

问题描述 投票:0回答:1

我想要一个在 pip 安装时自动执行 src/print_hello.py 的 pip 包

目录结构:

my_package/
├── src/
│       ├── __init__.py
│       ├── print_hello.py
└── setup.py

设置.py:

from setuptools import setup, find_packages

setup(
    name='my-package',
    version='0.1.0',
    packages=find_packages(where='src'),
    package_dir={'': 'src'},
    entry_points={
        'console_scripts': [
            'print_hello = print_hello:main',
        ]
    },
    author='Author',
    author_email='[email protected]',
    description='This is a test package',
    license='MIT',
    url='https://github.com/author/my_package',
)

init.py:它是空的

print_hello.py:

def main():
    print("Hello, world!")


if __name__ == "__main__":
    main()

为什么“print_hello.py”没有执行?我应该改进吗? 我尝试使用“pip install”来安装它。在 setup.py 目录中,但它没有执行“print_hello.py”

python pip setuptools
1个回答
0
投票

my_package
目录中打开控制台窗口并运行以下命令:

> pip install -e .
> print_hello
Hello, world!

第一行告诉 Python 将当前目录添加到 pip 路径中,第二行是运行文件的命令行参数。

© www.soinside.com 2019 - 2024. All rights reserved.