Python Forum
Cant Get Powershell to run a python program from notepad++. Newbie help! - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Cant Get Powershell to run a python program from notepad++. Newbie help! (/thread-385.html)



Cant Get Powershell to run a python program from notepad++. Newbie help! - Pythonerous - Oct-08-2016

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


RE: Cant Get Powershell to run a python program from notepad++. Newbie help! - Yoriz - Oct-08-2016

Where did you save the file, did you change the working directory to the location of the file ?.
If you didn't the other option is to use the full file path in order for python to find it.
There is a tutorial located on this forum on how to execute python code that you might find useful.

There is currently another discussion Windows/Power Shell: Differences from the tutorial taking place on the forum that you might want to view


RE: Cant Get Powershell to run a python program from notepad++. Newbie help! - ATXpython - Oct-09-2016

Pythonerous

First, welcome to Python and the forum!

You can run scripts from the Command Line or PowerShell, however as Yoriz mentioned, you'll likely need to pass in the full file path of the script in order for it to work.
Something like this:

D:\Projects\Test.py    (this would be for a file called "Test.py"  that is located in a folder called "Projects" on your D drive).


Without having Python added to PATH, you will likely need to pass in the location of your Python interpreter as well.
I highly suggest adding Python to PATH - this can be easily done via a checkbox option during initial Python install.

For most of my scripts, I simply double click the .py file, and they run automatically.
No Command Line / PowerShell drama.   :D


RE: Cant Get Powershell to run a python program from notepad++. Newbie help! - buran - Oct-09-2016

I know that's not what you ask, but check the Notepad++ plugins. There are several that are useful - run python script from NPP, Python indentation, etc.


RE: Cant Get Powershell to run a python program from notepad++. Newbie help! - Pythonerous - Oct-10-2016

Hey All!

Thanks for the quick replies and the extra resources to learn more about this. Yoriz, I had the file save on the desktop which might have been the problem as you said so I coppied the file to my D: (Data drive?) and once I did that I used ATXpython's advice and specified the full file path which was D:\folder\ex.1 and it ran my line of code in Powershell and CMD! Thank you guys so much! A lot of insight in this one little problem but I'm sure I'll be back with more questions.

Thank you!

Pythonerous