0

I am trying to follow learn python the hard way but it won't load in the powershell. I typed in the exact line that is

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

but I know that won't work cause that isn't where python is installed. I am on a school computer so I have my python installed in mi_lemi(\filer_useres)(G:) but I tried putting that in instead and fiddling around with it but no luck either. Also my python.exe is just alled python.exe so should I remeove the '27' from it?

Thanks!

user2709431
  • 51
  • 1
  • 1
  • 4
  • The python.exe executable is in a dir called C:\Python27, right? – Keith Hill Nov 09 '13 at 01:52
  • No its not its installed in the directory I posted above. The default directory for the powershell is also different. I copied all the python files in to the default directory and it seems to work now but I am having trouble loading files... I will try to figure it out. – user2709431 Nov 09 '13 at 02:07
  • possible duplicate of [Running Python in powershell?](http://stackoverflow.com/questions/19676403/running-python-in-powershell) – durron597 Aug 03 '15 at 18:03

3 Answers3

1

That call will work for subsequent invocations of PowerShell but it won't help the current PowerShell session. For the current session use:

$env:Path += ";C:\Python27"
python.exe

or

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "Process")
python.exe

Or perhaps just:

C:\> c:\python27\python.exe
Keith Hill
  • 194,368
  • 42
  • 353
  • 369
  • Thank you. I used your 2nd comment and it said "the command python.exe was not found but does exist in your current location..... if you trust this command instead type .\python.exe" So I did that but it said it was missing some files. I copied them all over from the directory I listed in my first post to the directory that the powershell starts in and it seems to work for now..... – user2709431 Nov 09 '13 at 02:01
  • If you are cd'd into the same directory as the executable then you have to execute the exe like so `.\python.exe`. That is a security feature of PowerShell. – Keith Hill Nov 09 '13 at 02:46
1

Just in case this is also the issue. I found Python replaced my PathExt content as well. Check your PathExt environment variable as well just in case it's been replaced with .PY.

It should look something like this.

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY
uadrive
  • 1,249
  • 14
  • 23
1

I had the same problem, I finally found how to fix it.

First search python in the windows search, Python 3.7 (32-bit) or another version of python should show up. (If not first install Python.)

Then Right click on it and choose open location then you should see a folder with Python in it.

If the python in that folder is a shortcut, right click on it and choose open location again. (This step is only required if it is a shortcut.)

When you have found the real Python.exe, click on the path wich is above the files on the file manager, copy it.

Then go to Windows PowerShell and type:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;INSERT WHAT YOU COPIED HERE")

In my case:

C:\Users\Stijn> [Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Users\INSERT WINDOWS USERNAME\AppData\Local\Programs\Python\Python37-32")

That fixed it for me.

Niels
  • 11
  • 2