0% found this document useful (0 votes)
5 views6 pages

Python Guide

This Python guide provides essential information on open-source licenses, recommended code editors, and creating virtual environments. It outlines steps for installing libraries, checking CUDA compatibility, and using PyTorch for deep learning. Additionally, it distinguishes between installing and importing libraries, and lists various Python libraries for data manipulation, visualization, machine learning, and deep learning.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Python Guide

This Python guide provides essential information on open-source licenses, recommended code editors, and creating virtual environments. It outlines steps for installing libraries, checking CUDA compatibility, and using PyTorch for deep learning. Additionally, it distinguishes between installing and importing libraries, and lists various Python libraries for data manipulation, visualization, machine learning, and deep learning.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Guide

If library is listed with the following licenses, then they are open source:
 MIT License
 2-Clause BSD License
 Apache Software License
 BSD 3 Clause
Note: Before Installing any Library, check for its license from the following sources:
pip-licenses --order=license
pip-licenses --allow-only="MIT License;BSD License;"
PIP: Python Package Installer (Python Package Index)
Command to install any library: pip install numpy
Command to change directory inside cmd: cd Documents (can be any folder name, in my case, I
created folder in documents)
Python Code Editors
Here is a recommended list of editors for Python:
Visual Studio Code: A free and open-source code editor with many plugins and features available.
PyCharm: A high-featured integrated development environment with extensive debugging and code
completion features.
Sublime Text: A simple and easy-to-use text editor suitable for writing Python code efficiently.
IDLE: The official Python editor with all the basic features.
Jupyter Notebook: A versatile IDE suitable for project management and data analysis.
Each of these editors offers different features in Python development and can be chosen according to
the user's needs.
Steps to Create a Virtual Environment
How to Create a Python Virtual Environment(Step-by-Step Guide) - GeeksforGeeks
1. Open a Terminal or Command Prompt:
Depending on your operating system, you can use the terminal (macOS/Linux) or Command Prompt
(Windows).
2. Navigate to Your Project Directory:
Use the cd command to change the directory to your project's folder (my folder name:
venvManager). For example:
Cd/documents/venManager
3. Create the Virtual Environment:
Use the python -m venv command followed by the name you want to give to your virtual
environment. It's common to name the environment venv or env. I gave name as trial
python -m venv trial
After running this command, a directory named trial will be created. This is where Python packages
will be installed. To list the files in the folder type below command in the terminal:
dir trial
4. Activate the virtual environment:
Activating a virtual environment sets up your terminal to use the specific Python and package
settings for that environment, ensuring isolation from other projects. This prevents dependency
conflicts and ensures consistency in package versions. Different operating systems and shells require
different activation commands. Activation commands vary by operating system and shell.
Input command is as below:
C:\Users\slm22658>cd documents/venvManager/trial/Scripts/activate
Output will be as below, Virtual environment folder name will be on the left side of the
terminal with the folder name inside brackets, it means it is active:
(trial) C:\Users\slm22658\Documents\venvManager\trial\Scripts>
5. Install Packages:
Now that the virtual environment is activated, you can install packages using pip and they will be
installed only in this environment:
pip install numpy
pip list
Now install pytorch. This library is very important for deep learning. For installing pytorch, we went
to pytorch website  [Link]
Now here we choose windows, pip, python, CUDA version (12.8) and copy the command and past
in virtual environment:
pip3 install torch torchvision --index-url [Link]
6. For checking CUDA Version in my PC:
CUDA (Compute Unified Device Architecture) is a parallel computing platform developed by
NVIDIA that maximizes the computing power of GPUs. For checking CUDA Version in my PC:
C:\Users\slm22658>nvidia-smi
7. Can PyTorch use my GPU right now?
python is simply to enter the Python interpreter so you can run Python commands. To check it out
type
python
After this, prompt changed to:
>>>
This means: “You are now inside Python. Type Python code.” Now write the following:
>>>import torch
>>>print([Link].is_available())
If “Yes” comes, it mean PyTorch can see and use your NVIDIA GPU for acceleration.
Python loads the PyTorch package so you can use its functions, such as:
[Link]() — create tensors
[Link].is_available() — check GPU
[Link] — build neural networks
[Link] — optimizers for training
[Link] — datasets and dataloaders
Without import torch, none of these features would exist in your program.
To exit from python environment:
>>>exit
8. Deactivate the Virtual Environment:
When you are done working, you can deactivate the environment by simply typing:
deactivate
Now I will be in global environment as below:
C:\Users\slm22658\Documents\venvManager\trial\Scripts>
Conclusion
Using Python's venv module to create a virtual environment is a best practice that helps you manage
dependencies and avoid conflicts across projects. It keeps your development environment clean,
organized, and easier to maintain. Now that you know how to create, activate, and use virtual
environments, you're ready to build python applications with confidence and clarity.
How to Open Python Virtual Environment in Visual Studio Code
1. Install Python and VS Code
Ensure you have Python installed on your system. Download and install VS Code from its official
website.
2. Install the Python Extension
Launch VS Code, go to the Extensions view by pressing Ctrl+Shift+X, and search for "Python".
Install the extension provided by Microsoft.
3. Now open the main virtual environment folder created from VS Code. File  Open Folder 
Problem-1
4. Create a Python File
Create a new Python file or open an existing one. For example, create a file named [Link].
How to run .py file in Visual Studio Code:
1. Firstly, select Python interpreter
Press: Windows/Linux: Ctrl + Shift + P (Opens command palette)
Type Python: Select Interpreter
Choose a Python version (e.g., Python 3.13)
2. There are different ways to run:
Method-1: Click ▶ Press triangle button, run python file
Method-2: Run from the Terminal ([Link])
3. Select default profile
4. Settings → Terminal → Integrated: Select default ProfileChoose cmd
 If the terminal is powershell then activate the virtual environment with the command
