This article will discuss setting up the python Virtual Environment on windows 10.
1. What’s Python?
Python is a high-level, all-purpose programming language. Programmers typically fall in love with Python due to its improved efficiency. The edit-test-debug cycle is extremely quick because there is no compilation stage.
Code readability is prioritized in its design philosophy, which heavily uses indentation. Python uses garbage collection and has dynamic typing. It supports a variety of programming paradigms, such as functional, object-oriented, and structured programming.
Developer Guido Van Rossum founded it in 1991. One of the most used and fastest-growing programming languages is Python. Python is a powerful, versatile, and simple-to-learn programming language. It is widely utilized in many different industries.
Python programs are simple to debug since segmentation failures never originate from errors in the input or code. Instead, the interpreter raises an exception if a mistake is found. The interpreter provides a stack trace if the program can’t handle the exception. Setting breakpoints, examining arbitrary expressions, viewing local and global variables, stepping through the code one line at a time, and using additional capabilities are all possible with a source-level debugger. Python was used to develop the debugger, which serves as an example of introspection in action.
2.1 What is a virtual environment?
By building isolated Python virtual environments for them, a virtual environment is a tool that aids in maintaining the separation of dependencies needed by various projects. The majority of Python developers utilize this as one of their most crucial tools.
2.2 Why do we need a virtual environment?
Imagine a scenario where you are working on two different versions of python one of them uses Python 2.8.2 and the other uses Python 3.11.2. In such situations, the virtual environment can be really useful to maintain the dependencies of both projects.
By default, all projects on your system will store and access site packages in these same directories (third-party libraries). How is this relevant? You have two versions of Python in the two projects mentioned above. As it cannot distinguish between versions in the “site-packages” directory, this is a serious issue. Virtual environments are useful in this situation. We just need to set up two distinct virtual environments for the two projects in order to overcome this issue.
The beautiful thing about this is that since they are only directories with a few scripts inside of them, there are no restrictions on how many environments you can have. Anytime you work on a Python-based project, you should use a virtual environment. The tendencies of every project are isolated from the system and each other.
A fresh virtual environment should normally be created for each Python-based project you work on. As a result, each project’s dependencies are kept separate from both the system and one another.
2.3 How does a virtual environment work?
We utilize the virtualenv module to create isolated Python environments. Virtualenv creates a folder with all the executables needed to use the packages that a Python project would require.
3. What is Jupyter Notebook?
An open-source web tool called the Jupyter Notebook enables you to create and share documents with real-time code, equations, visuals, and text. Data transformation and cleaning, statistical modeling, data visualization, machine learning, and many other applications are just a few examples.
Python is one of the more than 40 programming languages that Jupyter supports. Installing the Jupyter Notebook itself requires Python (Python 3.3 or higher, or Python 2.7).
4.1. How to Create a Virtual Environment in Python
There are instances when we want to use the Jupyter notebook in a virtual setting with only a few pre-selected packages available, contrary to popular belief. To for the most part do this, the Jupyter notebook’s list of available kernels must be expanded to include a new kernel for the virtual environment, or so they thought. How to mainly do it is as follows:
4.2. Create a virtual environment
Open the directory in which your project will be created. To build a virtual environment, open cmd/powershell, go to the same directory and execute the following commands.
python -m venv venv
4.3. Activate the virtual environment
Now that we have our virtual environment let’s activate it.
4.4. Use the command below to install the Jupyter for the virtual environment:
The following command creates a kernel that may be used to execute commands from a Jupyter notebook inside of a virtual environment.
pip install jupyter
These and many more will also install
4.5. Check if installed or not
Let’s now check if our jupyter notebook is created. Just run the “jupyter notebook” command in the command prompt or Powershell and the jupyter environment will open up.
Step 5: Now, open it, rename it, and start coding for example
def add(a , b):
return a + b
val = add (12 , 13)
A strong, adaptable, and easy-to-learn programming language is Python. It was started in 1991 by developer Guido Van Rossum. Python has dynamic typing and garbage collection. Many programming paradigms, including functional, object-oriented, and structured programming, are supported.
Virtual environments are a tool used by Python developers to maintain the dependencies of both projects. By default, all projects on the system will store and access site-packages in the same directories. To overcome this issue, two distinct virtual environments must be set up for the two projects.
The Jupyter Notebook is an open-source web tool that enables users to create and share documents with real-time code, equations, visuals, and text. It supports Python, a programming language with over 40 programming languages, and requires Python (Python 3.3 or higher). Examples include data transformation, cleaning, statistical modeling, data visualization, and machine learning.
So that’s what Python, Jupyter Notebook, and Virtual environment are and how you can download and set up a virtual environment.
Thanks for reading. Please clap for me 👏👏👏!!