hello I am a beginner in python and I have problems executing my code .
how can i fix this error with python:
import cgitb
cgitb.enable()
print('Content-type: text/html\r\n')
print('\r\n')
import Image, ImageDraw
import sys
import math, random
from itertools import product
from ufarray import *
ModuleNotFoundError: No module named 'Image'
args = ("No module named 'Image'",)
msg = "No module named 'Image'"
name = 'Image'
path = None
with_traceback = <built-in method with_traceback of ModuleNotFoundError
Make sure you have installed Pillow (the supported, open-source version of the PIL Python Image Library) and then change your import to:
from PIL import Image, ImageDraw
That should get you farther along.
Try this:
from PIL import Image
or else you haven't installed it yet:
pip install pillow
I had a similar Problem, this post helped me: How to insert an image in python
What they basically use is:
import Image
myImage = Image.open("your_image_here");
myImage.show();
For more help I would need your full code. Even after the edit it is not quite clear to me what is your code, what is the error and what you are actually trying to do.
Related
I alredy have a problem.
Show cairosvg as undefined. I wish save Turtle object as png.
I already installed the canvasvg and cairosvg libraries, but even so I keep getting the error. I leave my code as a sample. Thank you
from turtle import *
import os
import shutil
import tempfile
import canvasvg
from canvasvg import *
screen=Screen()
setup (640,520,0,0)
title("T")
tracer(0,0)
encendido='#51D1F6'
apagado='#922B3E'
pant=Turtle(visible=False)
pant.hideturtle()
pant.pensize(4)
pant.penup()
pant.goto(110,0)
pant.pendown()
pant.pendown()
pant.fillcolor(encendido)
pant.begin_fill()
pant.goto(-400,-180)
pant.goto(-400,-190)
pant.goto(-110,-190)
pant.end_fill()
Y=7
gb=Y*4
agua=Turtle(visible=False)
agua.pensize(4)
agua.penup()
agua.goto(110,-200)
agua.pendown()
agua.fillcolor(encendido)
agua.begin_fill()
agua.goto(110,-200+gb)
agua.penup()
agua.goto(-110,-200+gb)
agua.pendown()
agua.goto(-110,-200)
agua.goto(110,-200)
agua.end_fill()
update()
ts=getscreen().getcanvas()
tmpdir=tempfile.mkdtemp()
tmpfile=os.path.join(tmpdir,'tmp.svg')
canvasvg.saveall(tmpfile,ts)
name="image4.png"
with open(tmpfile) as svg_input, open(name, 'wb')as png_output:
cairosvg.svg2png(bytestring=svg_input.read(),write_to=png_output)
shutil.rmtree(tmpdir)
I am trying to make use of the streamlit SessionState, when I import SessionState. I get the following error: ModuleNotFoundError: No module named 'SessionState'
when using he SessionState
Here is a snipnet of my code:
from multiprocessing import Process
import streamlit as st
import SessionState
import time
import os
import signal
st.sidebar.title("Controls")
start = st.sidebar.button("Start")
stop = st.sidebar.button("Stop")
state = SessionState.get(pid=None)
Has anyone encountered this and how did you fix it? There are no resources online
https://docs.streamlit.io/en/stable/changelog.html?highlight=SessionState#version-0-54-0
Seems like you have to download this gist and put it into your project in order to use SessionState
I am trying a code to make a GUI but I keep on getting an error ModuleNotFoundError: No module named 'tkfilebrowser'.
There is a problem I get in the code that Unable to import 'tkfilebrowser'.
from PIL import Image
import tkinter
import tkinter.ttk
from tkinter import filedialog
from tkfilebrowser import askopendirname, askopenfilename, asksaveasfilename
def gendat(data):#convert data into binary data
newd=[]
for i in data:
newd.append(format(ord(i),'08b'))
return newd
def modpix(pix,data):#To return the modified pixels
datalist=gendat(data)
lendata=len(datalist)
imdata=iter(pix)
for i in range(lendata):
pix=[value for value in next(imdata)[:3] + next(imdata)[:3] + next(imdata)[:3]]
for j in range(0,8):
if (datalist[i][j]=='0') and (pix[j]%2!=0):
if (pix[j]%2!=0):
pix[j]-=1
elif (datalist[i][j]=='1') and (pix[j]%2==0):
pix[j]-=1
#0 means keep reading; 1 means the message is over.
if i==lendata-1:
if pix[-1]%2==0:
pix[-1]-=1
else:
if pix[-1]%2!=0:
pix[-1]-=1
pix=tuple(pix)
yield pix[0:3]
yield pix[3:6]
yield pix[6:9]
def encode_enc(data):
s2=tkinter.Tk()
name=askopenfilename()
image=Image.open(name,'r')
global newimg
newimg=image.copy()
hello according to the tkfilebrowser pypi describtion it is an alternative to a native tkinter module and need to be installed independently try
pip install tkfilebrowser
for more info
https://pypi.org/project/tkfilebrowser/
I've seen countless issues here on stack about this but still can't figure out why I cant get mine to work. I have a 2 .ipynb files and I'm looking to import a class from one file to the other as follows:
CV_Screening_Interface:
from joblib import dump, load
import sys
import pandas as pd
import os
import import_ipynb
import docx
import readDocx ***(This is another ipynb file)***
from docx import Document
import string
model = load('model.joblib')
class CV:
def __init__(self,university,major,masters,company,certification,GPA):
self.university = university
self.major = major
self.masters = masters
self.company = company
self.certification = certification
self.GPA = GPA
#And a bunch of other functions
Now in FirstProgram
from tkinter import *
from tkinter import filedialog
from docx import Document
import io
import import_ipynb
import CV_Screening_Interface
#Till here works fine
When I try to import class CV I get an import error
from CV_Screening_Interface import CV
OR
test = CV_Screening_Interface.CV()
ImportError: cannot import name 'CV' from 'CV_Screening_Interface' (CV_Screening_Interface.ipynb)
I checked PYTHONPATH, I have an empty init.py in the directory already. What's weird is that importing the module works, but importing the class in the module doesn't.
Note in CV_Screening_Interface CV class works perfectly fine so I don't think there is any issue with it specifically. Probably need a if name="main" inside it?
Ok so this solved my problems:
I created a new ipynb called ClassFile.ipynb and it only contains the Class CV without importing any packages
Then i converted ClassFile.ipynb to ClassFile.py and imported it to FirstProgram and it worked.
And I literally mean without replacing the '..'. I have seen this in the PySDL2-0.8.0 library:
from .. import sdlimage
The reason I ask myself this is because I am trying to run one of the examples they provided and reading the traceback leads me to a file that has this:
_HASPIL = True
try:
from PIL import Image
except ImportError:
_HASPIL = False
_HASSDLIMAGE = True
try:
from .. import sdlimage
except ImportError:
_HASSDLIMAGE = False
And of course at some point in the same file:
if not _HASPIL and not _HASSDLIMAGE:
raise UnsupportedError(load_image,
"cannot use PIL or SDL for image loading")
I do not have PIL (python imaging library) installed, but I do have the sdlimage.py file. So the file I am trying to run is:
/Library/Python/2.7/site-packages/sdl2/examples/helloworld.py
The path to sdlimage.py:
/Library/Python/2.7/site-packages/sdl2/sdlimage.py
And the file that raises UnsupportedError(load_image, "cannot use PIL or SDL for image loading"):
/Library/Python/2.7/site-packages/sdl2/ext/image.py
I think there is something fishy with these imports...Any ideas?
It's a relative import. More on this here: http://docs.python.org/3.3/tutorial/modules.html#intra-package-references