You can use os.environ, which first requires that you import os. os.environ is a dictionary that maps environment variable names to values. For example, os.environ['HOME'] would be equal to your home directory.
However, are you sure you are "compiling" file A? Python is generally interpreted, rather than compiled, which means you do not have to use a program to turn your code into an executable. I will assume you simply mean "import" when you say "compile".
The solution will be to first set the environment variables using os.environ[...] = ..., replacing the ellipses with the desired environment variable name (string) and value, respectively. Only after you set these variables should you import file A. Assuming you are running file B, the code in file A will only be interpreted when you import A. If you set the environment variables before importing, you should be good.
Caveat: Are you sure you want to set the variables in your code? It might make more sense to set them globally on your system, then add checks to file A to make sure they are set. It's not a good idea to assume environment variables are set.