I'm using the Python pillow module, but every time I try to import it and use a function, it gives me an error. Here is some code to reproduce the error.
import PIL
PIL.ImageGrab.grab()
You have to use from to import from PIL.
from PIL import ImageGrab
ImageGrab.grab()
Related
I've looked over 30 different pages and couldn't find the answer I needed. I'm using a windows 10 and I'm using python 3.9.0. So I installed Pillow 8.1.0 like this:
python3 -m pip install --upgrade Pillow
Then tried to import pillow into the shell using:
import PIL
import Pillow
import pillow
from Pillow import Image
from PIL import Image
from PIL import *
from Pillow import *
but I got the ModuleNotFoundError every time.
Do you have another way to put pillow into the python shell?
Thanks for the answer in advance😄.
If you're still having trouble, try this:
in your python terminal run:
import sys
print(f'"{sys.executable}" -m pip install pillow')
print(f'"{sys.executable}" -m pip install requests')
then, with the printouts you get, run your windows command prompt as an admin (right click -> run as admin) then paste the 2 commands you get back. restart python and you SHOULD be good to go.
With python 3.9 and above using Pillow 8.1.0, use
from pil import Image.
I am very new to Python and have used BeautifulSoup to parse and scrape information from some webpages. Now I need to fill out a form. submit it, and scrape some data after filling in the form, and it seems the easiest way is to use robobrowser.
However, I can't import robobrowser. I have installed robobrowser several different ways and robobrowser is located here:
C:\Users\(USERNAME)\AppData\Local\Programs\Python\Python37-32\Lib\site-packages
Here is my script:
import requests
from bs4 import BeautifulSoup
import datetime
import webbrowser
import re
from robobrowser import RoboBrowser
br = RoboBrowser()
etc....
The problem is the script will not run past "from robobrowser import RoboBrowser" and I get the following message:
ImportError: cannot import name 'RoboBrowser' from 'robobrowser'
Maybe your robobrowser package is corrupted
Now try Installing robobrowser using PyPI
first check if python package named as PyPI is installed on your system using this command in your terminal
pip --version
if it is installed then it will show the output like that
To install robobrowser using PyPI run this command in your terminal
pip install robobrowser
now import it
from robobrowser import RoboBrowser
br = RoboBrowser()
I'm working with MacOS, I've installed Python and iPython, but when I type:
import nltk
ipython tells me that there is no module named nltk. However, when I type in:
import sys
import nltk
It works perfectly fine. Can someone explain why this isn't working correctly? I'm a newbie to Python so please be gentle. Thanks.
I did conda install for numpy, pandas, scipy, and scikit-learn apparently all successful. I also tried to change the path in the Windows 10 registry. I only have 1 version of Python, 3.6 installed. I also installed Visual Studio. If I run the script, I get "scipy module not found". Can you explain me what's the problem, and how to fix this?
My imports look like this:
import pandas as pd
import quandl, math
import numpy as np
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
I'm following this tutorial by Sentdex:
https://www.youtube.com/watch?v=r4mwkS2T9aI&index=4&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v
from sklearn.linear_modelsklearn._model import SGDClassifierNo module named linear_modelsklearn._model
I am on OSX version 10.9.4
Python 2.7.6
numpy 1.9.0
scipy 0.14.0
scikit-learn 0.15.2 What I am missing? Thanks.(import sklearn works fine but not the model)
Your import seems wrong, try:
from sklearn.linear_model import SGDClassifier