Python Forum
Cant Get Powershell to run a python program from notepad++. Newbie help!
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cant Get Powershell to run a python program from notepad++. Newbie help!
#1
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
Reply
#2
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
Reply
#3
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
Reply
#4
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.
Reply
#5
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  using PowerShell from Python script for mounting shares tester_V 8 529 Mar-12-2024, 06:26 PM
Last Post: tester_V
  PowerShell & Python deep_logic 2 704 Jun-06-2023, 06:34 AM
Last Post: buran
  How to write a part of powershell command as a variable? ilknurg 2 1,120 Jul-26-2022, 11:31 AM
Last Post: ilknurg
Question Trouble installing modules/libraries and getting Notepad++ to show cyrillic letters Dragiev 6 2,250 Jul-24-2022, 12:55 PM
Last Post: Dragiev
  Python newbie laleebee 2 1,321 May-24-2022, 01:39 PM
Last Post: laleebee
Photo Windows 10 PowerShell doesn't work Amy 3 3,922 Apr-27-2021, 01:33 PM
Last Post: jefsummers
  Newbie on Python syntax rud0lp20 6 2,946 Apr-21-2020, 04:26 PM
Last Post: jefsummers
  Variable from notepad problem samuelbachorik 2 2,300 Apr-10-2020, 09:04 AM
Last Post: samuelbachorik
  Newbie needs help with a simple program feynarun 3 2,289 Jan-15-2020, 01:17 PM
Last Post: DeaD_EyE
  python newbie marcush929 2 2,598 Jan-01-2020, 08:06 AM
Last Post: marcush929

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020