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

But requests are in: C:\Users\piotr\Environments\bitcoin_notifications\Lib\site-packages\requests

I typed pip install requests to install them in my 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

I imported requests: import requests

And:

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)
rdas
  • 20,604
  • 6
  • 33
  • 46
  • 1
    Your requests seem to be in a `virtualenv` but the error seems to indicate you're trying to `import requests` in the system python. Did you activate the `virtualenv` before trying to `import requests` – rdas Apr 18 '19 at 10:48
  • Can you show us the command that generated these errors? There are so many possibilities... – Heath Raftery Apr 18 '19 at 10:51
  • ```PS C:\Users\piotr> Environments\bitcoin_notifications\Scripts\activate (bitcoin_notifications) PS C:\Users\piotr>``` –  Apr 18 '19 at 11:10
  • When I debug it again, Python Console is opening as 2nd terminal and: ```ppcd : The term 'ppcd' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.``` –  Apr 18 '19 at 11:16

2 Answers2

0

As commented before, you didn't activate your venv before pip install command.

Run: venv\Scripts\activate

from the directory where your virtual environment is located.

Then run pip install requests

RogerB
  • 74
  • 1
  • 7
  • ```PS C:\Users\piotr> Environments\bitcoin_notifications\Scripts\activate ``` –  Apr 18 '19 at 11:26
  • I ran it and I have activated venv: ```(bitcoin_notifications) PS C:\Users\piotr>``` –  Apr 18 '19 at 11:29
  • I typed ```pip install requests``` and Powershell told me that ```Requirement already satisfied: requests in c:\users\piotr\environments\bitcoin_notifications\lib\site-packages``` –  Apr 18 '19 at 11:31
  • This error still occurs... ```Exception has occurred: ModuleNotFoundError No module named 'requests'.``` –  Apr 18 '19 at 11:41
  • Can you just post your command and the output? Every detail counts. It's more effective than just tellung us what you did – RogerB Apr 18 '19 at 12:57
  • I fixed problem. Thx for all answers. :-) –  Apr 18 '19 at 15:34
0

Like others have said, it seems you didn't activate the virtual environment correctly.

BUT: since you're using PowerShell, you need to "dot source" the file, not run the script.

See your previous post for the solution: POWERSHELL VENV The module 'bitcoin_notifications' could not be loaded

wovano
  • 4,543
  • 5
  • 22
  • 49