PYTHONPATH?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dr. Pastor

    PYTHONPATH?

    Several Documents about Python
    refer to PYTHONPATH.
    I could not find such variable.
    (Python 2.4.2, IDLE 1.1.2, Windows XP)
    How should/could I nominate a Directory to be
    the local Directory?
    Thanks for any guidance.
  • Diez B. Roggisch

    #2
    Re: PYTHONPATH?

    Dr. Pastor wrote:
    [color=blue]
    > Several Documents about Python
    > refer to PYTHONPATH.
    > I could not find such variable.
    > (Python 2.4.2, IDLE 1.1.2, Windows XP)
    > How should/could I nominate a Directory to be
    > the local Directory?
    > Thanks for any guidance.[/color]

    It's a so called environment-variable. You can set these in some obscure
    windows dialog in the system-preferences on a per-system or per-user base.
    Or you start using cygwin (lots of good other reasons for that), and do

    export PYTHONPATH=/whatever

    Diez

    Comment

    • Magnus Lycka

      #3
      Re: PYTHONPATH?

      Dr. Pastor wrote:[color=blue]
      > Several Documents about Python refer to PYTHONPATH.[/color]

      If you need to import libraries into Python, that don't reside in the
      standard locations in your Python installation, you need to define
      a PYTHONPATH environment variable in the operating system, which
      points out this directory.

      Defining this is done in the same way as defining PATH etc.
      [color=blue]
      > I could not find such variable.[/color]

      Do you need it for anything?
      [color=blue]
      > (Python 2.4.2, IDLE 1.1.2, Windows XP)
      > How should/could I nominate a Directory to be the local Directory?[/color]

      import os
      os.chdir('c:/somedir')

      Another way is to start python from there, e.g. from the
      command prompt (nothing beats a command prompt!) you would do:

      cd some\local\dire ctory
      python myscript.py (... or just python ...)

      Note that backslash in a Python string literal denotes an escape
      sequence. In Python 'c:\temp' means 'c' ':' tab 'e' 'm' 'p', since
      '\t' is the escape sequence for a tab. You can use 'c:/temp' (ok
      for Windows APIs) r'c:\temp' (r for raw string, i.e. don't use
      escape sequences) or 'c:\\temp' (\\ is the escape sequence for
      backslash).

      Also note, that the way to use libraries from an arbitrary
      directory without setting PYTHONPATH, is not with os.chdir,
      but by doing this:

      import sys
      sys.path.append ('c:/somedir')

      Comment

      • Tombo

        #4
        Re: PYTHONPATH?

        Said obscure dialog is here:
        My Computer > Properties > Advanced (tab) > Environment Variables

        You probably want a new system variable.

        You can check the value by starting a new terminal window and typing:

        echo %PYTHONPATH%

        Cheers
        Tombo

        Diez B. Roggisch wrote:[color=blue]
        > Dr. Pastor wrote:
        >[color=green]
        > > Several Documents about Python
        > > refer to PYTHONPATH.
        > > I could not find such variable.
        > > (Python 2.4.2, IDLE 1.1.2, Windows XP)
        > > How should/could I nominate a Directory to be
        > > the local Directory?
        > > Thanks for any guidance.[/color]
        >
        > It's a so called environment-variable. You can set these in some obscure
        > windows dialog in the system-preferences on a per-system or per-user base.
        > Or you start using cygwin (lots of good other reasons for that), and do
        >
        > export PYTHONPATH=/whatever
        >
        > Diez[/color]

        Comment

        Working...