Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Oct 2016
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy 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. #2
    Regular Coder
    Join Date
    Sep 2014
    Posts
    165
    Thanks
    0
    Thanked 24 Times in 24 Posts
    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.

  3. Users who have thanked josephm for this post:

    pythonerous (10-07-2016)

  4. #3
    New to the CF scene
    Join Date
    Oct 2016
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  5. #4
    New Coder
    Join Date
    Nov 2016
    Location
    South Africa, Cape Town
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post
    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.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •