How to Install GIT on Python Virtualenv?
Last Updated :
13 Dec, 2022
A Virtual Environment is a mechanism that can be compared with a separating funnel, when we are creating or using different projects which require different types of packages and modules we will create a virtual environment for each of them so that the packages/modules we install for say project A doesn't affect project B. Virtual environment's main job is to manage different python packages used for different python projects so that no package version or anything gets overlapped with other project and cause any failure. To know more about Virtual Environments and their necessity, click here.
Downloading and Installation of Git in Virtualenv
Users can write the commands in Command Prompt or the terminal of any IDE like PyCharm of VSCode. Here, we will be using the cmd. Follow the further steps to install git in virtualenv.
Step 1: Write the below command in cmd or any terminal of the user's choice.
mkdir test-venv && cd test-venv
If the user uses any other terminal than cmd then break the above command into two like the below as the '&&' will be unrecognized by other terminals.
mkdir test-venv && cd test-venv
Running the mkdir and cd command together
Step 2: After changing the directory to the newly created one, write the below command.
python -m venv env
Now, if the user gets any error with python change it to python3. Using the above command we have now created a Virtual Environment inside of that directory named test-venv (The user can give any name it doesn't matter).
Step 3: Now, it is time to activate/start the virtual environment.
cd env
Scripts\activate
Remember to use uppercase S for Scripts. If the user is using any other terminal rather than cmd then use the command below.
source env/bin/activate
Cmd doesn't understand the source so that's why we had to first change the directory manually and then activate it.
output after activating the venv
As it is visible in front of the path we have an (env) which indicates that everything we do or every module we will install will only be available in that env (i.e Virtual Environment) and no other project will be affected by this.
Step 3: Now, for example, we will install a basic package here, one of the most common and required modules for Data Science is pandas, so we will install it here as it is lightweight and necessary. So run the following command.
pip install pandas
installing pandas module
Step 4: Now write deactivate in the terminal or cmd to stop the Virtual Environment. As of now, we will initialize the repo with git. Write the below command.
deactivate
git init
deactivating the venv
Step 5: Now we will add the env folder into .gitignore so that the virtual environment is ignored every time during the source control.
echo 'env' > .gitignore
Step 6 (Optional): If the user wants that their repository will be used by others and the dependencies (modules/packages) they have used in their code should be installed before running their code on a different machine then it is better to create a requirements.txt file with all the dependencies used. Write the below command to do that.
pip freeze > requirements.txt
Now add it using git.
git add requirements.txt
Step 7: After adding it we will now commit it. Users can give some messages (it is recommended to do that) while committing some new changes,
git commit -m "Adding the requirements.txt file"
committing the newly added files
Step 8 (Optional): Now if the user wants to see the changes reflected in GitHub then they must create a new repository without having any gitignore or readme files for now. Then write the following commands one by one.
git branch -M main
Now after using the above command user need to copy their remote_url from GitHub.
Github remote URL
Copy the highlighted url from the user's repository. Then write the following command in terminal
git remote add origin <REMOTE_URL_COPED_FROM_GITHUB>
Now, for reassurance, the user might run the git add and the git commit commands again to re-assure that everything is being traced and added before pushing it to the branch. Write the below command:
git push -u origin main
pushing into main branch
Now users need to refresh their GitHub page and see all the files are being updated there.
after pushing updated github screen
Similar Reads
How to Install Virtual Environment in Python on MacOS? In this article, we will learn how to install Virtual Environment in Python on macOS. The virtualenv is a tool to create isolated Python environments. Since Python 3.3, a subset of it has been integrated into the standard library under the venv module. The venv module does not offer all features of
2 min read
How to Install GIT on VMWare? Git must first be installed on your computer before you can use it. It's usually a good idea to update to the newest version even if it's already installed. Installing it as a package, using another installer, or downloading the source code and compiling it yourself are all options. If you want to i
2 min read
How to Install Git on Windows Git is a powerful version control system used by developers worldwide. If you're looking to set up Git on your Windows machine, you have several options. This article will walk you through the most reliable and effective methods for installing Git on Windows, ensuring you stay up to date with the la
5 min read
How to Install Python yfinance using GitHub Yfinance is a popular Python library for accessing Yahoo Finance's financial data. While it is commonly installed via pip, installing it directly from GitHub allows you to access the latest development version, which may contain new features or bug fixes not yet available in the pip version. This gu
2 min read
How to Install Python on Linux This guide explains how to install Python on Linux machines. Python has become an essential programming language for developers, data scientists, and system administrators. It's used for various applications, including web development, data science, automation, and machine learning.This comprehensiv
15+ min read
How to Install PyQt for Python3 on Ubuntu? PyQt is a Python binding of the cross-platform GUI toolkit Qt. It is implemented as a Python plug-in and developed by the British firm Riverbank Computing. It implements approximately 440 classes and 6,000 functions and methods. It is not installed by default, so to use this we have to install it in
2 min read
How to Install Python3 on AWS EC2? AWS or Amazon web services is a cloud service platform that provides on-demand computational services, databases, storage space, and many more services. EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform. In simpler words, EC2 is nothing but a virtual com
3 min read
How to Install GIT On Mac Git is the backbone of modern software development, enabling developers to track changes, manage code, and collaborate effortlessly. It is a version control system that keeps teams in sync, prevents code conflicts, and ensures every contribution fits seamlessly into the bigger picture. Whether you'r
4 min read
How to install Python in Ubuntu? This article will guide you through the steps to install Python on Ubuntu, ensuring you're ready to start coding quickly. We will focus on installing Python 3, which is the most widely used version today.Python is typically pre-installed on Ubuntu, particularly Python 3, as it's an essential part of
4 min read
How to Install Pyvista Using Github? Pyvista is a powerful and versatile library in Python designed for 3D visualization and analysis of scientific data. It simplifies the process of creating and interacting with 3D plots, making it an excellent tool for researchers, engineers, and data scientists. In this article, we will explore how
2 min read