TRying to import files from my folder not pythons lib folder

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tedpottel@gmail.com

    TRying to import files from my folder not pythons lib folder

    Hi,

    I'm trying to create my own lib of functions, but it seems like I can
    only import them if they are in pythons lib folder.

    Example
    I have a folder called
    K:\mypython

    Now in the interactive python shell I type
    Import k:\mypython\lis tall
    And get a error on :

    If I store listall.py in pythons lib folder and type
    Limport listall

    It works fins.

    Can I create my own library of functions and store them in a separate
    dir????

    Also I try to creat a folder in pythomns lib folder and that did not
    work

    Help
    -Ted

  • kyosohma@gmail.com

    #2
    Re: TRying to import files from my folder not pythons lib folder

    On Sep 21, 12:32 pm, "tedpot...@gmai l.com" <tedpot...@gmai l.com>
    wrote:
    Hi,
    >
    I'm trying to create my own lib of functions, but it seems like I can
    only import them if they are in pythons lib folder.
    >
    Example
    I have a folder called
    K:\mypython
    >
    Now in the interactive python shell I type
    Import k:\mypython\lis tall
    And get a error on :
    >
    If I store listall.py in pythons lib folder and type
    Limport listall
    >
    It works fins.
    >
    Can I create my own library of functions and store them in a separate
    dir????
    >
    Also I try to creat a folder in pythomns lib folder and that did not
    work
    >
    Help
    -Ted
    One workaround is to do to this:

    <code>

    import sys
    sys.path.append (r'K:\mypython' )
    import listall

    </code>

    You can also add your path to the .pth file, but I've never done that,
    so I can't tell you how.

    Hope that helps!

    Mike

    Comment

    • Steve Holden

      #3
      Re: TRying to import files from my folder not pythons lib folder

      kyosohma@gmail. com wrote:
      On Sep 21, 12:32 pm, "tedpot...@gmai l.com" <tedpot...@gmai l.com>
      wrote:
      >Hi,
      >>
      >I'm trying to create my own lib of functions, but it seems like I can
      >only import them if they are in pythons lib folder.
      >>
      >Example
      >I have a folder called
      >K:\mypython
      >>
      >Now in the interactive python shell I type
      >Import k:\mypython\lis tall
      >And get a error on :
      >>
      >If I store listall.py in pythons lib folder and type
      >Limport listall
      >>
      >It works fins.
      >>
      >Can I create my own library of functions and store them in a separate
      >dir????
      >>
      >Also I try to creat a folder in pythomns lib folder and that did not
      >work
      >>
      >Help
      >-Ted
      >
      One workaround is to do to this:
      >
      <code>
      >
      import sys
      sys.path.append (r'K:\mypython' )
      import listall
      >
      </code>
      >
      You can also add your path to the .pth file, but I've never done that,
      so I can't tell you how.
      >
      Hope that helps!
      >
      Mike
      >
      The easiest way, particularly for testing, is to set the PYTHONPATH
      variable. It should be a colon-separated list of directories on Unices,
      and a semi-colon separated list on Windows. Those directories will be
      added to sys.path.

      See http://docs.python.org/tut/node8.html for yet more.

      regards
      Steve

      --
      Steve Holden +1 571 484 6266 +1 800 494 3119
      Holden Web LLC/Ltd http://www.holdenweb.com
      Skype: holdenweb http://del.icio.us/steve.holden

      Sorry, the dog ate my .sigline

      Comment

      • =?iso-8859-1?q?Luis_M=2E_Gonz=E1lez?=

        #4
        Re: TRying to import files from my folder not pythons lib folder


        Steve Holden wrote:
        kyosohma@gmail. com wrote:
        On Sep 21, 12:32 pm, "tedpot...@gmai l.com" <tedpot...@gmai l.com>
        wrote:
        Hi,
        >
        I'm trying to create my own lib of functions, but it seems like I can
        only import them if they are in pythons lib folder.
        >
        Example
        I have a folder called
        K:\mypython
        >
        Now in the interactive python shell I type
        Import k:\mypython\lis tall
        And get a error on :
        >
        If I store listall.py in pythons lib folder and type
        Limport listall
        >
        It works fins.
        >
        Can I create my own library of functions and store them in a separate
        dir????
        >
        Also I try to creat a folder in pythomns lib folder and that did not
        work
        >
        Help
        -Ted
        One workaround is to do to this:

        <code>

        import sys
        sys.path.append (r'K:\mypython' )
        import listall

        </code>

        You can also add your path to the .pth file, but I've never done that,
        so I can't tell you how.

        Hope that helps!

        Mike
        The easiest way, particularly for testing, is to set the PYTHONPATH
        variable. It should be a colon-separated list of directories on Unices,
        and a semi-colon separated list on Windows. Those directories will be
        added to sys.path.
        >
        See http://docs.python.org/tut/node8.html for yet more.
        >
        regards
        Steve
        >
        --
        Steve Holden +1 571 484 6266 +1 800 494 3119
        Holden Web LLC/Ltd http://www.holdenweb.com
        Skype: holdenweb http://del.icio.us/steve.holden
        >
        Sorry, the dog ate my .sigline
        This is exactly what I did, but I have a new problem now:
        After seting PYTHONPATH I'm no longer able to start IDLE from the
        start menu.
        It seems the system cannot find the file.
        But if I eliminate PYTHONPATH, everything works as it used to.

        I set PYTHONPATH because I wanted to import any existing file in my
        desktop without having to use sys.path.append ...
        It works when using the command line but strangely, something get
        messed up with IDLE.
        Any hint?

        Luis

        Comment

        • Gabriel Genellina

          #5
          Re: TRying to import files from my folder not pythons lib folder

          En Sun, 23 Sep 2007 22:01:39 -0300, Luis M. González <luismgz@gmail. com>
          escribi�:
          This is exactly what I did, but I have a new problem now:
          After seting PYTHONPATH I'm no longer able to start IDLE from the
          start menu.
          It seems the system cannot find the file.
          But if I eliminate PYTHONPATH, everything works as it used to.
          >
          I set PYTHONPATH because I wanted to import any existing file in my
          desktop without having to use sys.path.append ...
          It works when using the command line but strangely, something get
          messed up with IDLE.
          Any hint?
          Perhaps a python module in your desktop has a name conflicting with a
          standard module?

          - On the Start menu, navigate to the IDLE item, but dont click it.
          - RIGHT click on it, and select Properties. Copy the Destination field.
          Should be something like "C:\Python25\Li b\idlelib\idle. bat"
          - Open a cmd window (console), paste the above text and press Enter.
          - Almost certainly you'll get an error; post here the full error and
          traceback.

          --
          Gabriel Genellina

          Comment

          • =?iso-8859-1?q?Luis_M=2E_Gonz=E1lez?=

            #6
            Re: TRying to import files from my folder not pythons lib folder

            On Sep 24, 5:00 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
            wrote:
            En Sun, 23 Sep 2007 22:01:39 -0300, Luis M. González <luis...@gmail. com>
            escribi?:
            >
            This is exactly what I did, but I have a new problem now:
            After setingPYTHONPAT HI'm no longer able to start IDLE from the
            start menu.
            It seems the system cannot find the file.
            But if I eliminatePYTHON PATH, everything works as it used to.
            >
            I setPYTHONPATHbe cause I wanted to import any existing file in my
            desktop without having to use sys.path.append ...
            It works when using the command line but strangely, something get
            messed up with IDLE.
            Any hint?
            >
            Perhaps a python module in your desktop has a name conflicting with a
            standard module?
            >
            - On the Start menu, navigate to the IDLE item, but dont click it.
            - RIGHT click on it, and select Properties. Copy the Destination field.
            Should be something like "C:\Python25\Li b\idlelib\idle. bat"
            - Open a cmd window (console), paste the above text and press Enter.
            - Almost certainly you'll get an error; post here the full error and
            traceback.
            >
            --
            Gabriel Genellina
            I solved the problem!
            You were right. It seems there was a module that was causing problems,
            although I don't know which one...
            I just moved all the .py files on my desktop to a new folder, and
            everything worked just fine.
            The list of .py files in my desktop were:

            'code.py', 'code2.py', 'code22.py', 'code3.py', 'draft.py',
            'flups.py', 'forma.py', 'fx.py', 'nuevo.py', 'nwind', 'ops',
            'pages.py', 'qqq.py', 'sample.py', 'ses.py', 'sess.py', 'sess2.py',
            'soup.py', 'style.py', 'test_session.p y', 'up.py', 'up2.py', 'ww.py',
            'xx.pyw', 'xx.rsrc.py', 'xxxx.py'

            Any idea of which one was causing trouble?

            Gracias, che!
            Luis

            Comment

            • Gabriel Genellina

              #7
              Re: TRying to import files from my folder not pythons lib folder

              En Mon, 24 Sep 2007 22:36:38 -0300, Luis M. González <luismgz@gmail. com>
              escribi�:
              I solved the problem!
              You were right. It seems there was a module that was causing problems,
              although I don't know which one...
              I just moved all the .py files on my desktop to a new folder, and
              everything worked just fine.
              The list of .py files in my desktop were:
              >
              'code.py', 'code2.py', 'code22.py', 'code3.py', 'draft.py',
              'flups.py', 'forma.py', 'fx.py', 'nuevo.py', 'nwind', 'ops',
              'pages.py', 'qqq.py', 'sample.py', 'ses.py', 'sess.py', 'sess2.py',
              'soup.py', 'style.py', 'test_session.p y', 'up.py', 'up2.py', 'ww.py',
              'xx.pyw', 'xx.rsrc.py', 'xxxx.py'
              >
              Any idea of which one was causing trouble?
              Possibly code.py, it's a standard module
              <http://docs.python.org/lib/module-code.html>
              Gracias, che!
              De nada loco!

              --
              Gabriel Genellina

              Comment

              Working...