Unable to use moviepy library - python

I am writing a program to convert video to audio using moviepy library. Problem is that I have installed this library import moviepy.editor as mp
but when I run my program I am facing an error as follows:
PS D:\MPhil CS\Semester 2\Multimedia Retrieval Techniques\Assignment1\MRT_Assignment1> &
'C:\Users\User\AppData\Local\Programs\Python\Python39\python.exe'
'c:\Users\User\.vscode\extensions\ms-python.python-
2021.3.658691958\pythonFiles\lib\python\debugpy\launcher' '61484' '--' 'd:\MPhil CS\Semester
2\Multimedia Retrieval Techniques\Assignment1\MRT_Assignment1\mrt_retreival.py'
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-
packages\IPython\utils\timing.py", line 27, in <module>
import resource
ModuleNotFoundError: No module named 'resource'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:\MPhil CS\Semester 2\Multimedia Retrieval
Techniques\Assignment1\MRT_Assignment1\mrt_retreival.py", line 5, in <module>
import moviepy.editor as mp
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\moviepy\editor.py", line
56, in <module>
from .video.io.html_tools import ipython_display
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-
packages\moviepy\video\io\html_tools.py", line 22, in <module>
from IPython.display import HTML
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\IPython\__init__.py",
line 49, in <module>
from .terminal.embed import embed
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-
packages\IPython\terminal\embed.py", line 19, in <module>
from IPython.terminal.ipapp import load_default_config
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-
packages\IPython\terminal\ipapp.py", line 30, in <module>
from IPython.core.magics import ScriptMagics
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-
packages\IPython\core\magics\__init__.py", line 21, in <module>
from .execution import ExecutionMagics
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-
packages\IPython\core\magics\execution.py", line 46, in <module>
from IPython.utils.timing import clock, clock2
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-
packages\IPython\utils\timing.py", line 64, in <module>
clocku = clocks = clock = time.clock
AttributeError: module 'time' has no attribute 'clock'
I am using VScode and my python version is 3.9.0. My code is as follows:
from pytube import YouTube
from youtube_transcript_api import YouTubeTranscriptApi
import ffmpeg
import moviepy.editor as mp
# where to save
SAVE_PATH = "D:\\MPhil CS\\Semester 2\\Multimedia Retrieval
Techniques\\Assignment1\\MRT_Assignment1\\Video" #to_do
# link of the video to be downloaded
link="https://www.youtube.com/watch?v=2DFzxsy3PaM"
try:
# object creation using YouTube
# which was imported in the beginning
yt = YouTube(link)
except:
print("Connection Error") #to handle exception
try:
print("*********************** Video Title ***************************")
print(yt.title)
print("\n")
print("*********************** Video Subtitles
***************************")
srt = YouTubeTranscriptApi.get_transcript("2DFzxsy3PaM")
with open("subtitles_file.txt", 'w') as f:
f.writelines('%s\n' % i for i in srt)
print("Subtitles written!!")
print("\n")
print("Downloading start...")
yt.streams.filter(file_extension= 'mp4').first().download(SAVE_PATH)
print("Video Downloaded!!")
my_clip = mp.VideoFileClip(r"D:\\MPhil CS\\Semester 2\\Multimedia
Retrieval Techniques\\Assignment1\\MRT_Assignment1\\Video\\A fight
against the norm - 1 minute spoken word poetry for introverts.mp4")
my_clip.audio.write_audiofile(r"D:\\MPhil CS\\Semester 2\\Multimedia
Retrieval Techniques\\Assignment1\\MRT_Assignment1\\Video\\abc.mp3")
print("Audio Downloaded!!")
except:
print("Some Error!")
print('Task Completed!')
I am new to Python and I am unable to resolve this. Thanks in advance for help.

AttributeError: module 'time' has no attribute 'clock'
If you are using Python 38 and above, time. clock() is deprecated from the version (https://bugs.python.org/issue31803)
So you can use time.perf_counter() instead of time.clock()

The error is happening inside import moviepy.editor as mp so the rest of your code is irrelevant.
It seems to be a bug in the IPython package being called by moviepy.editor. Check that it is fully up-to-date.
Alternatively you can avoid moviepy.editor entirely and do from moviepy.video.io.VideoFileClip import VideoFileClip.

Related

Errors in image background remover using Python with rembg and PIL - getting error in the modules I think?

So I'm making a super simple python program using rembg and PIL that I found on the internet. I'm getting an error that seems to be an issue with the module rembg or numpy, but I can't be sure. This is what the code looks like:
from rembg import remove
from PIL import Image
input_path = 'ballroom1.jpg'
output_path = 'output.png'
input = Image.open(input_path)
output = remove(input)
output.save(output_path)
Now these are the errors:
Traceback (most recent call last):
File "D:\PyCharm\BackgroundRemover\Remove.py", line 1, in <module>
from rembg import remove
File "D:\PyCharm\Python\rembg\__init__.py", line 5, in <module>
from .bg import remove
File "D:\PyCharm\Python\rembg\bg.py", line 5, in <module>
import numpy as np
File "D:\PyCharm\Python\numpy\__init__.py", line 124, in <module>
from numpy.__config__ import show as show_config
File "D:\PyCharm\Python\numpy\__config__.py", line 12, in <module>
os.add_dll_directory(extra_dll_dir)
AttributeError: module 'os' has no attribute 'add_dll_directory'
Now, I have numpy 1.23.5 rembg 2.0.30
Any help understanding what's going on would be much appreciated.
Thanks
I've tried reinstalling both numpy and rembg but received the same errors

Whenever I run my discord bot using discord.py I'm getting an AttributeError 'logging' has no attribute 'getlogger'

All my code is on github except for the token.py file for obvious reasons.
bot.py file
I have had similar issues in the past and have resolved them by reconstructing some code so I apologize in advance if this is another one of those issues where I missed a capital or something but I have tried all the obvious syntax issues and none of them seemed to work. Atom also didn't show any errors.
Here is the whole error message:
Traceback (most recent call last):
File "C:\Users\james\Documents\botpy\bot.py", line 5, in <module>
import discord
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\__init__.py", line 21, in <module>
import logging
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\logging\__init__.py", line 26, in <module>
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\traceback.py", line 5, in <module>
import linecache
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\linecache.py", line 11, in <module>
import tokenize
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\tokenize.py", line 34, in <module>
from token import *
File "C:\Users\james\Documents\botpy\token.py", line 2, in <module>
from discord.ext import commands
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\__init__.py", line 13, in <module>
from .bot import Bot, AutoShardedBot, when_mentioned, when_mentioned_or
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 27, in <module>
import asyncio
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\__init__.py", line 8, in <module>
from .base_events import *
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\__init__.py", line 8, in <module>
from concurrent.futures._base import (FIRST_COMPLETED,
File "C:\Users\james\AppData\Local\Programs\Python\Python38-32\lib\concurrent\futures\_base.py", line 42, in <module>
LOGGER = logging.getLogger("concurrent.futures")
AttributeError: partially initialized module 'logging' has no attribute 'getLogger' (most likely due to a circular import)
Try to rename your file into main.py
I had a similar error just because the filename.

Getting the following error: AttributeError: module 'pandas' has no attribute 'read_csv'

I have looked at several other similar questions but their fixes are not working for me. I am running my script in a conda venv but I already installed pandas within said environment. I will show my code and the error I get when running from the terminal. Obviously, the directory of the virtual environment is not the same as the directory of my css file, which is why I give the file path to the file. I must add that within VS Code, I am able to get the data set and add items to the list I created (although the while loop is not currently working). Can anyone help?
import pandas as pd
import random
data_set = pd.read_csv("/Users/rickvillanueva/Documents/Myron/dated_random.csv")
random_data = data_set.MYRON_ACCT
random_names = []
random_gatherer = True
#Gathering random account numbers
while random_gatherer:
one = random.choice(random_data)
random_names.append(one)
if len(random_names) < 50:
random_gatherer = True
continue
else:
break
len(random_names)
print(random_names)
Error I get in terminal:
Traceback (most recent call last):
File "random.py", line 1, in <module>
import pandas as pd
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/pandas/__init__.py", line 11, in <module>
__import__(dependency)
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/numpy/__init__.py", line 152, in <module>
from . import random
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/numpy/random/__init__.py", line 181, in <module>
from . import _pickle
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "_bit_generator.pxd", line 14, in init numpy.random.mtrand
File "_bit_generator.pyx", line 40, in init numpy.random._bit_generator
File "/Users/rickvillanueva/opt/anaconda3/lib/python3.7/secrets.py", line 20, in <module>
from random import SystemRandom
File "/Users/rickvillanueva/Documents/Myron/random.py", line 5, in <module>
data_set = pd.read_csv("/Users/rickvillanueva/Documents/Myron/dated_random.csv")
AttributeError: module 'pandas' has no attribute 'read_csv'

Having an import error with discord.py

I'm trying to build a discord bot, and I have this error that I can't seem to figure out that explicitly happens when I try to import discord.py
The error message is:
Traceback (most recent call last):
File "C:/Users/Pastry/PycharmProjects/PastryBot/sample.py", line 1, in <module>
import discord
File "C:\Python35\lib\site-packages\discord\__init__.py", line 20, in <module>
from .client import Client, AppInfo, ChannelPermissions
File "C:\Python35\lib\site-packages\discord\client.py", line 28, in <module>
from .user import User
File "C:\Python35\lib\site-packages\discord\user.py", line 27, in <module>
from .utils import snowflake_time
File "C:\Python35\lib\site-packages\discord\utils.py", line 31, in <module>
import asyncio
File "C:\Python35\lib\asyncio\__init__.py", line 21, in <module>
from .base_events import *
File "C:\Python35\lib\asyncio\base_events.py", line 18, in <module>
import concurrent.futures
File "C:\Python35\lib\concurrent\futures\__init__.py", line 17, in <module>
from concurrent.futures.process import ProcessPoolExecutor
File "C:\Python35\lib\concurrent\futures\process.py", line 55, in <module>
from multiprocessing.connection import wait
File "C:\Python35\lib\multiprocessing\connection.py", line 18, in <module>
import tempfile
File "C:\Python35\lib\tempfile.py", line 45, in <module>
from random import Random as _Random
ImportError: cannot import name 'Random'
I tried using the sample code from the quickstart bot guide on their documentation page as well, and ran into the same error. I thought it was a problem with my version of discord.py so I tried to update it, and then re-ran the program but I'm still getting this error. Could anyone help enlighten me?
Did you download the discord.py library? that could be the the problem. What about the asyncio library? Those two are most likely.

Why am I getting an import error upon importing multiprocessing?

I have a script which requires multiprocessing. What I found from this script is that there is a problem with the multiprocessing module. To test this theory, I copied and pasted
from multiprocessing import Process
def f(name):
print('hello', name)
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
p.join()
into a test script and received the following traceback
Traceback (most recent call last):
File "a.py", line 1, in <module>
from multiprocessing import Process
File "/usr/lib64/python3.3/multiprocessing/__init__.py", line 40, in <module>
from multiprocessing.util import SUBDEBUG, SUBWARNING
File "/usr/lib64/python3.3/multiprocessing/util.py", line 16, in <module>
import threading # we want threading to install it's
File "/usr/lib64/python3.3/threading.py", line 11, in <module>
from traceback import format_exc as _format_exc
File "/usr/lib64/python3.3/traceback.py", line 3, in <module>
import linecache
File "/usr/lib64/python3.3/linecache.py", line 10, in <module>
import tokenize
File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
from token import *
File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
from django.conf import settings
File "/usr/lib/python3.3/site-packages/django/conf/__init__.py", line 9, in <module>
import logging
File "/usr/lib64/python3.3/logging/__init__.py", line 195, in <module>
_lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'
Also, I am running fedora 18 64-bit on a quad core ivy bridge. Why am I receiving this traceback error?
Suggestion
Here is what happens when I run RLock
$ python3
>>> import threading
>>> threading.RLock()
<_thread.RLock owner=0 count=0>
>>>
File "/usr/lib64/python3.3/tokenize.py", line 30, in <module>
from token import *
File "/home/lucas/Server/ClinApp/weblabs/utils/token.py", line 1, in <module>
from django.conf import settings
Your /home/lucas/Server/ClinApp/weblabs/utils/token.py script is being imported instead of the standard python 'token.py'. Its got a bug in it or it simply shouldn.t be imported as a top level script. You probably have /home/lucas/Server/ClinApp/weblabs/utils/ in your python path in some way.
Generally, its not a good idea to name python scripts after builtin scripts.
After you rename token.py to something else (get_token.py), remember to delete token.pyc in your local working directory. Or else, you will continue to get the Traceback error message you listed above.

Categories

Resources