Python directory conflicts with python executable location
<p>I have a python executable I wish to run from PowerShell using the command <code>python [executable].py</code>.</p>

<p>First I changed the directory in PowerShell to the location of the executable using <code>cd path\to\my\directory</code> which worked fine. However whenever I tried to use python to execute my code, PowerShell immediately searches for the <code>[executable].py</code> in Python's installation folder - fails to find it - and gives the an error that it cannot find the appropriate file.</p>

<p>How do I make sure that Powershell looks for the executable in the directory I indicated as opposed to the default Python installation folder?</p>

<p><a href="http://i.stack.imgur.com/jcOWD.png" rel="nofollow"><img src="http://i.stack.imgur.com/jcOWD.png" alt="Screenshot Attached"></a></p>

<p>If you want to run <code>python.exe</code> from a location other than the installation directory you'd call it with its full path:</p>

<pre><code>&amp; 'C:\path\to\python.exe' 'your.py'
</code></pre>

<p>If you want to run it from the current directory, prepend the filename with the relative path <code>.\</code>:</p>

<pre><code>&amp; .\python.exe 'your.py'
</code></pre>

<p>If you call an executable without a path like this:</p>

<pre><code>&amp; python.exe 'your.py'
</code></pre>

<p>PowerShell will look for a matching file in the directories listed in the <code>$env:PATH</code> environment variable, and execute the first match (or report an error if no matching file can be found).</p>

<p>With that said, the error you got in your screenshot is not because of the Python interpreter, but because of the file you want the interpreter to run. You're calling</p>

<pre><code>python conditions
</code></pre>

<p>when you actually want to run</p>

<pre><code>python conditions.py
</code></pre>

<p>Neither PowerShell nor Python magically add the extension for you. Instead they report an error because a file <code>conditions</code> (without an extension) simply doesn't exist.</p>

python python-3.x powershell directory