I am trying to install some packages through python code using loop, but at once only one package get install.
Got below error on next package.
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\\users\\akshay~1.sha\\appdata\\local\\temp\\pip-req-tracker-aoybzz\\f37aad13bd20c8b1e66a004a7c01edf203f7e46ba784c9954fe935f7'
If I run the script again it will install the second package and throw error for the third. If I run it third time it will install the third, I want to install all the packages in one go, please help. Below is the code
===========================================================================
import os
from pip._internal import main as pipmain
PACKAGES = {'pymongo': 'pymongo-3.4.0', 'pexpect': 'pexpect-4.6.0', 'pathlib': 'pathlib-1.0.1'}
def install_dependency(pkg_name, crnt_path):
pkg_path = os.path.join(crnt_path, "dependencies\\"+pkg_name+"\\")
print("Installing package from local...", pkg_name)
pipmain(["install", pkg_path])
def check_dependecies():
current_path = os.path.dirname(os.path.abspath(__file__))
print(PACKAGES.keys())
for package_name in PACKAGES.keys():
try:
__import__(package_name, globals=globals())
print("================> Package imported successfully", package_name)
except ImportError as import_error:
print("Package not present", import_error)
install_dependency(PACKAGES[package_name], current_path)
print("================> Package imported successfully", package_name)
__import__(package_name, globals=globals())
if __name__ == "__main__":
check_dependecies()