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 Python on Windows?
Python is a high-level programming language that has become increasingly popular due to its simplicity, versatility, and extensive range of applications. The process of How to install Python in Windows, operating system is relatively easy and involves a few uncomplicated steps. This article aims to
5 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 Eli5 in Python on Windows?
Eli5 is an open-source and cross-platform Python library available for various operating systems including Windows, Linux, and macOS, written to easily and quickly debug machine learning classifier models to explain their predictions. It provides support for machine learning frameworks and packages
2 min read
How to Install Vaex in Python on Linux?
Vaex is a Python module that assists us in accomplishing this and makes dealing with massive datasets a breeze. It's notably useful for Out-of-Core DataFrames that are sluggish (similar to Pandas). It can quickly view, analyze, and compute on large tabular datasets with low memory utilization. In th
2 min read
How to Install GIT-TFS on Windows?
GIT-TFS is a tool that allows you to interact with TFS (Team Foundation Server) and enables the use of Git as a client for Microsoft TFS. Using Git commands, it provides a way to access TFS version control, allowing developers to use features to interact with TFS. GIT-TFS provides many features such
2 min read
How to Install python-dateutil on Windows?
The dateutil package, which is available in Python 2 and Python 3, adds a lot of features to the conventional DateTime module. Or, to put it another way, it extends Python's DateTime module. It calculates relative deltas such as next month, next year, previous week, and so on. Its time zone data com
2 min read
How to Install Fabric in Python on Windows?
Fabric is a Python library used to execute shell commands remotely over SSH, yielding useful Python objects in return.. In this article, we will look into the process of installing the Fabric Library on Windows. Pre-requisites: The only thing that you need for installing the Scrapy module on Windows
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