Skip to main content

Posts

Showing posts from March, 2023

How to Create a Python Virtual Environment

You can create a Python virtual environment and install pip packages in it by following these steps: 1. Open a terminal window and navigate to the directory where you want to create the virtual environment. 2. Run the command “python3 -m venv env” to create a new virtual environment. Replace “env” with the name you want to give your virtual environment. 3. Activate the virtual environment by running the command “source env/bin/activate” on Linux/Mac or “env\Scripts\activate.bat” on Windows. 4. Once the virtual environment is activated, you can install pip packages by running the command “pip install <package-name>”. Replace “<package-name>” with the name of the package you want to install. That’s it! You can now use the virtual environment to run your Python scripts and install packages without affecting the system-wide Python installation.