Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Friday, May 24, 2024

How to set verbose in Langchain

Here is how you can set globally. 

from langchain.globals import set_verbose, set_debug

set_debug(True)
set_verbose(True)
  

You can also scope verbosity down to a single object, in which case only the inputs and outputs to that object are printed (along with any additional callbacks calls made specifically by that object).

# Passing verbose=True to initialize_agent will pass that along to the AgentExecutor (which is a Chain).
agent = initialize_agent(
    tools, 
    llm, 
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True,
)

agent.run("who invented electricity")
  

Hope this helps!!

Monday, February 12, 2024

Learn Python for free!!!

is one of the easiest and most widely used programming languages. If you want to master Python, use these 5 FREE resources

1. Learn Basic concepts of Python
https://cs50.harvard.edu/python/2022/

2.  Learn Python basics for Data Analysis
https://t.co/0wPzZtaU25

3. Data Science with Python
https://t.co/dSRiUCKArm

4. Learn Django, a popular Python framework.
https://youtube.com/watch?v=rHux0gMZ3Eg

5. Learn Python and build 5 games with Free Code Camp's 6.5 hour tutorial.
https://youtube.com/watch?v=XGf2GcyHPhc

Happy Learning!!

Friday, February 09, 2024

[Solved] No module named MySQLdb

The error message "No module named 'MySQLdb'" typically indicates that Python cannot locate the MySQLdb module, which is a Python interface for accessing MySQL databases. This could be due to various reasons such as the module not being installed or the path to the installation directory not being correctly set. To fix this issue, you can either install the module using pip (the Python package installer) or set the path to the installation directory manually. 

To set the path to the MySQLdb installation directory in Python, you can follow these steps:

1. First, ensure that the MySQLdb module is installed in your Python environment. If not, you can install it using pip by running the following command in your terminal or command prompt:

pip install mysqlclient

2. Once the module is installed, you can check the installation path and set the path in Python using the following steps:

   - Open a Python environment or script.
   - At the top of your Python script or in the Python environment, you can set the path to the MySQLdb installation directory using the following code:

import sys
sys.path.append('/path/to/MySQLdb')

Replace "/path/to/MySQLdb" with the actual path to the MySQLdb installation directory on your system.

By setting the path in this way, you are enabling Python to locate the MySQLdb module when it is imported in your code. 

Hope this helps!!

Sunday, January 21, 2024

How to Create and Pip Install Requirements.txt in Python

Many projects rely on libraries and other dependencies, and installing each one can be tedious and time-consuming.

This is where a ‘requirements.txt’ file comes into play. requirements.txt is a file that contains a list of packages or libraries needed to work on a project that can all be installed with the file. It provides a consistent environment and makes collaboration easier. 'requirements.txt' ensures consistent environment and facilitating collaboration.

Key Points:

  1. Importance of Dependencies: Dependencies are crucial software components required for a program to run correctly. They can be libraries, frameworks, or other programs.

  2. Purpose of 'requirements.txt': It contains a list of packages or libraries needed for a project, allowing for their easy installation while ensuring a consistent environment for collaborative work.

  3. Creating a 'requirements.txt' file: It involves setting up a virtual environment and using the command 'pip freeze > requirements.txt' to capture the list of installed packages and their versions.

  4. Working with a 'requirements.txt' file: After creating the file, the listed dependencies can be installed using the command. 'pip install -r requirements.txt'.

  5. Benefits of 'requirements.txt': It simplifies managing dependencies, aids in sharing projects with others by ensuring easy installation of required packages, and helps maintain consistency in package versions across different environments.

Wednesday, August 09, 2023

Managing Python Packages: Installation, Upgrades, and Removal

Python, a versatile and widely-used programming language, owes much of its power to the extensive ecosystem of third-party packages that developers can easily integrate into their projects. Whether you're a seasoned developer or just getting started, understanding how to manage these packages is a crucial skill. In this guide, we'll walk you through the steps of installing, upgrading, and removing Python packages using the popular package manager, "pip".

Getting Started with "pip"

"pip" is the de facto package manager for Python, making package installation and management a breeze. Before diving into the specifics, ensure you have "pip" installed. To check, simply run the following command in your terminal:

pip --version
  

If you don't have it installed, you can easily install it using "get-pip.py":

python -m ensurepip --default-pip
  

 

Installing Packages

Installing packages is the first step in enhancing your Python projects with additional functionality. The process is straightforward:

pip install package_name

For example, to install the popular data manipulation library "pandas", enter:
pip install pandas

"pip" will automatically fetch the latest version of the package from the Python Package Index (PyPI) and install it in your environment.

Upgrading Packages

Keeping your packages up to date is crucial for security and ensuring that you have access to the latest features and bug fixes. To upgrade a package to its latest version:

pip install --upgrade package_name

For instance, to upgrade the "requests" library, simply use:
pip install --upgrade requests

This command fetches the latest version of the package and updates your environment.

Removing Packages

There might come a time when you need to remove a package from your project. The process is as simple as the rest:

pip uninstall package_name

For example, to uninstall the package "matplotlib":
pip uninstall matplotlib

 

Virtual Environments: Keeping Things Tidy

A best practice when working with Python packages is to use virtual environments. These isolated environments prevent conflicts between different projects' dependencies. To create a virtual environment:

