8

I'm at the very beginning of learning to code in Python (and first time using Powershell), so I assume my problem is very basic. When I try to run any Python script in PS, I get an error like the one below. The main suggestions I've found online are to (1) make sure I've set execution policy to unrestricted, and (2) edit my Path to include "c:\Python27;c:\Python27\Scripts" I've done both these things. What else should I try?

   PS C:\windows\system32> python
python.exe : Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
At line:1 char:7
+ python <<<< 
    + CategoryInfo          : NotSpecified: (Python 2.7.6 (d...ntel)] on win32:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError


Type "help", "copyright", "credits" or "license" for more information.
Kohlbrr
  • 3,861
  • 1
  • 21
  • 24
candidatemap
  • 81
  • 1
  • 2
  • Try running `python -v` to get verbose output. Do you get the same result when you run `python.exe` instead of just `python`? Do you get the same result when you run `python` in `CMD`? What is the output of `$env:PATH`? – Ansgar Wiechers Mar 13 '14 at 21:10
  • If Python is writing to STDERR, then PS interprets this as an exception. Type `python 2>$null` – andyb Mar 13 '14 at 22:28
  • Are you using the ISE? If so, try running from a PowerShell session. – andyb Mar 13 '14 at 22:34
  • If this IS caused by Python writing to STDERR, then this is a duplicate of (http://stackoverflow.com/questions/1394084/ignoring-an-errorlevel-0-in-windows-powershell) and probably many other postings as it's a common issue. – andyb Mar 13 '14 at 22:38
  • One final note - if you are learning PowerShell, check out PowerGui (www.powergui.org), it makes things a lot easier. – andyb Mar 13 '14 at 22:47
  • @andyb PowerShell does *not* treat output on StdErr as an exception. – Ansgar Wiechers Mar 14 '14 at 22:08
  • @AnsgarWiechers - I concede that this is only the case when using the ISE (hence my suggestion to try running from normal PowerShell session). Try the following in the ISE and then the normal PS console - it will throw an exception in the ISE `& cmd /c "echo hello from stderr 1>&2"` (also see http://stackoverflow.com/questions/1394084/ignoring-an-errorlevel-0-in-windows-powershell/11826589#11826589) – andyb Mar 15 '14 at 09:31
  • @AnsgarWiechers - see also (http://connect.microsoft.com/PowerShell/feedback/details/185231/output-of-stderr-should-be-consistent-there-should-be-a-way-to-redirect-stderr-from-text-based-programs-that-use-it-without-powershell-thinking-that-each-line-of-text-is-an-error) – andyb Mar 15 '14 at 09:38
  • See also: https://stackoverflow.com/a/43701614/324449 – Max Gasner Jan 10 '19 at 00:04

1 Answers1

10

This could be due to a 64bit/32bit mismatch. Try running the python command in "Powershell (x86)" assuming your were using the 64bit "Powershell" or "Powershell ISE".

Reader 1024
  • 101
  • 1
  • 3