ERROR PYTHON: name 'cairosvg' is not defined - python

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)

Related

Cannot import name 'functional_datapipe' from 'torch.utils.data'

When I am running datasets_utils.py from '/usr/local/lib/python3.7/dist-packages/torchtext/data/datasets_utils.py' in Google Colab, the following error occurs even with the most updated versions of Python packages:
ImportError: cannot import name 'functional_datapipe' from 'torch.utils.data' (/usr/local/lib/python3.7/dist-packages/torch/utils/data/init.py)
Are there any solutions to solve such errors, as I could not find functional_datapipe even in the official torch.utils.data documentation? The following is excerpt from datasets._utils.py in the Google Colab environment
import functools
import inspect
import os
import io
import torch
from torchtext.utils import (
validate_file,
download_from_url,
extract_archive,
)
from torch.utils.data import functional_datapipe, IterDataPipe
from torch.utils.data.datapipes.utils.common import StreamWrapper
import codecs
It might be available only on torchdata.datapipes

ModuleNotFoundError: No module named 'SessionState

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

Cannot import class from module (circular reference issue?)

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.

Import image in python

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.

How to resolve "ImportError : no module named ... " in python?

Chaps I am going through what is apparently a #1 problem for python novice. I have been through some tutorials but I really can t get it works. Here is the code :
import time
from settings import *
from actif_class import *
from get_settings import *
from dataython import *
from spreadython import *
from tankython import *
if __name__ == "__main__":
t0 = time.clock()
settings = get_settings()
tickers = get_data_mp(settings)
list_spreads = get_list_spread(tickers,settings)
list_spreads_tank = tanking(list_spreads,settings)
spread_traitable = obtention_spreads_traitables(list_spreads_tank,settings)
print 'done. Timing',time.clock()-t0,'seconds'
and here is the stack :
ImportError: No module named datayhton
Even though the module DOES exist and is in the same folder as every other modules. It is able to see the get_settings one but not dataython. I ve tried on another machine but still got the same trouble.
I tried to go through import sys, sys.path.append but I might have done something wrong because it still doesnt work.
Any help would be much appreciated.
EDIT : still doesnt work when I write this on top of my code :
import time
import sys
sys.path.append("/path/to/dataython")
Ok. I got it now. Not a no brainer so here is the amended code :
import time
import sys
sys.path.append("path/to/your/file")
import your_file
the mistake I was doing was keep writing :
from your_file import *

Categories