Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Python UserWarning

Tags:

python

I just finished installing my MySQLdb package for Python 2.6, and now when I import it using import MySQLdb, a user warning appear will appear

/usr/lib/python2.6/site-packages/setuptools-0.8-py2.6.egg/pkg_resources.py:1054: UserWarning: /home/sgpromot/.python-eggs is writable by group/others and vulnerable  to attack when used with get_resource_filename. Consider a more secure location  (set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).   warnings.warn(msg, UserWarning) 

Is there a way how to get rid of this?

like image 1000
kagat-kagat Avatar asked Jul 13 '13 03:07

kagat-kagat


People also ask

How do I stop deprecation warning in Python?

When nothing else works: $ pip install shutup . Then at the top of the code import shutup;shutup. please() . This will disable all warnings.

How do you ignore SettingWithCopyWarning?

One approach that can be used to suppress SettingWithCopyWarning is to perform the chained operations into just a single loc operation. This will ensure that the assignment happens on the original DataFrame instead of a copy. Therefore, if we attempt doing so the warning should no longer be raised.


2 Answers

You can change ~/.python-eggs to not be writeable by group/everyone. I think this works:

chmod g-wx,o-wx ~/.python-eggs 
like image 68
Waleed Khan Avatar answered Sep 23 '22 00:09

Waleed Khan


You can suppress warnings using the -W ignore:

python -W ignore yourscript.py 

If you want to supress warnings in your script (quote from docs):

If you are using code that you know will raise a warning, such as a deprecated function, but do not want to see the warning, then it is possible to suppress the warning using the catch_warnings context manager:

import warnings  def fxn():     warnings.warn("deprecated", DeprecationWarning)  with warnings.catch_warnings():     warnings.simplefilter("ignore")     fxn() 

While within the context manager all warnings will simply be ignored. This allows you to use known-deprecated code without having to see the warning while not suppressing the warning for other code that might not be aware of its use of deprecated code. Note: this can only be guaranteed in a single-threaded application. If two or more threads use the catch_warnings context manager at the same time, the behavior is undefined.

If you just want to flat out ignore warnings, you can use filterwarnings:

import warnings warnings.filterwarnings("ignore") 
like image 38
jh314 Avatar answered Sep 21 '22 00:09

jh314