Execute a Python Script

InstructorWill Button

Share this video with your friends

Send Tweet

Python scripts can be executed by passing the script name to the python command or created as executable commands that can run stand-alone. You’ll learn how to create both in this lesson.

Raunaq Sahni
~ 6 years ago

Hello Will,

I'm a little confused.

In order to make a file executable, is it recommended to add path to the python installed in the system or the python installed in the virtual environment? And also to which version 2 or 3?

Look forward to your response.

Will Buttoninstructor
~ 6 years ago

Hi Raunaq, The path to the python executable should already be in your path. That is taken care of by the package manager when installing python. The version (2 or 3) is a tricky question. For example, I’m OSX the default version should be 2.7 but in Ubuntu it should be 3. This is why virtual environments are useful: if the application you are creating uses python3, create a virtual environment to support that and it will only apply to that venv, preventing it from affecting other python installations on your system. Hope that helps!

Sent from my iPhone