Skip to content

ShadowShahriar/py200

Repository files navigation

py200

Important

Our Software Development Project (SDP200) course focuses on Python, and we need to learn the fundamentals of Python to complete a mini-project by the end of the semester. I studied Python about six years ago, and a lot has changed since then. That is why I am relearning Python and documenting my findings, insights, and best practices in this repository.

📌 Jump to the resources

Usage

Since some of you were clueless about how to use this repository for learning, here is an overview:

  • Install pyenv and one or multiple versions of Python by following the Installation section. This needs to be done only once.

Open a new Command Prompt by typing cmd in the Start menu and do the following:

  • Select a preferred global version of Python:

    pyenv global [VERSION]

    * I am using Python 3.10.10

  • Create a virtual environment in your project directory:

    python -m venv env
  • Activate the virtual environment:

    env\Scripts\activate.bat
  • Install the required packages:

    pip install -r requirements.txt

Having done that, we can run any script from this repository. Let's say, we want to run 03-f-string/01-huge-int.py, so we can type:

python 03-f-string/01-huge-int.py

Installation

Different projects require different packages that might depend on specific versions of Python. It is a good idea to have multiple versions of Python installed on the system. Therefore, we can switch to a particular version whenever necessary.

pyenv makes it easy to manage multiple versions of Python on a per-user basis. We will use pyenv-win to make it work on our Windows machines.

📌 Video Tutorial on YouTube

  1. Press the ⊞ Windows key and type Powershell. Run it as Administrator.

    Step one

  2. Create a new directory under home by typing the following in the PowerShell terminal:

    mkdir $HOME/.pyenv

    Step two

  3. Download the code archive from the pyenv-win repository and extract the files from it.

  4. Head over to the pyenv-win-master directory and copy the following files into the newly created .pyenv directory:

    📁 pyenv-win
    📄 .version

    Step four

  5. In the PowerShell terminal, type the following commands to set environment variables pointing to the installation folder:

    [System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
    [System.Environment]::SetEnvironmentVariable('PYENV_HOME',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
  6. Having done that, add the bin folder to the PATH environment variable:

    [System.Environment]::SetEnvironmentVariable('path', $env:USERPROFILE + "\.pyenv\pyenv-win\bin;" + $env:USERPROFILE + "\.pyenv\pyenv-win\shims;" + [System.Environment]::GetEnvironmentVariable('path', "User"),"User")
  7. Close the current PowerShell and open a new instance. Then enable the execution of scripts by typing the following command:

    Set-ExecutionPolicy unrestricted

    Type A (Yes to All) and hit enter.

Note

We might need to unblock the pyenv script if we encounter a security warning. We can do that by typing the following command:

Unblock-File $HOME/.pyenv/pyenv-win/bin/pyenv.ps1
  1. Open a Command Prompt by typing cmd in the Start menu:

    Step eight

  2. Verify the installation by typing pyenv in the terminal. If everything went well, we should see something like the following:

    Step nine

We are not done yet! We still need to install the specific versions of Python we want for our projects. Here is the command to install a specific version of Python using pyenv:

pyenv install [VERSION]

I installed the following versions of Python for my projects:

* 3.10.10
  3.11.9
  3.12.2
  3.13.0a1-win32
  3.9.6

Note

The asterisk symbol (*) before the version indicates the global Python version.

Command to make a version of Python globally available:

pyenv global [VERSION]

Command to see the global Python version:

pyenv global

Command to see the selected version of Python:

pyenv version

Command to see all available versions of Python installed on the system:

pyenv versions

Command to uninstall a specific version of Python:

pyenv uninstall [VERSION]

Creating a Virtual Environment

When starting a new Python project, it is important to isolate its dependencies from those installed globally on our system to prevent any conflicts. We can do this by creating a new virtual environment.

📌 Video Tutorial on YouTube

  1. Open a Command Prompt in the project directory. Type the following command:

    python -m venv env
  2. Activate the virtual environment by running the following script:

    env\Scripts\activate.bat
  3. Install the required dependencies by using the following command:

    pip install [PACKAGE]
  4. Having done that, deactivate the virtual environment:

    env\Scripts\deactivate.bat

Installing Dependencies

Command to install a specific package:

pip install [PACKAGE]

Command to uninstall a specific package:

pip uninstall [PACKAGE]

Command to list all installed dependencies:

pip list

Command to export the list of the installed dependencies:

pip freeze > requirements.txt

Command to install the dependencies from file:

pip install -r requirements.txt

VSCode Extensions for Python Development

Formatting Python Code

In order to enable the formatting of .py files, do the following:

  1. Install Black Formatter from the Visual Studio Marketplace.

  2. Press ^ CTRL + ⇧ Shift + P to open the Command Palette and run Preferences: Open User Settings (JSON).

  3. Add the following to the settings.json file:

    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true
    }

Useful Resources

youtube logo How to Install and Run Multiple Python Versions on Windows 10/11 | pyenv & virtualenv Setup Tutorial

youtube logo Python Virtual Environments - Full Tutorial for Beginners

youtube logo Python Full Course for Beginners [2025]

youtube logo 5 Useful F-String Tricks In Python

youtube logo 5 Good Python Habits

youtube shorts logo Python Sets are OP!!

youtube shorts logo CLEVER Python One Liner!!

youtube logo Changing the title bar color of tkinter windows

youtube logo An introduction to customtkinter [way better styling in tkinter]

youtube logo Make Tkinter Look 10x Better in 5 Minutes (CustomTkinter)

youtube shorts logo ALL Python Programmers Should Know This!!

youtube logo PLEASE Learn These 10 Advanced Python Features

youtube shorts logo CLEAN Python Input Handling!!

youtube shorts logo Python User Input Tip!!

youtube shorts logo Two VERY Useful List Functions!!

youtube shorts logo What are Python DECORATORS??

youtube shorts logo LEVEL UP Your Python Game!!

youtube logo EASY Way to Use SOUNDS in Python/PyGame Projects

About

A repository documenting my Python programming journey during the second year of university (4th Semester)

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages