- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9415 Articles for Python

Updated on 30-Sep-2019 08:45:28
To set the PYTHONPATH on Linux to point Python to look in other directories for the module and package imports, export the PYTHONPATH variable as follows:$ export PYTHONPATH=${PYTHONPATH}:${HOME}/fooIn this case, are adding the foo directory to the PYTHONPATH. Note that we are appending it and not replacing the PYTHONPATH's original value. In most cases, you shouldn't mess with PYTHONPATH. More often than not, you are doing it wrong and it will only bring you trouble. 
Updated on 27-Mar-2023 16:05:04
On Windows, you can set the PYTHONPATH environment variable to specify the directories that Python should search for modules when importing them. Here are several ways to set the PYTHONPATH environment variable on Windows: 1. Set PYTHONPATH using Command Prompt You can set the PYTHONPATH environment variable using Command Prompt by entering the following command: $set PYTHONPATH=c:\path\to\my\modules This sets the PYTHONPATH environment variable to c:\path\to\my\modules. To make this change permanent, you need to add it to the system environment variables: Open the Start menu and search for "Environment Variables". Click on "Edit the system environment variables". Click on the ... Read More 
Updated on 27-Mar-2023 16:10:59
To set the Python environment variable PYTHONPATH on a Mac, you can follow these steps: Open the Terminal app on your Mac. Navigate to your home directory by typing cd ~ and pressing Enter. Open the .bash_profile file in a text editor by typing open -e .bash_profile and pressing Enter. Create a new file called .bash_profile by typing touch .bash_profile and pressing Enter. Add a line to set the PYTHONPATH environment variable in the file. For example: $export PYTHONPATH=/path/to/my/python/modules This sets the PYTHONPATH environment variable to the path /path/to/my/python/modules. You ... Read More 
Updated on 27-Mar-2023 18:15:41
To set the PYTHONPATH environment variable on Linux, follow these steps: Open a terminal window on your Linux system. Determine the path to your Python module or package. For example, suppose you have a Python module named mymodule located in the /home/user/myproject folder. Set the PYTHONPATH environment variable to the path of your module or package using the following command: $export PYTHONPATH=/home/user/myproject:$PYTHONPATH This command sets the PYTHONPATH environment variable to /home/user/myproject and also includes the previous value of PYTHONPATH in case it was already set. Note that the path should be separated by a colon (:) on Linux. ... Read More 
Updated on 27-Mar-2023 18:16:27
In Python, PYTHONPATH is an environment variable that specifies a list of directories to search for Python modules when importing them. When you import a module in Python, Python looks for the module in the directories specified in sys.path, which is a list of directories that includes the current working directory and directories specified in PYTHONPATH. PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find ... Read More 
Updated on 30-Sep-2019 08:48:23
For a pure python module you can find the location of the source files by looking at the module.__file__. For example,>>> import mymodule
>>> mymodule.__file__
C:/Users/Ayush/mymodule.pyMany built in modules, however, are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and therefore, you can't see the source.Running "python -v" from the command line tells you what is being imported and from where. This is useful if you want to know the location of built in modules. 
Updated on 30-Sep-2019 08:48:52
The "from module import *" statement is used to import all function from a Python module. For example, if you want to import all functions from math module and do not want to prefix "math." while calling them, you can do it as follows:>>> from math import * >>> sin(0) 0.0 >>> cos(0) 1.0Note that for any reasonable large set of code, if you import * you will likely be cementing it into the module, unable to be removed. This is because it is difficult to determine what items used in the code are coming from 'module', making it easy ... Read More 
Updated on 30-Sep-2019 08:49:27
The "from module import function" statement is used to import a specific function from a Python module. For example, if you want to import the sin function from the math library without importing any other function, you can do it as follows:>>> from math import sin
>>> sin(0)
0.0Note that you don't have to prefix sin with "math." as only sin has been imported and not math. Also you can alias imported functions. For example,>>> from math import cos as cosine
>>> cosine(0)
1.0 
Updated on 30-Sep-2019 08:30:55
You can use the "from module import function" statement to import a specific function from a Python module. For example, if you want to import the sin function from the math library without importing any other function, you can do it as follows:>>> from math import sin
>>> sin(0)
0.0Note that you don't have to prefix sin with "math." as only sin has been imported and not math. Also you can alias imported functions. For example,>>> from math import cos as cosine
>>> cosine(0)
1.0 
Updated on 30-Sep-2019 08:31:50
To import multiple modules, just use the import statement multiple times. For example, >>> import os >>> import math >>> import sysSometimes grouping imports make more sense. To import multiple modules with a single import statement, just separate the module names by commas. For example, >>> import math, sys, osIf you want to change the name under which the modules are imported, just add as after each module name followed by module alias. For example, >>> import math as Mathematics, sys as systemIf you have a list of modules you want to import as strings, then you can use the ... Read More Advertisements