Module2Katas

Module 2’s katas from Launch X’s python introduction course.


Virtual environment creation process (on Windows):

Create a folder in any desired direction, I created mine in the documents/ folder and named it test-project.

empty folder

Next, use the Windows command prompt to navigate to the folder’s location, and executed the command py -m venv env.

cmd create env

A folder named env should appear in your root directory.

env folder

Overall directory structure:

env/
├── Include/
├── Lib/
│   └── site-packages/
│       └── (Lots of files.)
└── Scripts/
    ├── activate
    ├── activate.bat
    ├── Activate.ps1
    ├── deactivate.bat
    ├── pip.exe
    ├── pip3.10.exe
    ├── pip3.exe
    ├── python.exe
    └── pythonw.exe

Now, we should start the virtual environment using the file named activate inside the env/Scripts/ folder.

cmd activate venv

Then, (env) should be displayed in the command prompt.

running env in cmd

And, we can use the pip freeze command to display the installed packages.

cmd pip freeze

Which are none at the moment since we just created or virtual environment. We can change that quickly by installing the dateutil package running the command pip install python-dateutil.

cmd pip install

Running the pip freeze command once more should display the packages installed.

pip freeze with packages

Next, in order to test the installed packages, I’ve created an app.py file inside my root directory.

test-project/
├── env/
│   └── (Lots of files.)
└── src/
    └── app.py <-- Here it is.

Here is the code inside the app.py file, in case you want to try it yourself.

app.py code

To run the code we should navigate to the src/ folder and then look for the app.py file, hit enter, and two ouputs should appear in the command prompt:

  1. An output with your current date.
  2. An output the current date ahead by one month, one week, and the hours set to ten.

cmd app.py outputs

Finally, to exit the virtual environment you just need to navigate (once again) to env/Scripts/ and run deactivate.bat.

cmd deactivate venv

? Congratulations! if you followed until the end, you have just set up a Python’s virtual enviroment.