Articles on Trending Technologies

Technical articles with clear explanations and examples

How can I get a list of locally installed Python modules?

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 4K+ Views

Python is a flexible programming language with thousands of libraries and modules. As your Python environment grows with new installations, it becomes important to check which packages are currently available. Whether you're debugging, documenting your environment, or managing dependencies, listing locally installed Python modules is a valuable skill. In this article, we will explore different ways to get a list of locally installed Python modules using built-in tools and command-line utilities. Using pip list Command The pip package installer provides a list subcommand that displays all installed packages in your current Python environment. This is the most ...

Read More

What is the difference between dir(), globals() and locals() functions in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 909 Views

The Python built-in functions, dir(), globals(), and locals() are used to provide insights into the objects, variables, and identifiers present in various scopes. They might look similar, but each function serves a different purpose and behaves differently depending on where and how it is used. Python dir() Function The Python dir() function is used to list the names in the current local scope or the attributes of an object. If no argument is passed, it returns the list of names in the current local scope. dir(object) Example Let's look at the following ...

Read More

What is a namespace in Python?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 24-Mar-2026 4K+ Views

A Namespace in Python is a container that holds a set of identifiers (variable names) and their associated objects (values). It helps implement the concept of scope in your program, determining which variables are accessible at any given point in your code. Every time a new scope is created—like when a function is defined or executed—a new namespace is created. This namespace acts as an "evaluation context" for the identifiers defined within it. Types of Namespaces Following are the three types of namespaces in Python: Local Namespace − Created for each ...

Read More

How to set your python path on Windows?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 1K+ Views

The PYTHONPATH environment variable tells Python where to look for modules and packages beyond the standard library. While modifying PYTHONPATH is rarely needed, here's how to set it on Windows when necessary. Accessing Environment Variables To set the PYTHONPATH on Windows, navigate to the system environment variables ? My Computer > Properties > Advanced System Settings > Environment Variables Alternatively, you can press Win + R, type sysdm.cpl, and press Enter to access System Properties directly. Setting the PYTHONPATH Variable In the Environment Variables dialog, look for PYTHONPATH under System Variables. If ...

Read More

How to set your python path on Mac?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 2K+ Views

Setting the PYTHONPATH on macOS helps Python locate modules and packages in custom directories. While there are several methods available, it's important to understand when and why to use each approach. What is PYTHONPATH? PYTHONPATH is an environment variable that tells Python where to look for modules and packages beyond the standard library and site-packages directories. Method 1: Temporary Export (Current Session Only) This method sets PYTHONPATH for the current terminal session only − export PYTHONPATH="${PYTHONPATH}:${HOME}/foo" This adds the foo directory in your home folder to Python's search path. The ${PYTHONPATH}: part ...

Read More

How to set your python path on Linux?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 1K+ Views

To set the PYTHONPATH on Linux to point Python to look in other directories for the module and package imports, you can use the export command. This is useful when you have custom modules or packages in non-standard locations. Setting PYTHONPATH Temporarily To add a directory to PYTHONPATH for the current terminal session ? $ export PYTHONPATH=${PYTHONPATH}:${HOME}/foo This command appends the foo directory to the existing PYTHONPATH without replacing its original value. Example Let's create a custom module and add its directory to PYTHONPATH ? $ mkdir ~/mymodules $ echo ...

Read More

How to set python environment variable PYTHONPATH on Mac?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 13K+ Views

PYTHONPATH is an environment variable that tells Python where to look for modules when importing. On Mac, there are several methods to set PYTHONPATH depending on your shell and persistence needs. Method 1: Temporary Setting (Current Session Only) Set PYTHONPATH for the current terminal session only ? export PYTHONPATH=/path/to/your/modules This setting is lost when you close the terminal. Method 2: Permanent Setting Using .bash_profile For Bash shell users, add PYTHONPATH to your profile file ? Step 1: Open Terminal and navigate to your home directory ? cd ~ ...

Read More

How to set Python environment variable PYTHONPATH on Linux?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 25K+ Views

The PYTHONPATH environment variable tells Python where to look for modules and packages beyond the standard library. Setting it correctly on Linux ensures your custom modules can be imported from any location. Basic PYTHONPATH Setup Open a terminal and use the export command to set PYTHONPATH ? export PYTHONPATH=/home/user/myproject:$PYTHONPATH This command adds /home/user/myproject to PYTHONPATH while preserving any existing paths. The colon (:) separates multiple paths on Linux. Verifying PYTHONPATH Check if PYTHONPATH was set correctly ? echo $PYTHONPATH This displays the current PYTHONPATH value, showing all directories ...

Read More

What is PYTHONPATH environment variable in Python?

Rajendra Dharmkar
Rajendra Dharmkar
Updated on 24-Mar-2026 44K+ Views

In Python, PYTHONPATH is an environment variable that specifies additional directories where Python searches for modules during imports. When you import a module, Python searches through directories listed in sys.path, which includes the current working directory, standard library paths, and any directories specified in PYTHONPATH. PYTHONPATH allows you to add custom directories containing your Python modules without installing them in the global site-packages directory. This is particularly useful for maintaining project-specific libraries or when you don't have permissions to install packages globally. What is PYTHONPATH? PYTHONPATH is an environment variable that extends Python's module search path. When ...

Read More

How to import a single function from a Python module?

Yaswanth Varma
Yaswanth Varma
Updated on 24-Mar-2026 10K+ Views

In Python, a module is a file containing Python definitions and statements. For keeping code organized, we often write functions in separate modules and import them into the main program. While importing the entire module, sometimes we only need a single function from it. Python provides a direct way to do this using the from module_name import function_name syntax, which is more memory-efficient and cleaner than importing the whole module. Syntax from module_name import function_name This imports only the specified function, making it available directly without the module prefix. Importing sqrt() from math ...

Read More
Showing 1–10 of 61,302 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements