发生了异常:ModuleNotFoundError没有名为“ requests”的模块

时间:2019-04-18 10:45:18

标签: python python-3.x python-requests virtualenv python-venv

Exception has occurred: ModuleNotFoundError
No module named 'requests'. 

但是请求位于:C:\ Users \ piotr \ Environments \ bitcoin_notifications \ Lib \ site-packages \ requests

我输入了pip安装请求以将其安装到我的venv中。

(bitcoin_notifications) PS C:\Users\piotr> pip install requests
Collecting requests
  Downloading https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a6777857kB)
    100% |████████████████████████████████| 61kB 868kB/s
Collecting certifi>=2017.4.17 (from requests)
  Downloading https://files.pythonhosted.org/packages/60/75/f692a584e85b7eaba0e03827b3d5s/60/75/f692a584e85b7eaba0e03827b3d51f45f571c2e793dd2.py3-none-any.whl (158kB)731e598828d380aa/certifi-2019.3.9-py2.py3-none-any.w2MB/shl (158kB)
    100% |████████████████████████████████| 163kB 2.s/bc/a9/01ffebfb562e4274b6487b4bb1dd2MB/s                                               y3-none-any.whl (133kB)
Collecting chardet<3.1.0,>=3.0.2 (from requests)    5MB/s
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22s/14/2c/cd551d81dbe15200be1cf41cd038e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl ne-any.whl (58kB)
(133kB)                                             MB/s
    100% |████████████████████████████████| 143kB 1.5MB/s                                               s/df/1c/59cca3abf96f991f2ec3131a4ffeCollecting idna<2.9,>=2.5 (from requests)
  Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)69a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)    100% |████████████████████████████████| 61kB 2.4MB/s

我导入了请求:import requests

并且:

Exception has occurred: ModuleNotFoundError
No module named 'requests'
  File "C:\Users\piotr\Documents\bitcoin_notifications.py", line 1, in <module>
    import requests
  File "C:\Users\piotr\AppData\Local\Programs\Python\Python37\Lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\piotr\AppData\Local\Programs\Python\Python37\Lib\runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "C:\Users\piotr\AppData\Local\Programs\Python\Python37\Lib\runpy.py", line 263, in run_path
    pkg_name=pkg_name, script_name=fname)

2 个答案:

答案 0 :(得分:0)

如前所述,您没有在pip install命令之前激活venv。

运行: venv \ Scripts \ activate

虚拟环境所在的目录。

然后运行pip安装请求

答案 1 :(得分:0)

就像其他人所说的那样,看来您没有正确激活虚拟环境。

但是:由于使用的是PowerShell,因此需要“点源”文件,而不是运行脚本。

有关解决方案,请参见上一篇文章: POWERSHELL VENV The module 'bitcoin_notifications' could not be loaded