Python error while using MysqlDb - sets module is deprecated - python

I'm currently getting the warning every time I run a Python script that uses MySQLdb:
/var/lib/python-support/python2.6/MySQLdb/__init__.py:34:
DeprecationWarning: the sets module is deprecated
from sets import ImmutableSet
I'd rather not mess with their lib if possible. I'm on Ubuntu server. Anyone know an easy way to fix that warning message?
Thanks
UPDATE:
Fixed it based on the suggestions below and this link: https://bugzilla.redhat.com/show_bug.cgi?id=505611
import warnings
warnings.filterwarnings('ignore', '.*the sets module is deprecated.*',
DeprecationWarning, 'MySQLdb')
import MySQLdb

Do this before the mysql module is imported
import warnings
warnings.filterwarnings(action="ignore", message='the sets module is deprecated')
import sets

You can ignore the warning using the warnings module, or the -W argument to Python. Don't ignore all DeprecationWarnings, though, just the ones from MySQLdb :)

All it means is the sets module (more specifically the immutableset part) is deprecated, and you should use it's replacement, set. Set is inbuilt so no need to import.
If you need an immutable set, frozenset() should work.

Related

import from lib in python

I import vtt_to_srt converter.I read the instructions.I make the installation.From beginning to this "no problem" but when I import it as manuals describe python can't find the module there.
Installation
pip install vtt_to_srt3
Usage
from vtt_to_srt import vtt_to_srt
path = '/path/to/file.vtt'
vtt_to_srt(path)
Error
ImportError: cannot import name 'vtt_to_srt' from 'vtt_to_srt'
I am a rookie.Sorry for asking this question.
#SakuraFreak's answer was my immediate thought, too, but I ended up investigating this a bit further. It seems like vtt_to_srt stores all its API in the __main__.py file of the module. This file should normally be used when you want to a module using python -m.
This actually makes the module impossible to use the way that the documentation specifies. What I tried, then was:
from vtt_to_srt.__main__ import vtt_to_srt
print(vtt_to_srt)
This results in:
<function vtt_to_srt at 0x000002A0948216A8>
So it seems like this workaround is OK.
I do not know if storing all the module's code in __main__.py is some convention not supported by my version of Python (CPython 3.7.3 on Windows), or if it simply an error. Maybe you should approach the module's owners with this.
Because you're trying to import a function from the module which doesn't exist.
the correct way for this module is:
import vtt_to_srt

Python import pyLDAvis module - DeprecationWarning

I try to visualize my topic modeling results with the pyLDAvis python module. But when i try to import:
import pyLDAvis
import pyLDAvis.sklearn
Then i get the following warnings:
...\site-packages\msgpack_numpy.py:77: DeprecationWarning: The binary mode of fromstring
is deprecated, as it behaves surprisingly on unicode inputs.
Use frombuffer instead dtype=np.dtype(descr)).reshape(obj[b'shape'])
A lot of these warnings results, always in the same file.. Does somebody know, how I could fix this? Thanks!

Importing winappdbg gives ModuleNotFoundError for breakpoint in PyCharm?

Whenever I try to just import winappdbg it gives me an error ModuleNotFoundError: No module named 'breakpoint'. So, I tried installing breakpoint and that gives me another error ModuleNotFoundError: No module named 'ConfigParser' and I've installed configparser several times and still get the error. (Can't find capital ConfigParser) I'm using Windows 10/PyCharm Community Edition 2017.2.3/python 3.6.3
WinAppDbg is only for Python 2.x, it does not work on Python 3.x. Honestly, I had no idea it would even let you import it.
All those import errors are happening not because of missing dependencies (also, no idea there were similarly named modules in pip), they are submodules of WinAppDbg itself. Since Python 3 has a different syntax to specify those, it tries to load them as external modules instead. I suppose you could fix that in the sources by prepending a dot before every submodule import, but I'm guessing more stuff would break down the road (string handling for example is radically different and that would affect the ctypes layer).
TL;DR: use Python 2.x.

Python flask.ext.mysql is deprecated?

When I run from flask.ext.mysql import MySQL I get the warning Importing flask.ext.mysql is deprecated, use flask_mysql instead.
So I installed flask_mysql using pip install flask_mysql,installed it successfully but then when I run from flask_mysql import MySQL I get the error No module named flask_mysql. In the first warning I also get Detected extension named flaskext.mysql, please rename it to flask_mysql. The old form is deprecated.
.format(x=modname), ExtDeprecationWarning. Could you please tell me how exactly should I rename it to flask_mysql?
Thanks in advance.
flask.ext. is a deprecated pattern which was used prevalently in older extensions and tutorials. The warning is telling you to replace it with the direct import, which it guesses to be flask_mysql. However, Flask-MySQL is using an even more outdated pattern, flaskext.. There is nothing you can do about that besides convincing the maintainer to release a new version that fixes it. from flaskext.mysql import MySQL should work and avoid the warning, although preferably the package would be updated to use flask_mysql instead.
flask.ext.X is the old form to import a Flask extension, it is deprecated since Flask v0.10. The new way is to use flask_X. That's why you got the first warning.
But apparently, Flask-MySQL does not update it's name form and use the flaskext as the package name (chedck it on GitHub). That's why you got the second warning.

ImportError: cannot import name defaultdict

I'm getting this really strange ImportError when running from collections import defaultdict:
ImportError: cannot import name defaultdict
I'm running python 2.7, and the strange part is that in other parts of my application this exact same import line succeeds.
I thought maybe that's a circular import, but it doesn't make much sense when it comes to built-in python modules.
Any ideas why I get this error?
You probably have a module named 'collections' in your project.
Try renaming this module in your project.
Check that you have your own version of collections.py in python module search path.
It will prevent importing of the standard module collections.
You can confirm that by using following statements:
import collections
print(collections) # => This will print the module information. (esp. path)
most probably you have name clashes.
Try to rename your module or method.
In Python Programming Standarts, Python puts underscore for name clashes you can also do that(http://legacy.python.org/dev/peps/pep-0008/#function-and-method-arguments).

Categories