question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow importing librosa on Python 2 without a warning

See original GitHub issue

Description

I’d like to use librosa in Python 2 without an annoying warning on every import. The common pattern in Python is:

Steps/Code to Reproduce

import warnings

with warnings.catch_warnings():
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    import librosa

Unfortunately that doesn’t work, because librosa resets the filterwarning itself on import, which is an antipattern.

Expected Results

No warning on import.

Actual Results

3 lines (wrapped) of stdout noise:

/home/fabian/.virtualenvs/default/local/lib/python2.7/site-packages/librosa/__init__.py:40: DeprecationWarning: You are using librosa with Python 2. Please note that librosa 0.7 will be the last version to support Python 2, after which it will require Python 3 or later.
  DeprecationWarning)

Versions

Linux-4.15.0-62-generic-x86_64-with-Ubuntu-18.04-bionic
('Python', '2.7.15rc1 (default, Apr 15 2018, 21:51:34) \n[GCC 7.3.0]')
('NumPy', '1.15.2')
('SciPy', '1.1.0')
/home/fabian/.virtualenvs/default/local/lib/python2.7/site-packages/librosa/__init__.py:40: DeprecationWarning: You are using librosa with Python 2. Please note that librosa 0.7 will be the last version to support Python 2, after which it will require Python 3 or later.
  DeprecationWarning)
('librosa', '0.7.0')

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
bluenote10commented, Oct 8, 2019

Yes sounds good to me, thanks for taking the time to look into this!

0reactions
bmcfeecommented, Oct 8, 2019

I did a bit more digging, and I think we can rule out ipython as the culprit – vanilla python console has the same behavior.

According to the python 3.7 docs this is actually expected behavior (?!); deprecation warnings are hidden unless triggered by code called from a __main__() function.

However, the docs are a little different in 3.6, where there is no mention of the __main__ exception. 2.7 also ignores deprecation warnings by default.

Solution

If we change the 2.7 deprecation over to a FutureWarning (which is arguably a better fit for this purpose, though we’re not targetting end-user applications here), I think we can drop the filter and keep all the desired behavior. @bluenote10 does that sound agreeable to you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

librosa module import in python3 throws warning
i have installed module librosa in python3 using the command but when i am trying to import this module it shows below warning...
Read more >
Not able to install package librosa using pip and pycharm
C:\Users\ankit>pip install librosa. Collecting librosa. Using cached librosa-0.8.0.tar.gz (183 kB) Collecting audioread>=2.0.0
Read more >
Caching — librosa 0.10.0.dev0 documentation
This section covers the librosa function cache. This allows you to store and re-use intermediate computations across sessions. Enabling the cache¶. By default, ......
Read more >
librosa
Python module for audio and music processing.
Read more >
Unable to pip install librosa in raspberry pi 3 model b+ ...
You can now see if it imports in Python. Note: you'll likely see a Deprecation Warning message but it shouldn't be fatal.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found