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

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.

Related

Showing error while installing BeatifulSoup

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

cannot import module "cv2" in python on mac

I'm trying to use opencv-python. I imported with pip but it throws ModuleNotFound.
Joshua-Tews-MacBook-Pro:~ nathan$ pip install opencv-python
Requirement already satisfied: opencv-python in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (4.0.0.21)
Requirement already satisfied: numpy>=1.14.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from opencv-python) (1.16.2)
I import with this:
import cv2
I get this error:
Traceback (most recent call last):
File "/Users/nathan/Library/Mobile Documents/com~apple~CloudDocs/CEP/Y4/Capstone Project (Security Cameras System)/cep-ml-capstone/VideoProcessor.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I've look at the answers on this stackoverflow thread, none seem to help: Cannot import cv2 in python in OSX
Others have solutions I completely didn't recognise pertaining to other OS so I skipped those.
Okay I apparently I just had to run the script with Python 3.7 and it worked. I neglected to mention I was using Textmate.
To run scripts in Python 3.7 using Textmate, go to Preferences > Variables. If there isn't a variable named TM_PYTHON, create one then paste this in for the value: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3. Else, just change the value. Be sure to check the box next to the variable.

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

python pip install not installing modules ubuntu

Adding modules has been very confusing on my laptop. Whenever I run the pip command, it will appear to be successful – for example:
> pip install selenium
Requirement already satisfied (use --upgrade to upgrade): selenium in /usr/local/lib/python2.7/dist-packages
However, when I try to use it in running python example.py, I get:
Traceback (most recent call last):
File "scriptattempt.py", line 2, in <module>
from selenium import webdriver
ImportError: No module named selenium
Where this happens with pretty much any modules I try to import. Not exactly sure why, I installed python 3 in the past, so I wasn't sure if maybe that's causing problems. I tried python3 example.py, but got the same error for packages in the line before.
I looked in at my site-packages file, at location: /usr/local/lib/python2.7/site-packages
but it's empty. Is this my problem? Is pip not unpacking in the correct location?

Python-Failure to import BeautifulSoup4 in Python3.3.1, but success in Python 2.7-Installed using easy_install

Background & What I did: I'm writing a webpage content extractor, and realized the need to install BeautifulSoup4 to better parse my HTML file. On my Ubuntu 13.04 machine, I have both Python2.7(system default) and Python3.3.1 installed. After a few failures with both pip and easy_install due to the "SSL certificate" issue, I got to finally install BeautifulSoup4 using easy_install on my last try.
But: It seems that easy_install installed BS4 into the Python2.7 directory(/usr/local/lib/python2.7/dist-packages) in my system, as you can tell from the information below:
Searching for beautifulsoup4
Reading http://pypi.python.org/simple/beautifulsoup4/
Best match: beautifulsoup4 4.2.1
Downloading https://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-4.2.1.tar.gz#md5=91ea70ce16a5f1f43e58f2ef05651679
Processing beautifulsoup4-4.2.1.tar.gz
Writing /tmp/easy_install-OLXNjV/beautifulsoup4-4.2.1/setup.cfg
Running beautifulsoup4-4.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-OLXNjV/beautifulsoup4-4.2.1/egg-dist-tmp-SpupH8
zip_safe flag not set; analyzing archive contents...
Adding beautifulsoup4 4.2.1 to easy-install.pth file
Installed /usr/local/lib/python2.7/dist-packages/beautifulsoup4-4.2.1-py2.7.egg
Right now I'm able to import BS4 in Python2.7, but not in Python3.3, with this error message:
>>> import bs4
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import bs4
ImportError: No module named 'bs4'
Question: Should I add this Python2.7 directory to my Python3.3 library directory? (I worry about future conflict of different versions of a same module due to this shared library path) or should I uninstall BS4 and try it again with pip so maybe it'll install BS4 in Python3.3 directory? (right now this got returned when I try to install BS4 again using pip: Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in ./beautifulsoup4-4.2.1-py2.7.egg) Other general pointers about solving this problem will also be appreciated. Thank you!
According to the section Download Beautiful Soup on the official homepage, you can install the python-beautifulsoup4 package on Ubuntu 13.04.
Try this to prevent the conflict between Python 2.7 and 3.3. Before you do that though, I'd recommend removing the Beautiful Soup egg to avoid a potential version conflict.

Categories

Resources