-
Notifications
You must be signed in to change notification settings - Fork 30
Description
I am installing a package that uses pyasdf. I am a bit limited in the python version I can use. Only version 3.7.4 is available. I was just following instructions I was given which, among many other things, said I should run:
python3 -c "import pyasdf; pyasdf.print_sys_info()"
It failed in watermark.py, telling me I needed obspy even though i had installed obspy using pip (unfortunately it is difficult for me to use Anaconda on this machine). As you may know, watermark uses pkg_resources to get the version numbers of required modules. I did a little digging, and although I can't seem to find it again, somewhere on python.org there were instructions for transitioning from pkg_resources, which is being deprecated, to importlib. Unfortunately for me I couldn't find anything in importlib for 3.7.4 that would give me module version numbers (it is in importlib for 3.9).
Aside from pkg_resources being deprecated, it and/or its combination with pip just weren't working for me in python 3.7.4. Perhaps I should have used something other than pip to install.
So in the end I replaced the following in watermark.py:
watermark["module_versions"] = {
module: get_distribution(module).version for module in modules
}
with:
from pip._internal.operations.freeze import freeze
watermark["module_versions"] = {}
for requirement in freeze(local_only=False):
pkg = requirement.split('==')
if pkg[0] in modules:
watermark["module_versions"][pkg[0]] = pkg[1]
I have no idea if this is a good way to do it, but it worked for me so maybe it might help someone else using python 3.7.4. Also, I thought I'd point out the need (apparently) to eventually switch from pkg_resources to importlib.