【问题标题】:Imports not working in command prompt and VSCode导入在命令提示符和 VSCode 中不起作用
【发布时间】:2021-09-04 16:39:50
【问题描述】:

这是我的代码:

import praw

#do something

每当我在 VS Code 或命令提示符中运行它时,我都会收到此错误

Traceback (most recent call last):
  File "C:\Users\12488\Downloads\Reddit\post.py", line 3, in <module>
    r = praw.Reddit(user_agent="My user agent")
  File "C:\Users\12488\AppData\Local\Programs\Python\Python38\lib\site-packages\praw\reddit.py", line 249, in __init__
    raise MissingRequiredAttributeException(
praw.exceptions.MissingRequiredAttributeException: Required configuration setting 'client_id' missing.
This setting can be provided in a praw.ini file, as a keyword argument to the `Reddit` class constructor, or as an environment variable.

我认为这可能只是 praw 的问题,所以我尝试重新安装 praw 以及使用我在其他论坛上找到的命令安装不同的版本,最后我只是尝试导入我常用的其他模块,如 discord.py、cv2和moviepy,这些都不起作用。由于找出问题所在是一个相当广泛的问题,因此请随时询问更多信息。

【问题讨论】:

    标签: python python-3.x visual-studio-code import


    【解决方案1】:

    我不熟悉praw,但是错误提示显示你只是错过了client_id。我在官方文档中找到了一个例子,它提供了client_id 属性。

    import praw
    
    reddit = praw.Reddit(
        client_id="my client id",
        client_secret="my client secret",
        user_agent="my user agent",
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-11-15
      • 2018-06-20
      • 1970-01-01
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 2020-08-04
      相关资源
      最近更新 更多