Describe the bug
Reposting from @dan-ukr
While executing imports with the newest Nemo and all the dependencies, there is an issue ModuleNotFoundError: No module named 'pkg_resources' - due to the fact the the newest Nemo requiers the newest setuptools, where pkg_resources were removed, however lightning still requires them. My fix was:
def patch_pkg_resources():
if 'pkg_resources' in sys.modules: return
pkg_res = types.ModuleType("pkg_resources")
pkg_res.declare_namespace = lambda name: None
class Requirement:
def init(self, req_str): self.req_str = req_str
def repr(self): return self.req_str
class Distribution:
def init(self, name):
self.project_name = name
try: self.version = metadata.version(name)
except: self.version = "0.0.0"
def repr(self): return f"{self.project_name}=={self.version}"
def as_requirement(self): return Requirement(self.project_name)
pkg_res.get_distribution = lambda dist: Distribution(dist)
pkg_res.Requirement = Requirement
pkg_res.Distribution = Distribution
pkg_res.working_set = [Distribution("nemo_toolkit"), Distribution("lhotse")]
sys.modules["pkg_resources"] = pkg_res patch_pkg_resources()
So, basically 'find pkg_resources anywhere locally and run it' - worked in my env
Describe the bug
Reposting from @dan-ukr
While executing imports with the newest Nemo and all the dependencies, there is an issue ModuleNotFoundError: No module named 'pkg_resources' - due to the fact the the newest Nemo requiers the newest setuptools, where pkg_resources were removed, however lightning still requires them. My fix was:
def patch_pkg_resources():
if 'pkg_resources' in sys.modules: return
pkg_res = types.ModuleType("pkg_resources")
pkg_res.declare_namespace = lambda name: None
class Requirement:
def init(self, req_str): self.req_str = req_str
def repr(self): return self.req_str
class Distribution:
def init(self, name):
self.project_name = name
try: self.version = metadata.version(name)
except: self.version = "0.0.0"
def repr(self): return f"{self.project_name}=={self.version}"
def as_requirement(self): return Requirement(self.project_name)
pkg_res.get_distribution = lambda dist: Distribution(dist)
pkg_res.Requirement = Requirement
pkg_res.Distribution = Distribution
pkg_res.working_set = [Distribution("nemo_toolkit"), Distribution("lhotse")]
sys.modules["pkg_resources"] = pkg_res patch_pkg_resources()
So, basically 'find pkg_resources anywhere locally and run it' - worked in my env