Python中的uuu future_uuuu和swagger_u客户端存在问题

Python中的uuu future_uuuu和swagger_u客户端存在问题,python,python-3.x,swagger,python-import,strava,Python,Python 3.x,Swagger,Python Import,Strava,Strava API文档提供了以下示例代码,我复制并输入了自己的访问令牌和俱乐部ID: from __future__ import print_statement import time import swagger_client from swagger_client.rest import ApiException from pprint import pprint # Configure OAuth2 access token for authorization: strava_oau

Strava API文档提供了以下示例代码,我复制并输入了自己的访问令牌和俱乐部ID:

from __future__ import print_statement
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint

# Configure OAuth2 access token for authorization: strava_oauth
swagger_client.configuration.access_token = 'MY_ACCESS_TOKEN'

# create an instance of the API class
api_instance = swagger_client.ClubsApi()
id = MY_CLUB_ID # Integer | The identifier of the club.
page = 56 # Integer | Page number. (optional)
perPage = 56 # Integer | Number of items per page. Defaults to 30.     (optional) (default to 30)

try:
    # List Club Activities
    api_response = api_instance.getClubActivitiesById(id, page=page, perPage=perPage)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling ClubsApi->getClubActivitiesById: %s\n" % e)
我试着运行它,我明白了

from __future__ import print_statement
SyntaxError: future feature print_statement is not defined
我还可以看到,我将得到与我的招摇过市的客户端导入相同。我已经试着为每一个安装了软件包,但这并没有产生任何影响。我读到关于未来的内容,我应该在>Python2.7上,但我目前使用的是3.6


如何解决此问题?

1第一行包含输入错误

来自未来导入打印语句 ^^^ 应该是

来自未来导入打印功能 但是由于您使用的是Python3,因此实际上不需要此导入-请参阅以了解详细信息

2 swagger_客户端可能是由生成的Python客户端。看起来您需要使用Swagger Codegen手动生成它。有几种方法可以做到这一点:

将Strava OpenAPI定义粘贴到中,然后选择Generate Client>Python。 安装并运行:


好问题。老实说,我不完全确定它是什么,但我猜它包含的包不是当前Python版本中的包,而是将来版本中的包。我不是Python开发人员,我只是第一次看到这一点,所以这可能是一个准确的解释。。。在Python3中。请看,即使我对此进行了注释,我也会得到import swagger\u client modulenofounderror:没有名为“swagger\u client”的模块作为旁注。该功能名为print_函数,而不是print_语句。您仍然可以在python3中导入print_函数。x@MegaIng谢谢看起来import print_语句在Codegen-生成的示例中是一个输入错误。好的,所以我尽可能按照上面的说明进行操作。最后是一个名为swagger PythonClient的文件夹,其中包含一个包含configuration.py和rest.py的swagger_客户端文件夹,因此我将内容复制到了我的程序目录中。导入错误现已消失,但现在我发现了其他问题。我可以调查,如果需要的话,可能会发布一个新问题,但我想在继续之前检查一下我所做的是否正确。我的应用程序现在可以工作了。我也在努力开始。。。您是否愿意解释一下您还安装了哪些丢失的软件包?
# Windows
java -jar swagger-codegen-cli-<ver>.jar generate -i https://developers.strava.com/swagger/swagger.json -l python -o ./StravaPythonClient

# Mac
swagger-codegen generate -i https://developers.strava.com/swagger/swagger.json -l python -o ./StravaPythonClient