Edit: Trying to get these libraries to work in python 3.3 was clearly the wrong approach, and my problem now is entirely different so I'll just re-ask it in a new question.
I want to be able to edit ID3 tags of mp3 files with python commands, for example something like setAlbumName("folderPath\song.mp3", "albumname"). So far I've tried Mutagen, PyID3, pytagger, eyeD3, and they all seem to be outdated because the installation fails due to syntax errors. I tried to fix it in eyeD3, but I hit a dead end: http://i41.tinypic.com/o6zklv.png (second screenshot from after I had fixed all the prints and "except Error, e" and so on).
I tried the same with Mutagen, but I ran into a wall there as well when replacing "raise KeyError, key" with "raise KeyError as key" didn't work.
I didn't even know what to make of this one (pytagger): http://i41.tinypic.com/29fz7mh.png
It seems to suggest that there's something wrong with my python installation? Not getting into that.
So, would anyone like to point me to an ID3 package that works, or have a go at fixing an outdated one?
(Also, I tried both "python setup.py install" and "setup.py install" and it seemed to make no difference. I'm on windows 8.)
Edit: From the screenshot below, plus the source code (mutagen with python 2.7.5)
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.pprint()
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 5, in <module>
audio.pprint()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 138, in pprint
try: tags = self.tags.pprint()
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 190, in pprint
frames = list(map(Frame.pprint, self.values()))
TypeError: unbound method pprint() must be called with Frame instance as first a
rgument (got str instance instead)
_
from mutagen.mp3 import MP3
p = "E:\\Musik\\Aeon\\2005 Bleeding the False\\01 Cenobites - Copy.mp3"
audio = MP3(p)
audio["title"] = "An example"
audio.save()
_
Traceback (most recent call last):
File "id3tag.py", line 7, in <module>
audio.save()
File "C:\Python27\lib\site-packages\mutagen\__init__.py", line 132, in save
return self.tags.save(filename, **kwargs)
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 370, in save
framedata = [self.__save_frame(frame) for (key, frame) in frames]
File "C:\Python27\lib\site-packages\mutagen\id3.py", line 461, in __save_frame
framedata = frame._writeData()
AttributeError: 'str' object has no attribute '_writeData'
mutagen works great for me with Python 2.7.
examples:
https://code.google.com/p/mutagen/wiki/Tutorial
from mutagen.mp3 import MP3
audio = MP3("example.mp3")
audio["title"] = "An example"
audio.pprint()
audio.save()
p.s. please post code samples so people can help.. not links to screenshots.
p.p.s. it looks like you are trying to install Python2 libs into Python3.
Mutagen also has an EasyID3 tool, which handles simple tasks like changing the file's title:
from mutagen.easyid3 import EasyID3
f = EasyID3("file.mp3")
f["title"] = u"Some title"
f.save()
Works like a charm. But it has very restricted functionality.
See more examples at http://code.google.com/p/mutagen/wiki/Tutorial
Related
Hello I have a problem with pupil_apriltags in python.
I have been searching for more than 1 week and tried multiple solutions but none of them worked.
My problem is not with the import of the librairy but when I try to create the detector. There is a reference to a xxxx.dll file (I think) which does not work.
My code
Very simple
from pupil_apriltags import Detector
import cv2
import numpy as np
at_detector = Detector(families='tag36h11',
nthreads=1,
quad_decimate=1.0,
quad_sigma=0.0,
refine_edges=1,
decode_sharpening=0.25,
debug=0)
My error
Traceback (most recent call last):
File "detection_apriltags.py", line 6, in <module>
at_detector = Detector()
File "C:\Users\Utilisateur\anaconda3\lib\site-packages\pupil_apriltags\bindings.py", line 285, in __init__
self.libc = ctypes.CDLL(str(hit))
File "C:\Users\Utilisateur\anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\Utilisateur\anaconda3\lib\site-
packages\pupil_apriltags\lib\apriltag.dll' (or one of its dependencies). Try using the full path
with constructor syntax.
My configuration
Python 3.8.5
Windows 10
so i didn't find the solution with pupils-Apriltags (on Windows) but i discorver Aruco which is derectly in Opencv ( with the package : opencv-contrib-python, at this day).
arucoDict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50)
arucoParams = cv2.aruco.DetectorParameters_create()
(corners, ids, rejected) = cv2.aruco.detectMarkers(image, arucoDict,parameters=arucoParams)
Thanks to the comment from Manuel Valenzuela I was able to solve the problem and I made a PR to the pupil-apriltags repo; after this the issue should no longer be a problem.
https://github.com/pupil-labs/apriltags/pull/48
As Manuel says, this is an issue in Python 3.8 and up with the DLL search. The one who really figured it out was #Mad Physicist though:
https://stackoverflow.com/a/64472088/1832942
I am Following Chris P's 'Visualize Real-world JSON Data in Blender (3D Chart Animation Nodes Tutorial)' on YouTube but I seem to have got stuck at the first hurdle of importing the data. I have followed his instructions completely and am unsure why the script keeps failing. I have attached his script, My script, my file location, my error message and a snap shot of his video. I am On windows OS, he is on Linux I'menter image description here not sure if that makes a difference. Here is the link to the video: https://www.youtube.com/watch?v=0aRjInmibSw&t=1055s THE TIMESTAMP FOR HIS CODE IS 6 min.
FILE NAME: Export.json
MY FILE LOCATION: C:\Users\Jordan\Downloads
MY CODE
import json
with open(r'C:/Users/Jordan/Downloads/Export.json','r') as f:
j=json.load(f)
print (j)
MY ERROR MESSAGE:
Traceback (most recent call last):
File "D:\Mixed Graphs\Blender json\3D Charts.blend\My Script", line 3, in <module>
OSError: [Errno 22] Invalid argument: '/C:/Users/Jordan/Downloads/Export'
Error: Python script failed, check the message in the system console
HIS CODE:
import json
with open('/Home/chris/downloads/tutorial1.json') as f:
json.load(f)
print (j)
Your problem seems to be that you're using "/"(slash) instead of ""(backslash) on Windows.
In addition you need to use two "\" as one backslash signals an escaping for the next character.
Fix therefore should be:
import json
with open(r'C:\\Users\\Jordan\\Downloads\\Export.json','r') as f:
j=json.load(f)
print (j)
I need to get a list of all albums of my YouTube Music uploads library with ytmusicapi and I never work with Python before. I created the headers_auth.json and a test.py file with the following code from the example:
from ytmusicapi import YTMusic
ytmusic = YTMusic('headers_auth.json')
playlistId = ytmusic.create_playlist("test", "test description")
search_results = ytmusic.search("Oasis Wonderwall")
ytmusic.add_playlist_items(playlistId, [search_results[0]['videoId']])
I ran from the Ubuntu terminal: python /home/do/Desktop/ytmusicapi/ytmusicapi-master/test.py
Result error:
Traceback (most recent call last): File
"/home/do/Desktop/ytmusicapi/ytmusicapi-master/test.py", line 1, in
from ytmusicapi import YTMusic File "/home/do/Desktop/ytmusicapi/ytmusicapi-master/ytmusicapi/init.py",
line 2, in
from ytmusicapi.ytmusic import YTMusic File "/home/do/Desktop/ytmusicapi/ytmusicapi-master/ytmusicapi/ytmusic.py",
line 28
auth: str = None,
^ SyntaxError: invalid syntax
How to fix that?
This is because you are using a different version of Python.
The library you are using requires Python>=3.5 wheraas you seem to be using Python2.
If you are curious this code
def f(x:int):
return
is valid in Python3.5+ versions but not in Python2.
You will have to either switch to Python3 to use that library or else you can clone the repo and convert the whole repo to Python2 using something like this(though there might be other ways too).
I'd recommend you simply switch to Python3.5 or higher.
I recently made a program using an external document with pickle. But when it tries to load the file with pickle, I got this error (the file is already existing but it also fails when the file in't existing):
python3.6 check-graph_amazon.py
a
b
g
URL to follow www.amazon.com
Product to follow Pool_table
h
i
[' www.amazon.com', ' Pool_table', []]
p
Traceback (most recent call last):
File "check-graph_amazon.py", line 17, in <module>
tab_simple = pickle.load(doc_simple)
io.UnsupportedOperation: read
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "check-graph_amazon.py", line 42, in <module>
pickle.dump(tab_simple, 'simple_data.dat')
TypeError: file must have a 'write' attribute
Here is the code :
import pickle5 as pickle
#import os
try:
print("a")
with open('simple_data.dat', 'rb') as doc_simple:
print("b")
tab_simple = pickle.load(doc_simple)
print("c")
print(tab_simple)
print("d")
URL = tab_simple[0]
produit_nom = tab_simple[1]
tous_jours = tab_simple[2]
print("f")
except :
print("g")
URL = str(input("URL to follow"))
produit_nom = str(input("Product to follow"))
with open('simple_data.dat', 'wb+') as doc_simple:
print("h")
#os.system('chmod +x simple_data.dat')
tab_simple = []
tab_simple.append(URL)
tab_simple.append(produit_nom)
tab_simple.append([])
print(tab_simple)
print("c'est le 2")
print("p")
pickle.dump(tab_simple, 'simple_data.dat')
print("q")
The prints are here to show which lines are executed. The os.system is here to allow writing on the file but the error is persisting.
I don't understand why it's said that the document doesn't have a write attribute because I opened it in writing mode. And I neither understand the first error where it can't load the file.
If it can help you the goal of this script is to initialise the program, with a try. It tries to open the document in reading mode in the try part and then set variables. If the document doesn't exist (because the program is lauched for the first time) it goes in the except part and create the document, before writing informations on it.
I hope you will have any clue, including changing the architecture of the code if you have a better way to make an initialisation for the 1st time the program is launched.
Thanks you in advance and sorry if the code isn't well formated, I'm a beginner with this website.
Quote from the docs for pickle.dump:
pickle.dumps(obj, protocol=None, *, fix_imports=True)
Write a pickled representation of obj to the open file object file. ...
...
The file argument must have a write() method that accepts a single bytes argument. It can thus be an on-disk file opened for binary writing, an io.BytesIO instance, or any other custom object that meets this interface.
So, you should pass to this function a file object, not a file name, like this:
with open("simple_data.dat", "wb"): as File:
pickle.dump(tab_simple, File)
Yeah, in your case the file has already been opened, so you should write to doc_simple.
I'm running python2.5 and trying to use the astLib library to analyse WCS information in astronomical images. I try and get the object instanciated with the following skeleton code:
from astLib import astWCS
w = astWCS.WCS('file.fits') # error here
where file.fits is a string pointing to a valid fits file.
I have tried using the alternate method of passing a pyfits header object and this fails also:
import pyfits
from astLib import astWCS
f = pyfits.open('file.fits')
header = f[0].header
f.close()
w = astWCS.WCS(header, mode='pyfits') # error here also
The error is this:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/astro/phrfbf/build/lib/python2.6/site-packages/astLib/astWCS.py", line 79, in __init__
self.updateFromHeader()
File "/home/astro/phrfbf/build/lib/python2.6/site-packages/astLib/astWCS.py", line 119, in updateFromHeader
self.WCSStructure=wcs.wcsinit(cardstring)
File "/home/astro/phrfbf/build/lib/python2.6/site-packages/PyWCSTools/wcs.py", line 70, in wcsinit
return _wcs.wcsinit(*args)
TypeError: in method 'wcsinit', argument 1 of type 'char *'
When I run in ipython, I get the full error here on the pastebin
I know the astWCS module is a wrapped version of WCStools but i'd prefer to use the Python module as the rest of my code is in Python
Can anyone help with this problem?
Just found out the updated version of this library has fixed the problem, thanks for everyone's help
Oh sorry, I should have seen. Looking at the pastebin in more detail, the only error I can think of is that, for some reason the header has unicode in it. It can't be converted to char *, and you get the error. I tried searching for something in the header, but everything looks okay. Can you do this and post the output in another pastebin?
import pyfits
f = pyfits.open('file.fits')
header = f[0].header
f.close()
for x, i in enumerate(header.iteritems()):
if len(str(i[1])) >= 70:
print x, str(i[1])
cardlist = header.ascardlist()
cardstring = ""
for card in cardlist:
cardstring = cardstring + str(card)
print repr(cardstring)
Or, if you can check the header of your fits file for "funny" characters, getting rid of them should solve the issue.