Cannot run python script under powershell in spite of adding env Path as required
<p>I am a user of python under mac and need to work now on a windows system.
I have installed Python35 for windows in Powershell, the command <code>py --version</code> and <code>python --version</code> provides me "Python 3.5.2".</p>

<p>I want to run a python script in Powershell and have tried : <code>py file.py</code> <code>python file.py</code> <code>py .\file.py</code> <code>python .\file.py</code> 
and have the following :</p>

<pre><code>python :   File ".\file.py", line 1
Au caractÃ¨re Ligne:1 : 1
+ python .\file.py
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (  File ".\file.py", line 1:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

SyntaxError: Non-UTF-8 code starting with '\xff' in file .\file.py on line 1, but no encoding declared; see 
http://python.org/dev/peps/pep-0263/ for details
</code></pre>

<p>As for <code>.\file.py</code> it opens me a black window that closes within 1 second.</p>

<p>Interestingly, when doing <code>python</code> or <code>py</code> it outputs the python idle but powershell is blocked and I cannot use it either in powershell.</p>

<p>Now, I already looked at </p>

<p><a href="http://stackoverflow.com/questions/12829680/cannot-run-python-script-file-using-windows-prompt">cannot run python script file using windows prompt</a></p>

<p><a href="http://stackoverflow.com/questions/29627895/cannot-run-python-script">Cannot run python script</a></p>

<p><a href="http://stackoverflow.com/questions/19505337/run-python-script-inside-powershell-script">Run python script inside powershell script</a></p>

<p>As well as I tried to add the Python Path in Powershell and manully in the "Advance system" interface of windows.</p>

<p>By the way my <code>file.py</code> contains a simple <code>print("hello")</code></p>

<p>What am I doing wrong?</p>

<p>The problem is explained in the error message:</p>

<blockquote>
  <p>SyntaxError: Non-UTF-8 code starting with '\xff' in file .\file.py on line 1, but no encoding declared;</p>
</blockquote>

<p>It means that Python reads the source file and gets confused. On the other hand, it has a <a href="https://en.wikipedia.org/wiki/Byte_order_mark" rel="nofollow">byte order mark</a> header, but on the other hand there isn't enough information about what kind of Unicode the file is about.</p>

<p>It's better be safe than sorry, so Python requires you to tell what to do instead of trying to guess what's the real encoding. In unicode, you see, there are caveats. For example, Â½ is actually a <em>number</em> that has value of 0.5.</p>

<p>As for how to solve this, either save the file as non-unicode (ANSI) or start the source file with, say, header:</p>

<pre><code># -*- coding: utf-8 -*-
</code></pre>

python windows powershell