【问题标题】:I have installed requests but I still get ModuleNotFoundError: No module named 'requests' (Django)我已经安装了请求,但仍然收到 ModuleNotFoundError: No module named 'requests' (Django)
【发布时间】:2021-05-30 11:27:35
【问题描述】:

这是我安装“请求”时得到的

如果我执行 pip3 安装请求(要求已经满足),

如果我执行 pip 安装请求(要求已经满足),

python3.9 -mpip 安装请求(已满足要求),


似乎我已经安​​装了请求,但我仍然收到“ModuleNotFoundError: No module named 'requests'”

我的 django 项目中有一个包含此代码的文件

    import requests

def client():
    credentials = {"username": "admin", "password": "123456789"}

    response = requests.post("http://127.0.0.1:8000/api/rest-auth/login/",
                              data=credentials)

        
    print("Status Code:" , response.status_code)
    response_data = response.json()
    print(response_data)


if __name__ == "__main__":
    client()

【问题讨论】:

标签: django authentication python-3.9


【解决方案1】:

我不确定,但安装的包需要在已安装应用部分的 settings.py 文件中设置。

【讨论】:

  • 它必须使用“python3 -m pip install --user requests”安装,然后才能正常工作。
【解决方案2】:

我在website找到了解决方案

解决方案:

python3 -m pip install --user requests

然后它安装在 python3 上,但不是 2 或更少,所以它只有在你使用 python3 时才能工作。

取决于您的默认 python 版本。我的是 Python 2.7.16

【讨论】:

    猜你喜欢
    • 2019-07-21
    • 2018-06-12
    • 2021-04-13
    • 2022-06-30
    • 1970-01-01
    • 2022-10-22
    • 2019-05-10
    • 2020-05-24
    • 1970-01-01
    相关资源
    最近更新 更多