pypub module for python - python

Getting this error while using epub python package or you can say epub library for python , wondering what to do about it. please help..
There are my codes:
import pypub
my_first_epub = pypub.Epub('My first Epub')
my_first_chapter = pypub.create_chapter_from_url('https://en.wikipedia.org/wiki/EPUB')
my_first_epub.add_chapter(my_first_chapter)
my_first_epub.create_epub('OUTPUT_DIRECTORY')
There are the errors:
runcell(0, 'E:/python练习/untitled0.py')
Traceback (most recent call last):
File E:\python练习\untitled0.py:8 in <module>
import pypub
File D:\anaconda3\lib\site-packages\pypub\__init__.py:2 in <module>
from epub import Epub
ImportError: cannot import name 'Epub' from 'epub' (D:\anaconda3\lib\site-packages\epub\__init__.py)

Pypub not available at python 3.x, only in python 2.x. Read docs (first point at tutorial): https://pypub.readthedocs.io/en/latest/tutorial_reddit.html

Related

Why does lottie throw ImportError: cannot import name 'PngRenderer' from 'lottie.exporters.cairo'?

Why does lottie give the error ImportError: cannot import name 'PngRenderer' from 'lottie.exporters.cairo'?
import lottie
from lottie.exporters.gif import export_gif
from lottie.parsers.tgs import parse_tgs
def convert_tgs_to_gif(tgs_file, gif_file):
try:
animation = parse_tgs(tgs_file)
export_gif(animation, gif_file, skip_frames=5, dpi=48)
return True
except Exception:
logging.exception("Error occurred while converting TGS to GIF.")
return False
Traceback errors:
Traceback (most recent call last):
File "C:\Users\Bubunduc\PycharmProjects\tg\main.py", line 11, in <module>
from lottie.exporters.gif import export_gif
File "C:\Users\Bubunduc\PycharmProjects\tg\venv\lib\site-packages\lottie\exporters\gif.py", line 5, in <module>
from .cairo import PngRenderer
ImportError: cannot import name 'PngRenderer' from 'lottie.exporters.cairo' (C:\Users\Bubunduc\PycharmProjects\tg\venv\lib\site-packages\lottie\exporters\cairo.py)
I tried to import this library in different ways, tried to understand the source code
Here the problem is in a completely different library. PngRenderer requires the cairosvg library. On windows, it requires libcairo-2.dll. Therefore, the solution to this problem is the correct installation of cairosvg.
Answer about installing cairosvg on windows.

Where can I find WidgetRedirector in with Python3?

I was using a tkform(https://github.com/boscoh/tkform) with Python2 and it was working perfectly.
After switching to Python3, Im unable to run it, specifically the part:
from idlelib.WidgetRedirector import WidgetRedirector
It seems that WidgetRedirecor.py not even in the library (idellib) anymore...
Traceback (most recent call last):
File "/Users/igor/opt/cymorph3/runCyMorphGUI.py", line 7, in <module>
import tkform
File "gui/tkform.py", line 22, in <module>
from idlelib import WidgetRedirector
ImportError: cannot import name 'WidgetRedirector' from 'idlelib' (/Users/igor/opt/anaconda3/envs/cyMorph3/lib/python3.9/idlelib/__init__.py)
Can I fix it somehow?
Use:
from idlelib.redirector import WidgetRedirector

Unable to import one python file into another [duplicate]

is there a way to import multiple python files into a main python file?
I have a bunch of py files and each one has to run in the main python file and the data are saved into a json file.
This is what I tried and it gave me an error.
import light.py as light
Error:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Desktop/majorproject/pillar1.py", line 8, in <module>
import sensorkey.py as sensorkey
ImportError: No module named 'sensorkey.py'; 'sensorkey' is not a package
I have also tried specifying the path to the py file and it didn't work either and keeps giving an invalid syntax error.
import /home/pi/Desktop/json/light.py as light
Update:
I managed to fix the import error but i now, after importing this light.py file, i have to print out certain keys from a dictionary (key) into this new file then export it to a json file. I'm currently using TinyDB to do so. Here are my codes:
from tinydb import TinyDB, Query
import json
from light import key
with open("/home/pi/Desktop/json/sensortestest.json", 'w+'):
db = TinyDB('/home/pi/Desktop/json/sensortestest.json')
table = db.table('Light')
db.insert_multiple([{'Key 1' :key[lightkey]}, {'Key 2' : key[lightkeyID]}])
Error:
Traceback (most recent call last):
File "/home/pi/Desktop/majorproject/testertestest.py", line 12, in <module>
db.insert_multiple([{'Key 1' :key[lightkey]}, {'Key 2' : key[lightkeyID]}])
NameError: name 'lightkey' is not defined
The problem is I had already defined 'lightkey' in its own file already.
To include the dictionary, you could do this if your file location is in different directory (with caution of path.append as #Coldspeed mentioned):
import sys
sys.path.append("path/foo/bar/")
from light import *
If it is in same directory as current directory, you could just do:
from light import *
The syntax for importing your_filename.py, assuming it is in the same directory, is
import your_filename
In your case, it would be
import light
Note the absence of .py.
If your file is in a different directory, you'll need to do:
import sys
sys.path.append('path/to/dir/containing/your_filename.py')
import your_filename
Note that appending to sys.path is dangerous, and should not be done unless you know what you're doing.
Read more at the official docs for import.

I am not able to use re module, my interpreter showing me error

My code is:
import re
s="An apple in a day."
print(re.search("in",s))
Error:
C:\Users\DELL\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/DELL/AppData/Local/Programs/Python/Python38-32/Lib/encodings/re.py
Traceback (most recent call last):
File "C:/Users/DELL/AppData/Local/Programs/Python/Python38-32/Lib/encodings/re.py", line 1, in <module>
import re
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38-32\Lib\encodings\re.py", line 3, in <module>
re.search("is",s)
AttributeError: partially initialized module 're' has no attribute 'search' (most likely due to a circular import)
Process finished with exit code 1
You name your file re.py so python confused which one to use when you call import re: your file or regexp library.
Try to rename your file to something else and not to choose other library names.

ImportError: cannot import name 'scan_videos' from 'subliminal'

I'm using the module subliminal to easily retrieve subtitles from the internet.
The CLI works perfectly, but I cannot import it as a module in a .py file.
The simplest code ever:
import os
from subliminal import scan_videos
videos = scan_videos('./')
print(videos)
And I always have this error:
Traceback (most recent call last):
File "subliminal.py", line 2, in <module>
from subliminal import scan_videos
File "/Users/louisbertin/Desktop/videos/subliminal.py", line 2, in <module>
from subliminal import scan_videos
ImportError: cannot import name 'scan_videos' from 'subliminal'
I don't know what I'm doing wrong. I had copy-pasted the code from the documentation:
https://github.com/Diaoul/subliminal
Seems like you called your script subliminal.py, which makes Python find it instead of the installed module. Rename the script and you should be fine.

Categories