ImportError: No module named bs4 on mac - python

I sat down tonight and have decided to leran how to use python. Inspired by this webpage scraping article.
cam.ly/danesblog/2011/01/craigslist-arbitrage/
after working through a tutorial I:
1) downloaded and installed python: http://www.python.org/getit/ first 3.3 then 2.7
2) downloaded bs4: www.crummy.com/software/BeautifulSoup/bs4/download/
3) followed Brian Clapper's instructions:
How can I install the Beautiful Soup module on the Mac?
tried both easy_install and python setup.py install methods
I am still getting "ImportError: No module named bs4"
Python is installed in applications folder, the bs4 package auto installs in Library
Is this the problem? I tried copying and moving the folder into Python application, but didn't work.
I have also tried both forms:
from BeautifulSoup import BeautifulSoup
from bs4 import BeautifulSoup
Thank you for the support.

The solution is in setting up the PATH the packages get installed. EPD or Canopy create their VirtualEnv set up in the .\~profile and .\~bash_profile files. These path may not be identical to the path pip install or easy_install try to install the packages. If you open bash_profile or profile files there should be a path similar to this :
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/test_user/Library/Enthought/Canopy_64bit/User/bin/activate
I am using Enthought as my python editor so yours will be something else but what is important is if you are using pip or easy_install the address the python packages are installed should point here. Or put another way, your active virtual environment set up is in this address.

Related

ModuleNotFoundError: No module named 'bs4' even though I have installed BeautifulSoup4 properly with pip3 (Windows)

Python version: 3.9.5
pip version: 21.1.1
BeautifulSoup4 version: 4.9.3
from bs4 import BeautifulSoup
with open('home.html', 'r') as html_file:
content = html_file.read()
print(content)
I have been trying to use the BeautifulSoup4 library but it just won't work. In vscode, it shows the indication that bs4 is there when I do CTRL+click on bs4 written in Code. But it still gives ModuleNotFoundError: No module named 'bs4'
I have installed it properly with pip3 as shown in the below screenshot
The version of python I am using in VS Code is shown in below Image
Just a side note. I also used some other packages such as Camelcase and that one worked fine. Idk why this one is not working properly. I couldn't find any proper related solution for it in the existing solutions for it.
I had python3 installed 2 times.. 1 from the Windows store and the other from python exe file. python3 command referred to windows installed python3 and python referred to exe file installed python3. BeautifulSOup installed via pip3 was linked to the python command instead of python3 so that was the reason it wasn't working.
after checking for paths of python and python3 everything got clarified and the problem solved thanks to the hint given by #Y.R in the comments section of the main post.

How to avoid "no module installed" in Python 3

Every single dependency I try to install results in a ton of troubleshooting before I can get IDLE to recognise that it's installed.
I'm on a Mac, and I'm using the Terminal's pip install. I also have two versions of IDLE – one for Python 2, the other for 3.
pip install says "beautifulsoup" is installed
pip3 install says "beautifulsoup" is installed, and yet it doesn't appear that IDLE knows that it is.
I've tried "import beautifulsoup4, import beautifulsoup, from bs4 import beautifulsoup..."
Why is this happening for every dependency I install?
It's not beautifulsoup or Beautifulsoup
Try this from bs4 import BeautifulSoup

BeautifulSoup4 is not working even though I have successfully installed it using pip Linux Mint Sarah

I am a brand new linux user using linux mint sarah and I just installed python 3.5 as well as BeautifulSoup to do some web scraping.
However, when I type in the following command I receive a traceback error:
from bs4 import BeautifulSoup
The error tells me that there is no module bs4.
I have also tried:
import bs4
from BeautifulSoup import BeautifulSoup
import beautifulsoup
This is weird because if I go into terminal and give the command pip list, it shows me a list of all my programs and it states that I have beautifulsoup4 (4.5.1)
I successfully used pip in the same exact way to install a module called requests and it was successful.
One thing that I think may be getting in the way is that Linux mint comes with python 2.7 installed and my modules are going into a 2.7 folder which seems odd. (However, the requests module that I can successfully use is in the same folder as the BeautifulSoup4 module)
I must admit I have not tried easy_install because it gives me some error about the directory not existing when I try to install BeautifulSoup4 that way.
I'm muddying the waters too much so I will leave it at that. Hopefully, somebody can help me figure out whats going on so that people who have this problem in the future can benefit.
Thanks!
You need to install BeautifulSoup4 for Python 3.5.
Option 1:
Download https://bootstrap.pypa.io/get-pip.py file to server.
Run python3 get-pip.py
Run pip3 install beautifulsoup4
Option 2:
Download https://pypi.python.org/pypi/beautifulsoup4 to server.
Extract tar.gz: tar -xvzf beautifulsoup4-4.5.1.tar.gz
Go to folder: cd beautifulsoup4-4.5.1/
Install from source: python3 setup.py install

Error while importing requests and pyvmomi module in python

I tried to import requests in my python scripts but it shows error
>>>import requests
ImportError: No module named requests
So I tried to install it using easy_install
Path\easy_install.exe requests
in Windows, but it shows no response and when I run import again, it shows the same error.
Make sure you have requests and pyvmomi directories located under c:\pythonXXX\Lib\site-packages.
In case of absence, try to install those packages via pip on windows(here you have the instructions to install pip on windows).
Once you have done installation of pip, open the CMD prompt with administrative privilege and use the following commands to install the required python packages :
pip install requests pyvmomi
Now you could see that the packages are successfully installed.
After this, open the "System Properties" window and select "Advanced" tab and click the button "Environment variables" to set required path variables as shown below :
PYTHONHOME - "c:\Python278"
PYTHONPATH - "c:\Python278\Lib"
Edit the system variable Path and append the following :
%PYTHONHOME%;%PYTHONPATH%;
Finally open idle or python shell and import the packages as follows :
import requests
import pyVmomi
Now you are able to import with out any problem. Whenever you import packages, also check the spelling and case sensitive of the name.
Open cmd.exe that run this command:
pip install requests
Another solution is to install Anaconda which is Python distribution that comes with great package manager from here: Anaconda
Anconda python comes with built in requests library (and many more useful libraries)

Where is BeautifulSoup4 hiding?

I did sudo pip install BeautifulSoup4 and got an awfully optimistic response:
Downloading/unpacking beautifulsoup4
Running setup.py egg_info for package beautifulsoup4
Installing collected packages: beautifulsoup4
Running setup.py install for beautifulsoup4
Successfully installed beautifulsoup4
Cleaning up..
but when I try to use import BeautifulSoup4 or from BeautifulSoup4 import BeautifulSoup4 in a script, python says there's no module by that name.
> import BeautifulSoup
ImportError: No module named BeautifulSoup
Update: pip tells me beautifulsoup4 in /usr/local/lib/python2.6/dist-packages but I'm running 2.7.2+ (and print sys.path sees 2.7 paths) ... so now I need to figure out why pip is putting things in the wrong place.
Try import bs4. It's unfortunate there's no correspondence between PyPI package name and import name. After that the class names are the same as before eg. soup = bs4.BeautifulSoup(doc) will work.
If that still doesn't work, try pip install again and note the path to the package install. Then in your python console run import sys and print sys.path to make sure that the path is there.
You might need to explicitly specify pip-2.7 or switch to easy_install (or easy_install-2.7)
Try this:
from bs4 import BeautifulSoup
I had this issue while using VS Code and the Pylance extension. I was able to resolve it by finding the location of my python packages (in my case it was "c:\python39\lib\site-packages"), and adding that to the external resolution paths in Pylance's settings. Pylance was then able to locate the import. I used below code segment to import BeautifulSoup from bs4.
from bs4 import BeautifulSoup
After trying the easy_install and pip if things dont work then download the tz package from the package website untar it in a folder. Now open cmd window and go to the directory where you unzip the tz and run the command 'python setup.py install' IT should work

Categories