1

this may seem basic, but could somebody run me through how to run a python file (one that's already created), through powershell? I know absolutely nothing about powershell despite hours of looking online to learn

Thanks all

  • 1
    Possible duplicate of [Running Python in powershell?](https://stackoverflow.com/questions/19676403/running-python-in-powershell) – Will Estes Jun 21 '17 at 19:08
  • Or https://stackoverflow.com/q/10321970/478656 or https://superuser.com/q/437790/67909 or https://stackoverflow.com/q/11813435/478656 – TessellatingHeckler Jun 21 '17 at 19:09

2 Answers2

0

It is happily very similar, if not the same, as running a python script from the normal command line.

First you're going to need to have python installed and in your path. To test this try python --version in powershell. You should get output like: python 2.7.

If that worked fine then you run your script by typing python followed by the script name i.e. python test.py (if its in another directory you will need to go to that dir or add the dir to the filename).

If that didn't work you probably need to install python: https://www.python.org/

axwr
  • 2,118
  • 1
  • 16
  • 29
  • thank you, that helped more than you might think lol.... now would you happen to know how you can write a powershell script as well? – python_beginner_coder Jun 21 '17 at 19:23
  • im not even sure if that question made sense... that's how bad I am at powershell @Scheme – python_beginner_coder Jun 21 '17 at 19:24
  • @python_beginner_coder Sure that made sense, everyone starts somewhere. a basic powershell script is simple enough but it is hard to explain in a comment! take a look here: https://www.pdq.com/blog/powershell-how-to-write-your-first-powershell-script/ – axwr Jun 21 '17 at 19:27
  • @python_beginner_coder A useful thing to remember is everything is run in a linear way, logically. Things execute in order, almost strictly, in powershell scripts. For example, there are not function prototypes unless you write them in an alternate file and import them at the top of the script you're writing your logic in. – Maximilian Burszley Jun 21 '17 at 19:32
0

Provide the path where you have installed the Python, followed by the path of the Python script:

'path of python.exe' 'Path of the python script'

Example:

C:\\Python27\python.exe 'D:\\Project\script.py'
franiis
  • 1,378
  • 1
  • 18
  • 33