importing beautiful soup using python 3.6 on OS X - python

please help!
I am using a macbook running OS X 10.10.5
I am trying to install and then import beautifulsoup using python 3.6 but am getting the following error:
ModuleNotFoundError: No module named ‘beautiful soup’
This is what I have done:
installed python 3.6, this has installed in the applications folder, this is working fine with idle.
downloaded and installed beautifulsoup4, installed using: sudo python setup.py install. This has installed beautifulsoup4-4.5.3-py2.7.egg files into the Library/2.7/site-packages directory
My code is as follows:
import sys
sys.path.append("Macintosh HD/Library/Python/2.7/site-packages")
import beautifulsoup4
Any ideas? Many thanks in advance.

Have you ever checked the documentation of that package?
You import this package as below:
from bs4 import BeautifulSoup

Related

how to fix ModuleNotFoundError: no module named bs4

I am trying to create a program that takes a set of numbers from a webpage and adds them up together. I used the beautifulsoup module that I installed(ran "pip install beautifulsoup4 in command prompt).
Code:
from bs4 import BeautifulSoup
web=request.urlopen('http://py4e-data.dr-chuck.net/comments_845350.html').read()
x = BeautifulSoup(html)
tags=x('span')
sum=0
for tag in tags:
sum = sum+int(tag.contents[0])
print(sum)
However, whenever I run the program, python gives me a ModuleNotFoundError: no module named bs4. How can I fix this?
If you look here, you see that
pip install beautifulsoup4 should do the job.
If you are on Linux you might have to use pip3 instead.
Do you have more than one version of Python installed on your machine?
If so, try running
pip --version
Will return something like this
pip 18.1 from c:\...\lib\site-packages\pip (python 3.6)
Then verify if you are using the same version to run your script

Python wkhtmltopdf can't import module

I am using Python version 3.6, Django version 1.9 and wkhtmltopdf version 0.2. My Python is not GCC it's Anaconda3.
When running my project which uses wkhtmltopdf, following error will be thrown:
from main import WKhtmlToPdf, wkhtmltopd
ModuleNotFoundError: No module named 'main'
This is how I imported the wkhtmltopdf:
import pdfkit
from wkhtmltopdf.views import PDFTemplateView
Yes i got the answer. This error occurred because i didn't installed django-wkhtmltopdf.
installed >> `pip install django-wkhtmltopdf
I hope this answer will help to resolve the similar error.
after installing pdfkit with following command and pointing python version 3.8, i was able to get pdfkit working on mac
pip3 install pdfkit

Exporting Python 3.5 and Tkinter to EXE or MSI

I'm using Python 3.5 and would like to export my python code for me to send to others who do not have Python installed. Thing is Pyinstaller doesn't work as I get this error:
CX_Freeze also doesn't work for me either as Tkinter still presents a problem, on running python setup.py build I get:
KeyError: 'TCL_LIBRARY'
I'm getting sick of this to be frank so any help would be appreciated. Here's my imports in my code if it helps
import pdb
from tkinter import *
from tkinter import filedialog
import tkinter.messagebox
from datetime import datetime, date, timedelta
import pandas as pd
import numpy as np
from xlsxwriter.utility import xl_rowcol_to_cell
If you are using an older version of cx_Freeze(<5.0), it doesn't have Python35 support. The latest development version has Python35 support. You can install it by
pip install cx-Freeze-win
But you need to have VC++ run-time installed on your system to run this successfully.
Also I've found this GitHub-repo with pre-built binary packages of cx_Freeze 5 for windows platform.
pip install wheel
https://raw.githubusercontent.com/sekrause/cx_Freeze-Wheels/master/cx_Freeze-5.0-cp35-cp35m-win_amd64.whl
Well I managed to get it working by downloading Pyinstaller from the website and running the commands in the new folder. I followed the steps in this answer here.

ImportError: No module named bs4 in Windows

I am trying to create a script to download the captcha from my website.
I think the code works except from that error, when I run it in cmd (I am using windows not Linux) I receive the following:
from bs4 import BeautifulSoup
ImportError: No module named bs4
I tried using pip install BeautifulSoup4
but then I receive a syntax error at install.
Here is the script:
from bs4 import BeautifulSoup
import urllib2
import urllib
url = "https://example.com"
content = urllib2.urlopen(url)
soup = BeautifulSoup(content)
img = soup.find('img',id ='imgCaptcha')
print img
urllib.urlretrieve(urlparse.urljoin(url, img['src']), 'captcha.bmp')
The problem according to this answer must be due to the fact I have not activated the virtualenv, and THEN install BeautifulSoup4.
I don't think this information will be of any help but I saved my python text in a notepad.py and the run it using cmd.
I had the same problem until a moment ago. Thanks for the post and comments! According to #Martin Vseticka 's suggestion I checked if I have the pip.exe file in my python folders. I run python 2.7 and 3.7 simultaneously. I didn't have it in the python 2.7 folder but in the 3.7.
So in the command line I changed the directory to where the pip.exe file was located. Then I ran "pip install BeautifulSoup4" and it worked. See enclosed screen shot.
I did a fresh install of Python 3.5 on my Windows 8.1 (64b) machine and then run:
C:\Users\Me\AppData\Local\Programs\Python\Python35-32\Scripts>pip install b
eautifulsoup4
Collecting beautifulsoup4
Downloading beautifulsoup4-4.4.1-py3-none-any.whl (81kB)
100% |################################| 81kB 890kB/s
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.4.1
and then run:
C:\Users\Me\AppData\Local\Programs\Python\Python35-32>python test.py
test.py contains only:
from bs4 import BeautifulSoup
I received no error.
I could install bs4, but still got an error message like yours. My operation system is 64 bit, and I only had this issue after I installed the latest Python in "32 bit" version. So I removed the 32 bit one, then I can import the bs4 again, and it still works after I install the latest Python in 64 version. Hope it helps.
I have python3.7 32bit and python3.7 64 bit installed on Windows 10.
For this app, I am using the 32 bit version.
I was getting the following error:
ImportError: No module named bs4
when I was trying to 'import bs4' from my app.py. Someone said: "Make sure your pip and your python are both 32 bits", but omitted to explicitly say how, so here it is:
Delete your virtual environment if it exists.
Create a new venv using python -m venv venv, but explicitly call it from your 32bit python directory like this:
C:\Users\me\AppData\Local\Programs\Python\Python37-32\python -m venv my_venv
install the requirements by explicitly calling the 32bit version like this:
C:\Users\me\AppData\Local\Programs\Python\Python37-32\Scripts\pip install -r requirements.txt
That's it. I hope it works.

Beautiful Soup 4 Import

So I'm getting an import error on this line:
from bs4 import BeautifulSoup
It says:
ImportError: no module named 'bs4'
Any idea what's going on / how to fix this?
Thanks,
Mariogs
import sys; print(sys.path) shows that you use Python 3.3 but the output from pip shows that it installs for Python 2.7
Use pip that installs for Python 3.3. It might be already installed as pip3 or pip3.3. If not; then install it first.

Categories

Resources