On Windows 10:
Hi, I am having an issue with understanding how my computer works with python. When I run a python file in my IDE, Atom, it uses the python from PATH. When I run python in .cmd, it uses the python from PATH. When I execute the same python file from .cmd it uses a python that is not in PATH. Why is it doing this and how can I get it to use the same python? I want everything to use the anaconda python.
I don’t understand where the AppData python is coming from?
Advertisement
Answer
What you see in Control Panel is just a template (if you will). Every process gets those settings when it starts, but it can modify them afterwards. Take the following example:
Start cmd.exe:
1.1.
echo %PATH%
– will output the inherited value1.2.
set PATH=%PATH%;some_other_dir
– will change the inherited value in the current (cmd.exe) process1.3. Repeat #1.1 – will output the updated value
1.4. Open the Control Panel settings again. You won’t see some_other_dir there
To check the current Python process environment (inherited from the parent process), use os.environ. Add in your script:
import os print(os.environ["PATH"])
So, the non Anaconda Python might actually be in %PATH%.
But the behavior could also be (and I’m leaning towards this one) due to [Wikipedia]: File association. For more details, check [SO]: How do I set “default App” for a file extension to an “.exe” on Windows 10 after April 2018 update (@CristiFati’s answer).