Web Analytics Made Easy -
StatCounter Cant Get Powershell to run a python program from notepad++. Newbie help! - CodingForum

Announcement

Collapse
No announcement yet.

Cant Get Powershell to run a python program from notepad++. Newbie help!

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cant Get Powershell to run a python program from notepad++. Newbie help!

    Hey Forum!

    Im new here and happy that I'm part of the community.

    I just started geting into programming and recived a book on how to learn Python 2.7 and the first excercise wants me to write a script just printing a few lines of text.

    I wrote the script in Notepad++ on Windows 10 and saved the file as a Python file. .py.

    Once I save the file and try to run it in Powershell by typing, python example.py, I recive an Errno 2 stating that there is no such file or directory even though i just saved the file!

    I'm sure I'm doing something wrong so I would appreciate some insight.

    Thanks All,

    Pythonerous

  • #2
    Haven't touched windows for a long time, but there were a few traps I used to encounter when saving files.

    Sometimes, say you save example.py, notepad appends the .txt suffix. So what happens is the file saved is named example.py.txt. Do a dir on the folder to make sure you have saved it with the right extension.

    Also, are you sure, python.exe is visible. You might need to add python's directory to your PATH. The easiest way to test it is to type in "python", without parameters.

    Comment


    • #3
      Thanks for the advice josephm!

      I double checked the file name of ex.py and it is solely a python file. I make sure I change it from the defualt .txt file before saving. Python is also visible to Powershell. It didn't see it at first as I had to type in this line of code into Powershell before Python could see it. Which I think is just a line of code to add Python's directory to my PATH as you said to do. [Environment]::SetEnvironmentVariable("Path", "$senv:Path;C:\Python27", "User")

      I know you said you haven't touched windows in a long time but I'm just following up.

      Thanks,

      Pythonerous

      Comment


      • #4
        Is the file a single string name or multi-string. single = example.py -- multi = im the example.py

        If you have a file called python text.py and try open it using python python text.py it will fail because you need to tell the command line it's the name of a file not separate keywords.

        python "python text.py"

        Goes without saying your environment variables are correct otherwise python would not be recognized by the command line.

        Comment

        Working...
        X