V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
allencode
V2EX  ›  Python

pip 打包问题,程序入口在哪里?

  •  
  •   allencode · 2016-06-23 09:32:16 +08:00 · 2791 次点击
    这是一个创建于 2868 天前的主题,其中的信息可能已经有所发展或是发生改变。

    小弟写了一个脚本,通过在 CMD 窗口执行:python xxx.py 能够达到效果。程序结构也就像下面这个样子。

    pip 打包,上传都会了。安装 pip install xxx 成功之后,程序入口在哪里呢?怎么用呢? import xxx ?

    第一次搞这个,还请知道的大侠指导一下,十分感激。

    
    import os
    
    def fun1():
    	...
     
    def fun2():
    	...
    
    if __name__ == '__main__':
    	
       fun1()
       fun2()
    
    3 条回复    2016-06-24 07:31:21 +08:00
    zeyexe
        1
    zeyexe  
       2016-06-23 10:41:41 +08:00
    你打包用的 setup.py 文件的 setup()应该有一个 entry_points 项,可以在那里设置入口
    NxnXgpuPSfsIT
        2
    NxnXgpuPSfsIT  
       2016-06-23 10:49:49 +08:00
    假设这个 py 文件为`test.py`,假设使用 setuptools 。

    在`test.py`中加入如下命令:
    ```python
    def main():
    fun1()
    fun2()
    ```

    在`setup.py`的 setup()中加入 entry_points 键
    ```python
    entry_points={
    'console_scripts':[
    'mycommand = test:main'
    ]
    },
    ```
    建议参考:[localnote]( https://github.com/littlecodersh/LocalNote/blob/master/setup.py)

    命令行执行`mycommand`即可(需要已配置好环境变量)
    allencode
        3
    allencode  
    OP
       2016-06-24 07:31:21 +08:00
    @NxnXgpuPSfsIT 十分感谢哈
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2614 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:15 · PVG 22:15 · LAX 07:15 · JFK 10:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.