Python单击模块没有输出?

Python单击模块没有输出?,python,anaconda,command-line-interface,python-click,Python,Anaconda,Command Line Interface,Python Click,我试图继续单击,但由于某种原因,$python cli.py'London'的命令行中的代码不起作用,不幸的是,它没有返回任何错误,因此很难调查这里发生了什么 然而,函数current_weather()在Spyder IDE中工作得很有魅力,因此首先我怀疑Python Anaconda版本和单击模块之间存在兼容性问题,因此我完全卸载了Anaconda,现在正在运行用于Ubuntu的Python 3.6.7 但我仍然无法使它在CLI中工作,并且它不会返回任何错误。我做错了什么 import cl

我试图继续
单击
,但由于某种原因,
$python cli.py'London'
的命令行中的代码不起作用,不幸的是,它没有返回任何错误,因此很难调查这里发生了什么

然而,函数
current_weather()
在Spyder IDE中工作得很有魅力,因此首先我怀疑Python Anaconda版本和
单击
模块之间存在兼容性问题,因此我完全卸载了Anaconda,现在正在运行用于Ubuntu的Python 3.6.7

但我仍然无法使它在CLI中工作,并且它不会返回任何错误。我做错了什么

import click
import requests

SAMPLE_API_KEY = 'b1b15e88fa797225412429c1c50c122a1'

@click.command()
@click.argument('location')
def main(location, api_key):
    weather = current_weather(location)
    print(f"The weather in {location} right now: {weather}.")


def current_weather(location, api_key=SAMPLE_API_KEY):
    url = 'http://samples.openweathermap.org/data/2.5/weather'

    query_params = {
        'q': location,
        'appid': api_key,
    }

    response = requests.get(url, params=query_params)

    return response.json()['weather'][0]['description']
在CLI中:

$ python cli.py
$
$ python cli.py 'London'
$
在Spyder IDE中:

In [1109]: location = 'London'

In [1110]: current_weather(location)
Out[1110]: 'light intensity drizzle'
当与
pdb
源代码调试器一起使用时,pdb会自动进入后期调试,这意味着程序将异常退出。但是没有错误

$ python -m pdb cli.py 'London'
> /home/project/cli.py(2)<module>()
-> import click
(Pdb) 
$python-m pdb cli.py'London'
>/home/project/cli.py(2)()
->导入点击
(Pdb)

我已经安装了
click-7.0
python3.6.7(默认,2018年10月22日,11:32:17)
您需要调用
main()

完整示例: 使用安装工具 或者,您可以使用,然后以这种方式调用
main

调试: 我强烈推荐将其作为Python IDE。这可以使做这类工作容易得多

if __name__ == '__main__':
    main()
import click

@click.command()
@click.argument('location')
def main(location):
    weather = current_weather(location)
    print(f"The weather in {location} right now: {weather}.")


def current_weather(location):
    return "Sunny"


if __name__ == '__main__':
    main()