ModuleNotFoundError: No module named 'requests' ;installed in multiple location - python

import requests
from bs4 import BeautifulSoup
try:
source = requests.get('https://www.tripadvisor.com.sg/Hotels-g294265-Singapore-Hotels.html')
source.raise_for_status()
soup = BeautifulSoup(source.text, 'html.parser')
print(soup)
hotel = soup.find('div', class_="prw_rup prw_meta_hsx_responsive_listing ui_section listItem")
print(hotel)
except Exception as e:
print(e)
PS C:\Users\keeha\PycharmProjects\INF1002_Draft> py main1.py
Traceback (most recent call last):
File "C:\Users\keeha\PycharmProjects\INF1002_Draft\main1.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
PS C:\Users\keeha\PycharmProjects\INF1002_Draft> cd C:\Users\keeha\AppData\Local\Programs\Python\Python310\Scripts
PS C:\Users\keeha\AppData\Local\Programs\Python\Python310\Scripts> .\pip install requests
Requirement already satisfied: requests in c:\users\keeha\appdata\local\programs\python\python310\lib\site-packages (2.28.1)
Requirement already satisfied: idna<4,>=2.5 in c:\users\keeha\appdata\local\programs\python\python310\lib\site-packages (from requests) (3.4)
Requirement already satisfied: charset-normalizer<3,>=2 in c:\users\keeha\appdata\local\programs\python\python310\lib\site-packages (from requests) (2.1.1)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\keeha\appdata\local\programs\python\python310\lib\site-packages (from requests) (2022.9.24)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in c:\users\keeha\appdata\local\programs\python\python310\lib\site-packages (from requests) (1.26.12)
WARNING: You are using pip version 21.3.1; however, version 22.2.2 is available.
You should consider upgrading via the 'C:\Users\keeha\AppData\Local\Programs\Python\Python310\Scripts\python.exe -m pip install --upgrade pip' command.
PS C:\Users\keeha\AppData\Local\Programs\Python\Python310\Scripts> cd c:\users\keeha\appdata\local\programs\python\python310\lib\site-packages
PS C:\users\keeha\appdata\local\programs\python\python310\lib\site-packages> py C:\Users\keeha\PycharmProjects\INF1002_Draft\main1.py
Traceback (most recent call last):
File "C:\Users\keeha\PycharmProjects\INF1002_Draft\main1.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
PS C:\users\keeha\appdata\local\programs\python\python310\lib\site-packages>
I am trying to webscrape but it keep popping up the NoModuleFoundError while I have installed it in both my python and pycharm and I can find it in my settings. Please also a look at this link "i.pinimg.com/originals/e5/2e/6c/…" and see if you can notice anything that might cause the error?

To install requests module on Debian/Ubuntu for Python 2:
$ sudo apt-get install python-requests
And for Python 3 the command is:
$ sudo apt-get install python3-requests
Windows
Use
pip install requests
(or
pip3 install requests for python3)
if you have pip installed and Pip.exe added to the Path Environment Variable. If pip is installed but not in your path you can use python -m pip install requests (or python3 -m pip install requests for python3)
Alternatively from a cmd prompt, use > Path\easy_install.exe requests, where Path is your Python*\Scripts folder, if it was installed. (For example: C:\Python32\Scripts)
If you manually want to add a library to a windows machine, you can download the compressed library, uncompress it, and then place it into the Lib\site-packages folder of your python path. (For example: C:\Python27\Lib\site-packages)

Related

python on raspberry pi 3b+: "no module named requests", despite the module being installed

first of all - I'm a newbie when it comes to Linux stuff. I follow commands and try to look up problems that I encounter along the way. I tried the same approach with this issue, but nothing has worked so far.
I'm trying to install a program on a fresh install of Raspberry Pi OS (version 11 Bullseye) on a Raspberry Pi 3b+. I'm not sure I can link the github page of the program here, but it's an application that's written mostly in Python. I have already installed that application successfully on a laptop running an Arch based distro. There were no such problems there.
I follow install instructions, I download dependencies, I create a virtualenv, activate it, download stuff from requirements.txt and then try to run the program.
Here's where the issue occurs:
Traceback (most recent call last):
File "app.py", line 4, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
So I try to install requests with
sudo pip install requests
(while still being in the virtualenv):
(venv) pi#pimusic:~ $ sudo pip install requests
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (2.28.1)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests) (2.7)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests) (1.24.3)
Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.9/dist-packages (from requests) (2.1.1)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests) (2020.6.20)
So requests is already there, but is not recognized, somehow.
I have tried:
uninstalling requests from within venv and installing it again
uninstalling requests from outside venv and trying to install it from inside venv
uninstalling requests from outside venv and installing it again
removing everything with "requests" in the filename from /usr/loval/lib/python3.9/dist-packages and installing requests back from inside venv and from outside venv
none of these things worked. I'm stumped, what do I do?