below
Scripts\Activate.ps1
If successful
(Problem-1) PS C:\Users\slm22658\Documents\venvManager\Problem-1>
 If the terminal is cmd then activate the virtual environment with the command below
Scripts\[Link]
To run each line in python code:
right click > Run Selection/Line in Python Terminal
OR
Shift+enter command only run the selected lines of python code.
 The terminal is Windows CMD or PowerShell, not Python — so Windows thinks print is a
printer command. So firstly write “python” in the terminal now it will be in Python interpreter.
Now Shift+enrer button then it will only run the selected lines. Then exit from python >>> by
typing “exit ()” in the terminal.
 If I need to install any library, do it form the terminal in the Visual studio code
pip install numpy matplotlib
VS Code itself doesn’t execute Python — it just tells cmd to run the Python interpreter with
your script, then shows the terminal output.

Installing a library vs. Importing a library


These are two different things:
1. Installing (done once per environment)
You install a library into your virtual environment:
Code
pip install pandas
pip install matplotlib
This puts the library on your computer, inside your venv.
You only do this once (unless you delete the venv).
2. Importing (done every time your script runs)
Inside your .py file, you must tell Python to use the library:
python
import pandas as pd
import [Link] as plt
This tells Python:
 “Load pandas into memory”
 “Load matplotlib into memory”
Every time you run the script, Python starts fresh, so it needs the import lines again.
✔ Install once
✔ Import every time you run the script

To clear terminal
For Bash, Zsh, Git Bash: clear
For Windows PowerShell: cls
For Command Prompt (CMD): cls

 In cmd, type the command below to directly open all folders in visual studio code.
code .
Pytorch:
It is the main deep learning platform in Idea Consultants.

Write code in cmd


Jyupter Notebook is also graphical user interface

Python Libraries:
[Link]
Python libraries are reusable modules with pre-written code that save time and effort in
development.
Array refers to the set of data arranged in certain order for programming purposes.
 Data Manipulation and Analysis
Pandas: For data manipulation and analysis using Data Frames and Series.
NumPy (Numerical Python): For numerical computations and array operations.
SciPy: For scientific and technical computing, including optimization and signal processing.
Polars: A fast Data Frame library for large datasets.
 Data Visualization
Matplotlib: For creating static, animated, and interactive plots.
Seaborn: Built on Matplotlib, ideal for statistical visualizations.
Plotly: For interactive and visually appealing charts.
Bokeh: For interactive visualizations embedded in web applications.
 Machine Learning
Scikit-learn: For traditional machine learning algorithms like classification and regression.
XGBoost: For efficient gradient boosting.
CatBoost: For handling categorical data in machine learning tasks.
 Deep Learning
TensorFlow: For building and training deep neural networks.
PyTorch: A dynamic computational graph library for deep learning.
Keras: A high-level API for neural networks, built on TensorFlow.
Theano: For numerical computations involving multi-dimensional arrays.

Procedure
Pytorch data set and data loader

print(x) Prints all x values


x[:5] First 5 elements
[Link] Size of array
flatten() Makes it one line
[Link]() Reads CSV

You might also like