How to Setup Python Project For The First Time

I am a JavaScript developer learning to build projects with python. While using Node JS everything is so easy just install Node, use npm init command and now you can install all the packages that you need but when it comes to python it's not that easy. But not after reading this post, here is how I approach project setup for the first time starting with python.
- Install Python
- Create a Virtual Environment
- Activate the Virtual Environment
- Install Packages in the Virtual Environment
- Verify Package Installation
- Deactivate the Virtual Environment
Create a Virtual Environment
Navigate to Your Project Directory: Open Terminal and navigate to the directory where you want to create your virtual environment.
cd /path/to/your/projectUse the venv module to create a virtual environment. Replace venv with your desired name
python -m venv venv
// or python3 in some version of MAC
python3 -m venv venvActivate the Virtual Environment
Once the virtual environment is created, you can activate it with the source command:
source venv/bin/activateVerify Activation:
To confirm the environment is active, check the Python executable path:
which pythonor
which python3It should point to the Python executable inside your venv folder, like /path/to/your/project/venv/bin/python
Install Packages in the Virtual Environment
Install Packages Using pip: While the virtual environment is active, you can install packages using pip. For example, to install sympy:
pip install sympyVerify Package Installation: You can list installed packages with:
pip listDeactivate the Virtual Environment
When you are done working in the virtual environment, you can deactivate it with:
deactivate