Found 27104 Articles for Server Side Programming

How to set your python path on Windows?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:44:06

796 Views

To set the PYTHONPATH on windows to point Python to look in other directories for module and package imports, go to:My Computer > Properties > Advanced System Settings > Environment VariablesThen under system variables edit the PythonPath variable. At the end of the current PYTHONPATH, add a semicolon and then the directory you want to add to this path:C:\Python27;C:\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 ... Read More

How to set your python path on Mac?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:44:46

1K+ Views

To set the PYTHONPATH on Mac OS to point Python to look in other directories for module and package imports, export the PYTHONPATH variable as follows:$ export PYTHONPATH=${PYTHONPATH}:${HOME}/foo In 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

How to set your python path on Linux?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:45:28

783 Views

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.

How to set python environment variable PYTHONPATH on Windows?

Rajendra Dharmkar
Updated on 02-May-2023 12:43:46

33K+ Views

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 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 ... Read More

How to set python environment variable PYTHONPATH on Mac?

Rajendra Dharmkar
Updated on 02-May-2023 12:42:27

9K+ Views

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/ This sets the PYTHONPATH environment variable to the path /path/to/my/python/modules. You should replace this with the path to the directory where your Python modules are ... Read More

How to set Python environment variable PYTHONPATH on Linux?

Rajendra Dharmkar
Updated on 02-May-2023 12:39:55

15K+ Views

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:$ 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. Verify that the PYTHONPATH environment variable has been set correctly using the following command − ... Read More

What is PYTHONPATH environment variable in Python?

Rajendra Dharmkar
Updated on 26-Aug-2023 08:50:16

35K+ Views

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

What is the use of "from...import *" Statement in Python?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:48:52

1K+ Views

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

What is the use of "from...import" Statement in Python?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:49:27

2K+ Views

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

How to import a single function from a Python module?

Rajendra Dharmkar
Updated on 30-Sep-2019 08:30:55

9K+ Views

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

Advertisements