Python Programming – Setting up Path

Many directories contain programs and other executable files, therefore, the operating system Windows, Unix/Linux, or MAC search for executables by providing a search path for directories. The path is a named string maintained by the operating system and is stored in an environment variable. The environment variable contains information available to the come shell and other programs.

The Unix is a case-sensitive operating system. However, Windows does not follow case sensitivity. So path variable is named PATH in Unix or Path in windows. On the other hand, in Mac OS, all the path details are handled by the installer. The path variable of your operating system is needed to be set before invoking the python interpreter from any particular directory.

Setting up the path at Unix/Linux

Since many shells are available in Unix/Linux OS, the path set up is slightly different for different shells. For csh, bash, sh, and ksh shells the Python path can be set as follows for a particular session in Unix:

  • In the csh shell: type setenv PATH “$PATH:/usr/local/bin/python” and press Enter.
  • In the bash shell (Linux): type export

PATH=”$PATH:/usr/local/bin/python” and press Enter.

  • In the sh or ksh shell: type PATH=”$PATH:/usr/local/bin/python” and press Enter.

Note: /usr/local/bin/python is the path of the Python directory

Setting up Path at Windows

To add the Python directory to the path for a particular session in Windows:

  • At the command prompt: type path %path%;C:\Python and press Enter.
    Note: C:\Python is the path of the Python directory

Python Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *