Error when using musixmatch python wrapper - python

I have been trying to use the the musixmatch python wrapper but I am getting a strange error when trying to run the example. Can anybody tell me what should be done to fix the library?
$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import musixmatch.ws
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "musixmatch/ws.py", line 14, in <module>
import musixmatch.api
File "musixmatch/api.py", line 167, in <module>
class XMLResponseMessage(ResponseMessage, etree.ElementTree):
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

As explained by #jdi in this question, it is a metaclass confict : Python does not know from which class to derive XMLResponseMessage from. ( it can't be from both due two possible diamond inheritance)
There is an Active State Recipe which solves this problem automatically (noconflict module): http://code.activestate.com/recipes/204197-solving-the-metaclass-conflict/ . The drawback is that you have to dive into the lib code and modify it to resolve the conflict.
From what I've seen, this lib was tailored for the developper purpose, and can only be run with his environment : neither python 2.7 (metaclass clash) nor python 3.3 ( unable to install the egg module) are able to install and test the module. I would advise you to fork the code, and adapt it to your needs.

Related

pypy5.6 install confluent_kafka cause: undefined symbol PyUnicode_FromFormat Error

When install confluent_kafka on pypy5.6, its has an error of : undefined symbol PyUnicode_FromFormat Error, i dont know how its happend ?
the os is: CentOs5.6
the full error output is :
Python 2.7.12 (aff251e543859ce4508159dd9f1a82a2f553de00, Nov 12 2016, 08:50:18)
[PyPy 5.6.0 with GCC 6.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import confluent_kafka
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/pypy/site-packages/confluent_kafka/init.py", line 2, in
from .cimpl import *
ImportError: unable to load extension module '/usr/local/pypy/site-packages/confluent_kafka/cimpl.pypy-41.so': /usr/local/pypy/site-packages/confluent_kafka/cimpl.pypy-41.so: undefined symbol: PyUnicode_FromFormat
How can I resolve this issue?
PyUnicode_FromFormat is not implemented so far inside PyPy. We'll get to it at some point (maybe soon if you have an example that requires it). You can also contribute it directly, if you want to get involved.
FWIW it is implemented in the py3.5 branch implementing Python 3.5, but not in trunk (supporting Python 2.7). Trunk only implements PyString_FromFormat. It's mostly a matter of back-porting the implementation, and "downgrading" the C code: in py3.5 it comes from CPython 3.5, so for trunk we'd need the same C code from CPython 2.7 instead.

Importing python module using bytecode with out source

From the python book:
Learning Python. 5th edition, page #727
I read the following:
if Python finds only a byte code file on the search path and no
source, it simply loads the byte code directly; this means you can
ship a program as just byte code files and avoid sending source
But when attempting the same on Python 3.5, it doesn't work:
~/Python/Module_Test$ cat a.py
a = "abc"
l = [1,2,3]
importing module 'a' created the byte-code file as:
~/Python/Module_Test/__pycache__$ ls
a.cpython-35.pyc
Now I removed the 'a.py' file and from the byte-code directory, I'm importing the module 'a':
~/Python/Module_Test/__pycache__$ python
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:53:06)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'a'
I even tried to add the byte-code directory to the search path, still it fails to load the module:
>>> import sys
>>> sys.path.append('/home/pradeep/Python/Module_Test/__pycache__')
>>> import a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'a'
What I am doing wrong? Can we import module from the byte code without the source? Is my understanding of the statement of the book wrong?
Your understanding is not wrong; you can but, it isn't the best idea to do this. Afaik the default behavior of the import statement doesn't do this on its own, you'll either need to use a deprecated function from imp, write your own, or customize the import process to do it.
With imp, you'd use load_compiled as so:
from imp import load_compiled
mod = load_compiled('a', '__pycache__/a.cpython-35.pyc')
To get your module imported. The notable thing that I'm aware that Python does, is that it doesn't re-compile a module a.py if it's corresponding *.pyc is around and is still valid.
After you remove 'a.py', you need to put 'a.pyc' in its place. The import mechanism will see it (when it interprets 'import a'), and will import it successfully. It does this without referring to the cache.
To get 'a.pyc', look in the pycache and copy-to-folder/rename 'a.xxxx.pyc' to 'a.pyc' There is a python function to compile to bytecodes too, so you don't have to work with the pycache
So long as your installation of python does not change, this should work. I believe the format of '.pyc' files can differ between installations. I believe this is a way to ship bytecodes instead of source. However, you must preserve the directory structure and the placement of the 'pyc' files in the same directories as the corresponding 'py' files. Of course the target machine must have an appropriate installation of python.

Python3 on Ubuntu giving errors on help() command

I used help() in the python3 shell on Ubuntu 14.04
I got this output
Please help , don't know whats wrong.
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> help()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/_sitebuiltins.py", line 98, in __call__
import pydoc
File "/usr/lib/python3.4/pydoc.py", line 65, in <module>
import platform
File "/home/omega/platform.py", line 2, in <module>
print("System : ",platform.uname().system)
AttributeError: 'module' object has no attribute 'uname'
>>>
The problem is that platform is the name of a stdlib module, which help uses. By creating a module of your own with the same name that occurs before the stdlib in your sys.path, you're preventing Python from using the standard one.
The fact that your own platform module tries to use the stdlib module of the same name just compounds the problem. That isn't going to work; your import platform inside that module is just importing itself.
The solution is to not collide names like this. Look at the list of the standard modules, and don't create anything with the same name as any of them if you want to use features from that module, directly or indirectly.
In other words: Rename your platform.py to something else, or put it inside a package.
File "/home/omega/platform.py", line 2, in <module>
print("System : ",platform.uname().system)
This is the problem, go to platform.py and fix it, it will be ok. It says, platform has not any method called uname you probably misstyped.

Undefined symbol "afinfo" when importing python-iptables package "iptc"

I am trying to utilize the python-iptables package to list iptables rules in a web app. When I add the iptc package to my environment, I get the below error. I used yum 'provides' to find where the libxtables.so.4 file comes from and found that the iptables and iptables-devel packages were the appropriate choice in CentOS 6.4 x64. I upgraded those packages but it did not change the error.
Does anyone have any suggestions about how I can resolve this?
pgrace#ny-misc01:~/repos/python-iptables/libxtwrapper$ python
Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import iptc
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python2.6/site-packages/iptc/__init__.py", line 10, in
from ip4tc import Table, Chain, Rule, Match, Target, Policy, IPTCError
File "/usr/lib64/python2.6/site-packages/iptc/ip4tc.py", line 11, in
from xtables import (XT_INV_PROTO, NFPROTO_IPV4, XTablesError, xtables,
File "/usr/lib64/python2.6/site-packages/iptc/xtables.py", line 744, in
class xtables(object):
File "/usr/lib64/python2.6/site-packages/iptc/xtables.py", line 757, in xtables
_xtables_afinfo = ct.c_void_p.in_dll(_lib_xtables, "afinfo")
ValueError: /lib64/libxtables.so.4: undefined symbol: afinfo
>>>
See this: https://github.com/ldx/python-iptables/issues/25
This is a known problem, old versions of libxtables declared afinfo as static, thus it is not accessible for python-iptables. There is a possible workaround, though - please keep an eye on the ticket, it will be updated as soon as there has been progress.
Another solution is to update iptables on your machine.
Disclaimer: I am the maintainer of python-iptables.
Update: this should be fixed now.

"from _json import..." - python

I am inspecting the JSON module of python 3.1, and am currently in /Lib/json/scanner.py. At the top of the file is the following line:
from _json import make_scanner as c_make_scanner
There are five .py files in the module's directory: __init__ (two leading and trailing underscores, it's formatting as bold), decoder, encoder, scanner and tool. There is no file called "json".
My question is: when doing the import, where exactly is "make_scanner" coming from?
Yes, I am very new to Python!
It's coming from a C-compiled _json.pyd (or _json.so, etc, etc, depending on the platform) that lives elsewhere on the sys.path. You can always find out where that is in your specific Python installation by importing the module yourself and looking at its __file__, e.g.:
>>> import _json
>>> _json.__file__
'/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/_json.so'
As you see, in my installation of Python 2.6, _json comes from the lib-dynload subdirectory of lib/python2.6, and the extension used on this platform is .so.
It may be coming from a file, or it may be built-in. On Windows, it appears to be built-in.
Python 3.1.2 (r312:79149, Mar 21 2010, 00:41:52) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _json
>>> _json.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
and there is no _json.pyd or _json.dll in the offing.
If you want to see the source, having a binary file on your machine or not is irrelevant -- you'll need the SVN browser.

Categories