ImportError: No module named obd

I have installed obd library in python using : pip install obd. But when I tried to import eventlet this error occured:
pip install obd
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: obd in ./.local/lib/python3.6/site-packages (0.7.1)
Requirement already satisfied: pyserial==3.* in ./.local/lib/python3.6/site-packages (from obd) (3.4)
Requirement already satisfied: pint==0.7.* in ./.local/lib/python3.6/site-packages (from obd) (0.7.2)
pi#raspberrypi:~ $ python obd_hud_test.py
Traceback (most recent call last):
File "obd_hud_test.py", line 1, in <module>
import obd
ImportError: No module named obd
ow to rectify this error?
P.S : I am using Python 2.7
You can check which packages are installed with:
pip list
Hightlight specific package:
# Linux or other Unix-like systems
pip list | grep -i obd
# Windows
pip list | findstr /I obd
If it is not displayed, It is likely that something went wrong during the installation. You should reinstall.
OR
You should try to install a specific version
pip install "obd==0.7.1"

ModuleNotFoundError- Requests (despite installation attemps showing "requirement already satisfied")

When I run the code below to attempt to import a few of the usual Python libraries for API interaction... I get a ModuleNotFoundError on the import line of code.
I verified that it is indeed installed on my machine via pip3. I then tried uninstalling it and reinstalling it. When that didn't work I tried running the installation as a shell command in my Jupyter notebook. The same errors persisted.
Please note: what I am referring to as "it" is either the requests or json library for Python; I am encountering the same errors with each.
#right on the import line is where the error happens, the code is simple though...
import requests
import json
Here is the traceback...
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-021831bd5cc5> in <module>
1 # Dependencies
2 get_ipython().system(' pip3 install requests')
----> 3 import requests
4 import json
ModuleNotFoundError: No module named 'requests'
And here is the "requirement already satisfied" statement from Terminal...
(base) Computer:~ User$ pip3 install requests
Requirement already satisfied: requests in ./anaconda3/lib/python3.7/site-packages (2.22.0)
Requirement already satisfied: idna<2.9,>=2.5 in ./anaconda3/lib/python3.7/site-packages (from requests) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./anaconda3/lib/python3.7/site-packages (from requests) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in ./anaconda3/lib/python3.7/site-packages (from requests) (2019.6.16)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./anaconda3/lib/python3.7/site-packages (from requests) (1.24.2)
Sorry I’ve reputation to comment.
Pleas look at your env where you install the package.
You’re running on base environment maybe you’re using Anaconda, and then run Python without that environment. So the package won’t be seen bye your editor or terminale.
Could you add more information on where you use python?
I was facing the same problem on mac OSX, when I did "pip install requests", then I installed with "sudo" and it worked.
On OSX/Linux :
Use $ sudo pip install requests if you have pip installed.
Alternatively you can also use sudo easy_install -U requests if you have easy_install installed.
For centOS: yum install python-requests
Reference: [ImportError: No module named requests

ImportError: No module named attr

I have only very rudimentary experience in Python. I am trying to install the package pyslim (see here on the pypi website). I did
$ pip install pyslim
Requirement already satisfied: pyslim in ./Library/Python/2.7/lib/python/site-packages/pyslim-0.1-py2.7.egg (0.1)
Requirement already satisfied: msprime in /usr/local/lib/python2.7/site-packages (from pyslim) (0.6.1)
Requirement already satisfied: attrs in /usr/local/lib/python2.7/site-packages (from pyslim) (16.3.0)
Requirement already satisfied: svgwrite in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (1.1.12)
Requirement already satisfied: jsonschema in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (2.6.0)
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (1.10.0)
Requirement already satisfied: numpy>=1.7.0 in /usr/local/lib/python2.7/site-packages/numpy-1.10.4-py2.7-macosx-10.11-x86_64.egg (from msprime->pyslim) (1.10.4)
Requirement already satisfied: h5py in /usr/local/lib/python2.7/site-packages (from msprime->pyslim) (2.8.0)
Requirement already satisfied: pyparsing>=2.0.1 in /usr/local/lib/python2.7/site-packages (from svgwrite->msprime->pyslim) (2.2.0)
Requirement already satisfied: functools32; python_version == "2.7" in /usr/local/lib/python2.7/site-packages (from jsonschema->msprime->pyslim) (3.2.3.post2)
But when I open python and try to import pyslim, it fails
> import pyslim
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/remi/Library/Python/2.7/lib/python/site-packages/pyslim-0.1-py2.7.egg/pyslim/__init__.py", line 4, in <module>
from pyslim.slim_metadata import * # NOQA
File "/Users/remi/Library/Python/2.7/lib/python/site-packages/pyslim-0.1-py2.7.egg/pyslim/slim_metadata.py", line 1, in <module>
import attr
ImportError: No module named attr
So, I did
$ pip install attr
Requirement already satisfied: attr in /usr/local/lib/python2.7/site-packages (0.3.1)
and
$ pip install attrs
Requirement already satisfied: attrs in /usr/local/lib/python2.7/site-packages (16.3.0)
I restarted python and tried to import pyslim again but I keep receiving the same error message. I also tried to download and install the files from github by doing
$ git clone https://github.com/tskit-dev/pyslim.git
$ cd pyslim
$ python setup.py install --user
as indicated here on the pypi website. On this last line of code, I get a long output ending with
Download error on https://pypi.python.org/simple/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
No local packages or download links found for attrs
error: Could not find suitable distribution for Requirement.parse('attrs')
I am using Python 2.7.10 on a MAC OSX 10.11.6. Not sure if it matter but I usually install things with homebrew. I am using pip 18.1 from /usr/local/lib/python2.7/site-packages/pip (python 2.7).
Edit
$ which python
/usr/bin/python
$ which pip
/usr/local/bin/pip
Take a look to this other question that is related to the attrs package.
In your case, you have attr and attrs installed at the same time, and they are incompatible between them, so python is unable to resolve the package name on the import correctly.
You should use attrs only, so try uninstalling attr and try it again:
python -m pip uninstall attr
If, in the future, you need to have some packages incompatibles between them, take a look about using virtual environments in Python, which are really easy to use and will be very useful to play with packages and packages versions without break anything.
First uninstall pyslim. Use "pip uninstall pyslim". Then try installing again using
"conda install -c conda-forge pyslim"
Refer https://anaconda.org/conda-forge/pyslim

Weird pip bug. Can't install some modules but I can install others

Despite my best effors, I can't seem to get gevent or grequests working. They both rely on greenlet which I can't get working either.
I've completely installed and reinstalled python via homebrew. I haven't tried using python's installer but I don't see why that would matter. I have upgraded xcode to the latest version and installed literally every plugin. I regularly have success installing python modules via pip. I've been trying to install grequests for the last month.
Computer:
Mac OSX Yosemite Version 10.10.1
MacBook Pro (Retina, 15-inch, Late 2013)
2.3 GHz Intel Core i7
16 GB 1600 MHz DDR3
Intel Iris Pro 1536 MB
`
$ sudo pip install greenlet
Requirement already satisfied (use --upgrade to upgrade): greenlet in /usr/local/lib/python2.7/site-packages
Cleaning up...
$ sudo pip install gevent
Requirement already satisfied (use --upgrade to upgrade): gevent in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): greenlet in /usr/local/lib/python2.7/site-packages (from gevent)
Cleaning up...
$ sudo pip install grequests
Requirement already satisfied (use --upgrade to upgrade): grequests in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): gevent in /usr/local/lib/python2.7/site-packages (from grequests)
Requirement already satisfied (use --upgrade to upgrade): requests>=1.0.0 in /Library/Python/2.7/site-packages (from grequests)
Requirement already satisfied (use --upgrade to upgrade): greenlet in /usr/local/lib/python2.7/site-packages (from gevent->grequests)
Cleaning up...
'
>>> import grequests
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import grequests
ImportError: No module named grequests
>>> import greenlet
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import greenlet
ImportError: No module named greenlet
>>> import gevent
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import gevent
ImportError: No module named gevent
Edit:
$ which -a python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python
Edit 2:
I must have broken something at some point because now none of the modules I install are coming through. The modules I've installed in the past still work but the new ones are getting the same errors as above.
After reinstalling everything, I still had the problem. I thought that /Library/Frameworks/Python.framework/Versions/2.7/bin/python was the system installed version, but it's not.
I needed to delete that and remove it from ~/.bash_profile that and then everything worked fine. I don't know if that was my only problem as the reinstall could have fixed something, but I think it was.

Categories