How to make all my imports in a separete file then importing this file in

I'm trying to make a setup script that will install needed python modules on machines that don't have it. so going with the recommended way of installing packages this is my

import subprocess
import sys
import importlib

required_packages = ["cryptography.fernet", "os", "pip"]
for package in required_packages:
        print("Imported {} successfully".format(package))
    except ImportError:
        subprocess.check_call([sys.executable, "-m", "pip", "install", package])
        print("Installed {} successfully".format(package))

and as :

import setup
os.walk(".")   # cause an error

This way I have control about which modules have been installed and which not and then install them. the problem is that importing in doesn't seem to import these packages in the global namespace of so how can I make these two python files work as intended.

Read more here:

Content Attribution

This content was originally published by Khaled Gaber at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: