Python interpreter PATH oddity. Can't use django
<p>I have three Python environments across two different interpreters. The first is the basic Python27 in my c:. The second is an Anaconda interpreter with its own environment and another environment in it's \envs\ directory. I have directed my PYTHONPATH variable to point to the Anaconda interpreter not in the \envs\ folder.
<a href="http://i.stack.imgur.com/VFmP0.png" rel="nofollow"><img src="http://i.stack.imgur.com/VFmP0.png" alt="enter image description here"></a></p>

<p>I also have my PATH variable set to the scripts directory from that environment <a href="http://i.stack.imgur.com/8eIIv.png" rel="nofollow"><img src="http://i.stack.imgur.com/8eIIv.png" alt="enter image description here"></a></p>

<p>However, when I run Django, I get a message about a discrepancy in versions. I think this results from the fact that Django is using the interpreter in my C:\ directory, Python27. When I echo my PATH environment variable in cmd, this is what I see:</p>

<pre><code>C:\Program Files (x86)\ActiveState Komodo Edit 10\;C:\Program Files (x86)\ActiveState Komodo IDE 10\;
C:\Program Files\MATLAB\R2014a\bin\win64;
C:\ProgramData\Oracle\Java\javapath;
c:\Program Files (x86)\Intel\iCLS Client\;
c:\Program Files\Intel\iCLS Client\;
C:\Windows\system32;C:\Windows;
C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;
C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;
**C:\Python27**;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit\;C:\Program Files (x86)\Skype\Phone\;
C:\Program Files\MATLAB\R2016a\runtime\win64;
C:\Program Files\MATLAB\R2016a\bin;
C:\WINDOWS\system32;
C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Users\jackf_000\sw\FFMPEG\bin;
C:**\Users\jackf_000\sw\Anaconda2\Scripts\**;
</code></pre>

<p>C:\cygwin64\bin;C:\Users\jackf_000\AppData\Local\Microsoft\WindowsApps;</p>

<p>When I run python in cmd and import os to see the executable, I get the following output:</p>

<pre><code>C:\Users\jackf_000&gt;python
Python 2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import sys
&gt;&gt;&gt; sys.executable
'C:\\Python27\\python.exe'
</code></pre>

<p>Why is the Python interpreter from C:\ in the PATH variable before the Anaconda one if I do not have it specified anywhere in PATH in the control panel window? And how can I specify that I want Django to look in the Anaconda environment for what it needs, or use pip to install to Django to C:\Python27? Currently, pip installs all packages to the Anaconda environment.</p>

<p>Because python 2.7 path is set in the system environment variable PATH.  You are editing your user variables (which are bizarrely configured because they contain duplicate stuff only found in system path like <code>C:\windows\system32</code> for instance)</p>

<p>if you type <code>where python</code> you'll probably get:</p>

<pre><code>C:\Python27\python.exe
</code></pre>

<p>(EDIT: you actually get that value, since you answered to my comment)</p>

<p>if you type <code>where pip</code> you'll probably get:</p>

<pre><code>C:\users\jackf_000\sw\anaconda2\scripts\pip.exe
</code></pre>

<p>which explains that pip installs package in the anaconda2 package</p>

<p>To get anaconda python in your path you would need to add <code>C:\users\jackf_000\sw\anaconda2</code> not the scripts subdir that contain pip.</p>

<p>then, if you typed <code>where python</code> you'll probably get:</p>

<pre><code>C:\Python27\python.exe
C:\users\jackf_000\sw\anaconda2\python.exe
</code></pre>

<p>But that wouldn't be enough because..</p>

<p>The system path comes first. PATH is one special env variable that you dont override with your user profile, only append dirs to. And it's perfectly normal to have one user PATH variable and one system PATH variable.</p>

<p>On the other hand, let's say the system variable <code>PYTHONPATH</code> does not please you, you could choose to replace it by setting a completely different one in your user variables. That would replace the paths, not append to them, unless you add <code>;%PYTHONPATH%</code> somewhere (<code>PYTHONPATH</code> is a path variable, but unknown by windows, it's nothing special). And PYTHONPATH does not influence which executable will be loaded, so forget it for now.</p>

<p>2 solutions:</p>

<ol>
<li>modify system path (admin needed) to add anaconda is before python 2.7 (not recommended)</li>
<li><p>run your applications which require anaconda with a .bat file starting by the following:</p>

<p><code>set PATH=C:\users\jackf_000\sw\anaconda2;%PATH%
 rem now run the command which needs anaconda python first</code></p></li>
</ol>

python django environment-variables windows-10