module is installed in Python – Idomaster https://idomaster.com/blog Blog Tue, 19 Mar 2019 20:36:27 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.3 https://idomaster.com/blog/wp-content/uploads/2019/01/logo.png module is installed in Python – Idomaster https://idomaster.com/blog 32 32 How do I check whether a module is installed in Python, and install it if needed? https://idomaster.com/blog/how-do-i-check-whether-a-module-is-installed-in-python-and-install-it-if-needed/ https://idomaster.com/blog/how-do-i-check-whether-a-module-is-installed-in-python-and-install-it-if-needed/#respond Tue, 19 Mar 2019 20:36:27 +0000 https://idomaster.com/blog/?p=91 How do I check whether a module is installed in Python, and install it if needed? PKGS=['selenium','ctypes','time', 'os','shutil','subprocess','unittest','urllib'] for p in PKGS: import imp m_repr = "'%s'"%p m_repr = m_repr.ljust(20,".") print("Module %s"%m_repr,) try: fp, pathname, description = imp.find_module(p) imp.load_module(p, fp, pathname, description) except: print("FAIL") continue finally: print("OK")

The post How do I check whether a module is installed in Python, and install it if needed? appeared first on Idomaster.

]]>
How do I check whether a module is installed in Python, and install it if needed?


PKGS=['selenium','ctypes','time', 'os','shutil','subprocess','unittest','urllib']

for p in PKGS:
import imp
m_repr = "'%s'"%p
m_repr = m_repr.ljust(20,".")
print("Module %s"%m_repr,)
try:
fp, pathname, description = imp.find_module(p)
imp.load_module(p, fp, pathname, description)
except:
print("FAIL")
continue
finally:
print("OK")

The post How do I check whether a module is installed in Python, and install it if needed? appeared first on Idomaster.

]]>
https://idomaster.com/blog/how-do-i-check-whether-a-module-is-installed-in-python-and-install-it-if-needed/feed/ 0