VSCode & Python


Starting a New Python Project in VSCode 


Python commands in the terminal when multiple versions of Python are installed


In Python, "python" and "python3" are both command-line commands used to run Python code, but they have a few key differences:

In summary, "python" and "python3" both allow you to run Python code, but "python" is used to run the default version of Python on a system, while "python3" is used to run a specific version of Python 3.x. On Windows, "py" can be used instead of "python" to run python.


Running Python Modules


In Python, the "-m" command is used to run a module as a script. It allows you to run a python module by specifying the module name, rather than the name of the script file.

For example, if you have a module named "mymodule" in your python environment, you can run it by using the command: python -m mymodule

This is equivalent to running a script named mymodule.py with the command: python mymodule.py

The -m command also allows you to run built-in modules that come with python, for example: python -m venv myenv 

This command creates a new virtual environment in the folder myenv.

Another example is using the -m http.server command, this command starts a simple HTTP server in the current directory.

This feature is particularly useful when you have a module that you want to run as a script but don't want to create a separate script file. It also allows you to run built-in modules as script, which can be useful in various scenarios.

Created with the assistance of OpenAI's ChatGPT


Starting to package your project


Creating and using a requirements.txt file: https://www.geeksforgeeks.org/how-to-install-python-packages-with-requirements-txt/ 

To create a requirements.txt file for a Python project in Visual Studio Code, follow these steps:

requests

numpy==1.21.0

pandas>=1.3.0

In the above example, requests is listed without a version constraint, numpy is pinned to version 1.21.0, and pandas has a minimum version requirement of 1.3.0.

That's it! You have created a requirements.txt file for your Python project in Visual Studio Code. Make sure to update this file whenever you add, remove, or modify project dependencies.

Created with the assistance of OpenAI's ChatGPT

You can also automatically create a requirements.txt file using Pipreqs: geeksforgeeks.org/how-to-automatically-install-required-packages-from-a-python-script/ 


Creating an execulable file from a python project: https://pyinstaller.org/en/stable/index.html