ModuleNotFoundError with a python requests library - python

Is anyone else receiving a moduleNotFoundError with their requests library? Not sure why this is happening. The library is installed as well which is even more confusing.
import csv
from datetime import datetime
import requests
from bs4 import BeautifulSoup
and the resulting error was this:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In [1], line 4
2 import csv
3 from datetime import datetime
----> 4 import requests
5 from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'requests'
when i run pip freeze I can confirm I have requests installed as well, see below:
Screenshot from my terminal
I have requests version requests==2.28.1

Most likely, you don't have the requests module installed. Run the following command:
pip install requests to install the package.

corrected the error by referencing this question (i didnt see it when I first searched)
running sudo pip3 install requests and it recognized the library now.

Related

ModuleNotFoundError, trying to use binance.websockets

Hi I thought this would be pretty straightforwards but I can't figure it out.
It can't find binance.websockets for whatever reason even though it can find binance.client which should be part of the same package?
import config
import os
from binance.client import Client
from twisted.internet import reactor
from binance.websockets import BinanceSocketManager
Running this import code gives this error
Traceback (most recent call last):
File "/home/lucho/Documents/cryptoAPIs/binance/importconfig.py", line 6, in <module>
from binance.websockets import BinanceSocketManager
ModuleNotFoundError: No module named 'binance.websockets
To get the library I installed with pip3
pip3 install python-binance
pip3 install binance-api
The BinanceSocketManager is no longer in the websockets file. Change your import to this:
from binance.streams import BinanceSocketManager
This will fix the issue
use this " pip install python-binance==0.7.9 "
If you look into the breaking changes on version 1.0.1 they mention they changes Websockets, so that is probably what you are hitting.
I would just reinstall the latest version "pip install python-binance" and use the up to date examples on their repo:
https://github.com/sammchardy/python-binance

ImportError: cannot import name BeatifulSoup

In my program i used from bs4 import BeatifulSoup, and i get the error:
Traceback (most recent call last):
File "D:\Noahs program\python black hat\retrievescreenshot.py", line 2, in <module>
from bs4 import BeatifulSoup
ImportError: cannot import name BeatifulSoup
I installed bs4 from the command line with pip.exe from python 2.7.15.
pip install bs4
I have tried pip install beautifulsoup4 and it said installation allready satisfied.
pip install beautifulsoup4
then you will be able to import it
You have a typo in your import... It should be:
from bs4 import BeautifulSoup #<-- not BeatifulSoup

Can not solve ImportError: No module named request

I have read this question
1) I installed pip and I executed
pip install requests
and got
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages/requests-2.9.1-py2.7.egg
Cleaning up...
2) I started my python2 shell:
>>> from urllib.request import urlopen
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named request
Why I am still catching this exception? What I am doing wrong?
You are confusing the 3rd party module named requests with the Python 3's built-in urllib.request. You can use
import requests
both with Python 2 and 3. However, you can use
from urllib.request import urlopen
only with Python 3.
urllib.requests module is available in Python 3.x. In Python 2.x, it's urllib module
You installed the third party library requests, but trying to import standard module.
Why dont you just import requests?
What worked for me was to install python-pip with this command:
sudo apt install python-pip
then I update it with this command
pip install --upgrade pip
you have installed request(s) and you want to import a module from request. It's not the same.
The module request exists only on python 3. Python 2 don't have this module.
-> If u want to use urlopen, you don't need to install requests. U muss only use python 3

Having trouble using requests for urls

I simply wrote the following code to play around with the Requests library
requests tests
import requests
r = requests.get('https://api.github.com/events')
but I keep getting the same error message, even if I use from requests import *
Traceback (most recent call last):
File "/Users/dvanderknaap/Desktop/Organized/CS/My_Python_Programs/requests.py", line 3, in <module>
import requests
File "/Users/dvanderknaap/Desktop/Organized/CS/My_Python_Programs/requests.py", line 5, in <module>
r = requests.get('https://api.github.com/events')
AttributeError: 'module' object has no attribute 'get'
I've tried reinstalling requests using pip install requests, but the output is:
Requirement already satisfied (use --upgrade to upgrade): requests in /anaconda/lib/python3.5/site-packages
I think the problem is that it is installed in my python3.5 library but I am using python2.7, but I'm not sure how to fix that.
Advice?
First, rename your file My_Python_Programs/requests.py to something else than requests.py. It is importing itself instead of the requests module.
Your python 2.7 may or may not already have the requests package installed. If not, you can install it with
pip2.7 install requests
Instead of expecting that there is a proper wrapper for your pip with a version number, use the pip module of your desired Python interpreter:
% python2.7 -mpip install requests

No module named BeautifulSoup (but it should be installed) [duplicate]

This question already has answers here:
ImportError: No module named BeautifulSoup
(8 answers)
Closed 3 years ago.
I downloaded BeautifulSoup.
Then I upgraded pip:
pip install --upgrade pip
Then, installed BS:
pip install beautifulsoup4
It seems like everything worked fine, but now when I run these three lines of code:
from BeautifulSoup import BeautifulSoup
import urllib2
import csv
I get this error.
Traceback (most recent call last):
File
"C:\Users\rshuell001.spyder2\temp.py", line 1, in
from BeautifulSoup import BeautifulSoup ImportError: No module named BeautifulSoup
I'm using Anaconda-Spyder
What am I doing wrong?
I think it should be: from bs4 import BeautifulSoup.

Categories