Showing error while installing BeatifulSoup - python

while pip installing BeautifulSoup it is showing this:-
C:\Users\LENOVO>pip install beautifulsoup4
Requirement already satisfied: beautifulsoup4 in
c:\users\lenovo\anaconda3\lib\site-packages (4.9.3)
Requirement already satisfied: soupsieve>1.2; python_version >= "3.0" in
c:\users\lenovo\anaconda3\lib\site-packages (from beautifulsoup4) (2.0.1)
C:\Users\LENOVO>
But while importing this library it is showing this error message:-
>>>from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
>>>
I have only Python3 installed in my system. Please Help :-)

Python loads modules from location in sys.path. So probably worth calling that and seeing where it is looking for modules. E.g. for my system (in a virtualenv)
In [9]: sys.path
Out[9]:
['/Users/me/.virtualenvs/standard/bin',
'/Users/me/.virtualenvs/standard/lib/python37.zip',
'/Users/me/.virtualenvs/standard/lib/python3.7',
'/Users/me/.virtualenvs/standard/lib/python3.7/lib-dynload',
'/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'',
'/Users/me/.virtualenvs/standard/lib/python3.7/site-packages',
'/Users/me/.virtualenvs/standard/lib/python3.7/site-packages/IPython/extensions',
'/Users/me/.ipython']
and checking that c:\users\lenovo\anaconda3\lib\site-packages is in that list

Related

Trying to import a python module that is installed receiving error

I'm new to python so this might be a simple fix but I couldn't find a solution by just googling. I'm getting this error when trying to run an import on a module.
Traceback (most recent call last):
File "c:/Users/joeshmo/OneDrive - company Industries/Documents/Python/Excel Join/join.py", line 1, in <module>
from openpyxl import load_workbook
ModuleNotFoundError: No module named 'openpyxl'
Openpyxl is already installed as pip gives me this...
pip install openpyxl
Requirement already satisfied: openpyxl in c:\users\joeshmo\appdata\local\programs\python\python38-32\lib\site-packages (3.0.5)
Requirement already satisfied: jdcal in c:\users\joeshmo\appdata\local\programs\python\python38-32\lib\site-packages (from openpyxl) (1.4.1)
Requirement already satisfied: et-xmlfile in c:\users\joeshmo\appdata\local\programs\python\python38-32\lib\site-packages (from openpyxl) (1.0.1)
Python installed here...
C:\Users\joeshmo\AppData\Local\Programs\Python\Python38-32
PythonPath here...
C:\Users\joeshmo\AppData\Local\Programs\Python\Python38-32\python38.zip
C:\Users\joeshmo\AppData\Local\Programs\Python\Python38-32\DLLs
C:\Users\joeshmo\AppData\Local\Programs\Python\Python38-32\lib
C:\Users\joeshmo\AppData\Local\Programs\Python\Python38-32
C:\Users\joeshmo\AppData\Roaming\Python\Python38\site-packages
C:\Users\joeshmo\AppData\Local\Programs\Python\Python38-32\lib\site-packages
On windows 10.
Any help would be appreciated!
After troubleshooting with a colleague, we discovered I had 2 versions of python running. I could run "py" (3.8.0) or "python"(3.8.5). After uninstalling the older version. This was no longer an issue.

I install bs4, but then get "No module named 'bs4'"

UPDATE: Thank you to everyone who answered and commented. I understand now that I have 2 versions of python installed. My program was running from "Miniconda3/python.exe ". While bs4 was installed in "c:\python38\lib\site-packages". I understand this to be the cause of the problem. I removed Minicoda3 but VS code still tries to use it when I run a program. How can I fix this?
When I run the following code:
>>> from bs4 import BeautifulSoup
Error:
I get the error: "No module named 'bs4'.
After I install bs4, It says "Requirement already satisfied" yet I get the same error.
Im not sure what I'm doing wrong, please help. Error messages below.
PS C:\Users\Admin\Desktop\exAPP> pip install bs4
Collecting bs4
Requirement already satisfied: beautifulsoup4 in c:\python38\lib\site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in c:\python38\lib\site-packages (from beautifulsoup4->bs4) (2.0.1)
Using legacy setup.py install for bs4, since package 'wheel' is not installed.
Installing collected packages: bs4
Successfully installed bs4-0.0.1
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
import BeautifulSoup
ModuleNotFoundError: No module named 'BeautifulSoup'
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
PS C:\Users\Admin\Desktop\exAPP>
You are using miniconda, which might not be on your PATH correctly such that pip is actually part of a separate Python installation.
You could use conda install pip, or C:/Users/Admin/Miniconda3/python.exe -m pip install bs4
Okay so my problems are fixed an my program is running. Like I said in the update the first problem was due to having 2 versions of python installed. After I removed the unwanted version it was still set as the python interpreter path. I was trying to fix this by going into VS code settings but was having no luck. Fortunately I finally noticed there was a button on bottom left of the screen that allowed me to change the path easily. Thanks again to those who commented and answered.

