Quick Start Guide to Setting Up a Python Development Environment on Ubuntu Desktop using Visual Studio Code

Introduction

These steps will show you how to create a Python development environment using Visual Studio Code on Ubuntu Desktop.

Read Setting up an Ubuntu Desktop VM with Oracle VirtualBox if you need help setting up an Ubuntu VM on Oracle VirtualBox.

Set up steps

Confirm Python is Installed

If you already have Ubuntu installed, then good news, most Ubuntu distributions dome with Python pre-installed. If you’ve installed Ubuntu recently, you probably have Python3. To confirm Python3 is installed, open a terminal by pressing Ctrl + Alt + T. Then type “which python3” on the command line. if Python3 is installed, you should see the path to Python3 as the output of the command.

Output of which python3 command

If the command output is empty, you might have an older version of Python. You can try “which python2” or “which python” to look for older versions. If the output is still blank, then you don’t have Python and will need to install it. The steps to install Python are outside the scope of this post.

Install VS Code

After confirming Python is installed, install VS Code. Here are 2 ways to install VS Code. 1. Using snap on the command line. or 2. using Ubuntu Software application.

Install VS Code using Snap on the Command Line

  1. Press Ctrl+Alt+T to open a terminal window.

  2. Type “snap version” to confirm snap is installed.

Output of snap version command

  1. Type “sudo snap install –classic code” and press Enter to install VS code. Enter the password when prompted.

    NOTE: If you get a message like “[username] is not in the sudoers file. This incident will be reported.” Then you will need to add your user to the sudoers file .

    You should see a screen like the following:

    Download snap “code” (210) from channel “stable”

    When the install is complete, you should see a message similar to the following:

    Code 03c265b1 from Visual STudio Code (vscode) installed

Install VS Code using the Ubuntu Software Application

  1. Open the Ubuntu Software application by clicking the icon on the menu.

    Ubuntu Software application icon

  2. Click the search button in the upper left-hand corner.

  3. Enter “visual studio code” in the search field.

  4. Find and click the “code” option.

    code in Ubuntu Software Application with description of “Code editing. Redefined.”

  5. Click the Install button to install VS Code.

    Ubuntu Software Application Visual Studio Code Install page"

Run VS Code and Set Up the Python Environment

  1. Open a terminal and type “code” from the command line, or use the Ubuntu search feature to search for code, then click the icon to open it.

On a new installation, VS Code will prompt you for steps to configure your environment. One of these steps is “Code With Extensions”. If you select the default of popular extensions, the Python extension from Microsoft will likely be near the top. For these instructions, I’ll us this extension.

Visual Studio Code Get Started with Python"

  1. Create a folder to store the python files.

I’ve created a directory called “python” in my home directory.

python directory under user home directory"

  1. Open the python directory with Visual Studio Code.

  2. Create a new python file.

Select File > New File and click Python File from the options presented.

Enter the following text into the file

print("Hello World!")

Press Ctrl + S to save the file in the python directory as helloworld.py.

  1. Run the python file

Open a terminal in VS Code by clicking Terminal > New Terminal

Click the “Run Python File” button in the upper right-hand corner of the editor.

Run Python File button. Arrow button in upper right-hand corner

Clicking the button will open a Python terminal and the output of your code will be shown in the terminal window.

“Hello World!” printed by Python in the terminal window

Conclusion

You’re now ready to start experimenting with Python. This is just a rough quick-start guide to get you up and running quickly. For more detailed instructions, refer to the Getting Started with Python in VS Code from the official Visual Studio Code documentation.


The postings on this site are my own and do not necessarily reflect the views of my employer.

The content on this blog is for informational and educational purposes only and represents my personal opinions and experience. While I strive to provide accurate and up-to-date information, I make no guarantees regarding the completeness, reliability, or accuracy of the information provided.

By using this website, you acknowledge that any actions you take based on the information provided here are at your own risk. I am not liable for any losses, damages, or issues arising from the use or misuse of the content on this blog.

Please consult a qualified professional or conduct your own research before implementing any solutions or advice mentioned here.