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

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.

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.

pypub module for 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

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

Importing module item of subpackage from another subpackage

I have this project structure:
root_package/
root_package/packA/
root_package/packA/__init__.py (empty)
root_package/packA/moduleA.py
root_package/packB/__init__.py (empty)
root_package/packB/moduleB.py
root_package/rootModule.py
In the rootModule.py I have from packA.moduleA import ModuleAClass.
At the packA.moduleA.py I have this from root_package.packB.moduleB import ModuleBItem.
When running rootModule either via PyCharm or the terminal with python ./rootModule.py I am getting this error:
Was this the right way of importing?
Traceback (most recent call last):
File "/project_dir/rootPackage/rootModule.py", line 7, in <module>
from packA.moduleA import ModuleAClass
File "/project_dir/rootPackage/packA/moduleA.py", line 8, in <module>
from rootPackage.packB.moduleB import module_b_method
File "/project_dir/rootPackage/rootModule.py", line 7, in <module>
from packA.wavelet_compression import WaveletCompression
ImportError: cannot import name WaveletCompression
How to solve this?
Update 1
I've added a test file at the project_folder (not the root_package folder).
So the current directory structure is this:
project_folder/
project_folder/root_package/
project_folder/root_package/packA/
project_folder/root_package/packA/__init__.py (empty)
project_folder/root_package/packA/moduleA.py
project_folder/root_package/packB/__init__.py (empty)
project_folder/root_package/packB/moduleB.py
project_folder/root_package/rootModule.py
project_folder/test_rootModule.py
I haven't made the project_folder a package (no __init__.py file) since, the test_rootModule is simply a script to help me run the experiments.
So, in root_package/packA/moduleA.py, after changing the from root_package.packB.moduleB import ModuleBitem, to from packB.moduleB import ModuleBitem, as the answer suggests, it works.
But now there are two problems:
1. PyCharm doesn't agree with the change:
I cannot run my experiments from the project_folder/test_rootModule.py script.
I got this error:
Traceback (most recent call last):
File "project_folder/test_rootModule.py", line 8, in
from root_package.rootModule import rootModuleClass
File "project_folder/root_package/rootModule.py", line 7, in
from packA.moduleA import ModuleAClass
File "project_folder/root_package/packA/moduleA.py", line 8, in
from packB.moduleB import module_b_item
ImportError: No module named packB.moduleB
I cannot seem to get the 2nd Traceback to look like a code segment.
Update 2
What solved the problem was going to the Project: project_name > Project Structure dialog in PyCharm, selecting the root_package and then setting it as a Sources folder.
Now, I can run via the IDE both the rootModule and the test_rootModule.
Although, I cannot get to run the test_rootModule from the terminal.
The test_rootModule has these imports:
from root_package.rootModule import RootModuleClass
from root_package.packB.moduleB import module_b_item
I am at the project_folder dir, and run python ./test_rootModule.py and get this error:
Traceback (most recent call last):
File "./test_rootModule.py", line 8, in <module>
from root_package.rootModule import RootModuleClass
File "project_folder/root_package/rootModule.py", line 7, in <module>
from packA.moduleA import ModuleAClass
File "project_folder/root_package/packA/moduleA.py", line 8, in <module>
from packB.moduleB import module_b_item
ImportError: No module named packB.moduleB
If you are running all your code from within this path:
project_folder
Then you should ensure that all your modules that reside in root_package are referenced by that first. So for example:
from root_package.modA import foo

ImportError: cannot import name

For some reason I receive an ImportError every time I try to import a class from another file. Here's the github page for my project: https://github.com/wheelebin/mcnextbot
Here's the error that I'm receiving:
Traceback (most recent call last):
File "ircbot.py", line 36, in <module>
from test import mcnextlvl
ImportError: cannot import name mcnextlvl
Here your from test import something refers to the module test in <PYTHONPATH>/lib, not yourselves test.py, and there is no submodule/class mcnextlvl there. You should use from lib.test import mcnextlvl as #sgmart commented.
The __init__.py python file allow you can import your individual modules named 'test' from the lib package.

Categories