Starting Your Python Project

0. Set Up Your Visual Studio Code

Open Visual Studio Code
File >> New Window

(In your new window)
File >> Open Folder >> Right Click on an Empty Space and Create a New Folder
     >> Select the newly created folder
  1. Learn the Terminal

TerminalTutor is a fanatastic tool to learn how to use the terminal.

  1. Create a Github Repository and Clone it onto your drive

Git + Github is a good way to do version control so that you can go back to your previous states of your program without worrying about CTRL+Z.

DO NOT CLONE A REPOSITORY INSIDE ANOTHER REPOSITORY

Creating a Public/Private GitHub Repository

  1. Log in to GitHub:

    • Go to GitHub and log in with your credentials.

  2. Create a New Repository:

    • Click on the + icon in the top right corner and select New repository.

  3. Repository Details:

    • Enter a repository name.

    • Optionally, add a description.

    • Select Public or Private under the repository visibility options.

    • Optionally, you can initialize the repository with a README, .gitignore, or a license.

  4. Create Repository:

    • Click on the Create repository button.

Cloning the Repository to Your Local Machine

  1. Copy Repository URL:

    • On your repository page, click on the Code button.

    • Copy the URL provided (HTTPS).

  2. Open Terminal/Command Prompt:

    • Open your terminal (Mac/Linux) or Command Prompt (Windows).

  3. Navigate to Desired Directory:

    • Use the cd command to navigate to the directory where you want to clone the repository.

      cd path/to/your/directory
  4. Clone the Repository:

    • Use the git clone command followed by the repository URL you copied.

      git clone https://github.com/your-username/your-repository.git
  5. Navigate into the Cloned Repository:

    • Change into the repository directory:

      cd your-repository
  1. (Windows Only) Enable your computer to run scripts

  1. Open PowerShell as Administrator:

    • Press Win + X and select Windows PowerShell (Admin) or Windows Terminal (Admin) if you're using Windows Terminal.

  2. Check Current Execution Policy:

    • In the PowerShell window, type the following command and press Enter:

    Get-ExecutionPolicy
    • This will show you the current execution policy. By default, it might be set to Restricted.

  3. Set Execution Policy:

    • To allow scripts to run, you can set the execution policy to RemoteSigned

    Set-ExecutionPolicy RemoteSigned
  1. Set up a Python Virtual Environment in your repository

The reason we want to have a Python Virtual Environment is to isolate our project for the following benefits:

  • Isolated Projects will have their own modules and libraries installed

    • Example: If your project is using an earlier version of Streamlit and your computer has a newer version of Streamlit, your project will not be affected by the local machine's version differences

  • Easier to create a list of libraries and modules your project is dependent on

Create a Virtual Environment:

// Windows
python -m venv myenv

// macOS
python3 -m venv myenv

This command creates a directory named myenv containing a new Python environment.

Activate the Virtual Environment:

On Windows:

myenv\Scripts\activate

On macOS/Linux:

source myenv/bin/activate

To Deactivate to venv you can simply run deactivate on your terminal

4a. Create a .gitignore file

With our virtual environment set up, please create a new file within the main folder of your repository not inside myenv

The file should be called .gitignore

This file will tell git to ignore the list of folders and files we write within it

Contents to be written in .gitignore

myenv/

By having this in your .gitignore, git will automatically not track changes in your virtual environment to upload to GitHub.

  1. With your virtual environment activated, Install your libraries/dependencies/modules

Windows:

python -m pip install PACKAGENAME

// Example: python -m pip install pygame

macOS:

python3 -m pip install PACKAGENAME

// Example: python3 -m pip install pygame

Now your project should have all it requires.

  1. Upload any changes to your GitHub

// On changes
git add FILENAME
git commit -m "What changes you have made"
git push

Last updated