1. Navigate to your project directory in the terminal.
2. Run the appropriate command based on your operating system:

   On macOS/Linux:

python -m venv venv_name

   On Windows:

python -m venv venv_name

3. Activate the virtual environment:

   On macOS/Linux:

source venv_name/bin/activate

   On Windows:

venv_name\Scripts\activate
  

With the virtual environment activated, you can install, upgrade, and remove packages without affecting the global Python environment. When you're done, deactivate the virtual environment:

deactivate
  
    

Conclusion

Managing Python packages with "pip" is an essential skill for every Python developer. It allows you to harness the vast potential of third-party libraries, ensuring your projects are efficient, feature-rich, and up to date. By mastering the installation, upgrade, and removal processes, and by using virtual environments, you'll be well-equipped to navigate the Python package landscape and build robust applications with ease. Happy coding!

Tuesday, July 18, 2023

How to downgrade the installed version of 'pip' on windows?

If you want to upgrade or downgrade to different version of pip, you can do it in multiple ways.

To go back to particular version, use below command

python -m pip install pip==23.1.2

If you want to upgrade or downgrade using single command, use below command with specific version

python -m pip install --upgrade pip==23.1.2

If you want to upgrade to latest version, use below command

python -m pip install --upgrade pip

Hope this helps!!

Friday, June 30, 2023

Best YouTube channels for Data Science

❯ Python ➟ Corey Schafer

❯ SQL ➟ Joey Blue

❯ Data Analyst ➟ AlexTheAnalyst

❯ Tableau ➟ Tableau Tim

❯ PowerBI ➟ Guy in a Cube

❯ MS Excel ➟ ExcelIsFun

❯ Machine Learning ➟ sentdex

❯ Mathematics ➟ 3Blue1Brown

❯ And the winner is  ➟ Socratica, who does educational vidoes on math, science and computers

Wednesday, June 07, 2023

What are the key differences between Python and Anaconda?

Python is a multi-purpose programming language used in everything from from machine learning to web design. It uses pip (a recursive acronym for "Pip Installs Packages" or "Pip Installs Python") as its package manager to automate installation, update, and package removal.

Anaconda is a distribution (a bundle) of Python, R, and other languages, as well as tools tailored for data science (i.e., Jupyter Notebook and RStudio). It also provides an alternative package manager called conda.

So, when you install Python, you get a programming language and pip (available in Python 3.4+ and Python 2.7.9+), which enables a user to install additional packages available on Python Package Index (or PyPi).

In contrast, with Anaconda you get Python, R, 250+ pre-installed packages, data science tools, and the graphical user interface Anaconda Navigator.

Python and Anaconda are not directly comparable as they serve different purposes. Here are the key differences between Python and Anaconda:

Python:

  1. Programming Language: Python is a widely-used high-level programming language known for its simplicity and readability. It provides a broad range of libraries and frameworks for various purposes, such as web development, data analysis, artificial intelligence, and more.

  2. Interpreter: Python has an official interpreter that allows you to execute Python code. You can write Python scripts and execute them using the Python interpreter installed on your system.

  3. Package Manager: Python has its package manager called pip (Python Package Installer). It is used to install and manage Python packages from the Python Package Index (PyPI) and other sources. Pip helps you download and install packages required for your Python projects.

Anaconda:

  1. Distribution: Anaconda is a distribution of Python and other scientific computing packages. It includes the Python interpreter along with commonly used packages for scientific computing, data analysis, and machine learning.

  2. Package Management: Anaconda comes with its own package management system called Conda. Conda allows you to create separate environments with different package versions and dependencies, making it easier to manage complex projects with conflicting requirements.

  3. Additional Packages: Anaconda includes a curated collection of packages commonly used in data science, machine learning, and scientific computing. It provides popular packages like NumPy, pandas, Matplotlib, scikit-learn, and Jupyter Notebook out of the box.

  4. Cross-Platform Support: Anaconda is designed to work seamlessly on different operating systems, including Windows, macOS, and Linux. It simplifies the installation and management of packages, especially those with complex dependencies.

In summary, Python is a programming language, while Anaconda is a distribution of Python bundled with additional packages and tools for scientific computing. Anaconda's Conda package manager provides an environment management system, making it popular among data scientists and researchers working on complex projects.

Saturday, June 03, 2023

What is NameError in Python?

Which error will be thrown when a variable is deleted using del

In Python, a NameError occurs when an identifier (variable, function, class, etc.) is undefined. This error occurs when Python encounters a variable or an identifier that it doesn't recognize or cannot find in the current namespace.

NameError can occur due to various reasons. One common reason for a NameError is when a variable is referenced before it is defined. Another reason for the occurrence of NameError is when the name is misspelled or mistakenly written in the wrong case.

Sometimes, it can also occur when you try to access a variable outside of its scope. When this error occurs, Python interpreter raises an exception with a message stating the name that caused the error.

As a programmer, it's essential to handle such errors in Python by using try and except statements and also verifying that all variables are correctly defined and accessed within their intended scope.

Wednesday, May 31, 2023

Data Structures in Python

Python provides several built-in data structures that are commonly used in programming

Below is some helpful summary on Python Data Structures

1685466094870