No module named 'bs4'

I want to import BeautifulSoup. But there is a problem. The BeautifulSoup library has installed in anaconda.
C:\Users\q>pip install BeautifulSoup4
Requirement already satisfied: BeautifulSoup4 in c:\users\q\anaconda3\lib\site-packages
But when i want to import BeautifulSoup, it trigger an error.
from bs4 import BeautifulSoup
Here is result
Traceback (most recent call last):
File "C:\Users\q\pyfile\ipsearch.py", line 1, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
Why? The reason is to the path of python's site-packages and the path to anaconda's site-packages trigger a confilct? A month ago, i use it successfully, at that time, my computer has installed python3.5 and anaconda. But now, it trigger an error. Why? Thanks for your answer.
try following command:
pip install --ignore-installed beautifulsoup4

For Python3, installing beautifulsoup4, on MacOS, unable to import within code?

I’m having trouble with installation of (or is it usage of?!) the beautifulsoup4 package, with Python 3.6, on MacOS High Sierra (10.3). I experienced the problem first in PyCharm and then also had same issue from the MacOS terminal, as demonstrated below. I’ve searched high and low on Stackoverflow and on the web at large, but cannot find a post/explaination that seems to meet the very specific symptoms I’m experiencing.
First three lines of my Python 3 code file called “main.py”….
import numpy as np
import matplotlib.pyplot as plt
import beautifulsoup4 as bs
When I execute it, I get the following error, seemingly indicating that the beautifulsoup4 package is not installed…..
DangerZone:test09-playwithnumpyandscipy bruce$ python3 main.py
Traceback (most recent call last):
File "main.py", line 3, in <module>
import beautifulsoup4 as bs
ModuleNotFoundError: No module named 'beautifulsoup4'
Yet, when I request a "list" of installed modules from pip3, i get the following....
DangerZone:test09-playwithnumpyandscipy bruce$ pip3 list
beautifulsoup4 (4.6.0)
certifi (2017.7.27.1)
chardet (3.0.4)
cycler (0.10.0)
idna (2.5)
inflection (0.3.1)
matplotlib (2.0.2)
more-itertools (3.2.0)
numpy (1.13.1)
pandas (0.20.3)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.6.1)
pytz (2017.2)
Quandl (3.2.0)
requests (2.17.3)
scikit-learn (0.19.0)
scipy (0.19.1)
setuptools (28.8.0)
six (1.10.0)
sklearn (0.0)
urllib3 (1.21.1)
Seems that beautifulsoup4 is installed, so why the earlier error? What am I doing wrong?
I've always found this one a bit weird, because the name of the library is 'BeautifulSoup4'. However, the proper way to import it is:
from bs4 import BeautifulSoup as bs
Making the Soup (documentation)

Python requests works in iPython, not in regular interpreter or in file

I've run into the issue that when I import the requests module in iPython it works great however when I try to compile a file that uses it everything goes bananas. Similarly when I try to import requests in the standard python interpreter things go bananas as well.
Any ideas?
import csv, requests, re
Leads to
Traceback (most recent call last):
File "sherpa_romeo.py", line 18, in <module>
import csv, requests, re
ImportError: No module named requests
I'm thinking that I may have pip'd to the wrong version of python.
I installed with the command:
pip install requests
I ran the command pip list and it returned:
certifi (14.05.14)
Flask (0.10.1)
gnureadline (6.3.3)
ipython (2.4.1)
itsdangerous (0.24)
Jinja2 (2.7.3)
MarkupSafe (0.23)
oauthlib (0.6.3)
pip (1.5.6)
pokitdok (0.9)
requests (2.4.0)
requests-oauthlib (0.4.1)
sendgrid (1.1.0)
setuptools (5.4.2)
smtpapi (0.1.2)
unittest2 (0.5.1)
virtualenv (1.11.6)
Werkzeug (0.9.6)
wsgiref (0.1.2)
which includes requests so I'm confused on why it's not working.
In the directory where you have the file that you compile, see if there is another file named "requests" and rename it

Categories

Resources