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.
Navigate to Your Project Directory: Open Terminal and navigate to the directory where you want to create your virtual environment.
cd /path/to/your/project
Use 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 venv
Once the virtual environment is created, you can activate it with the source
command:
source venv/bin/activate
Verify Activation:
To confirm the environment is active, check the Python executable path:
which python
or
which python3
It should point to the Python executable inside your venv
folder, like /path/to/your/project/venv/bin/python
Install Packages Using pip
: While the virtual environment is active, you can install packages using pip
. For example, to install sympy
:
pip install sympy
Verify Package Installation: You can list installed packages with:
pip list
When you are done working in the virtual environment, you can deactivate it with:
deactivate