<>Environment Variables! Can they get around specifying the path on the command line?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #16
    Originally posted by ghostdog74
    hi barton, let's try this ok, just to verify if i understand you. In my environment, I have C:\Python24\lib \site-packages\. And under this site-packages directory, i have a pywin32.pth file. The contents of this pywin32.pth file looks like this:
    Code:
    #.pth file for PyWin32 extensions
    win32
    win32\lib
    Pythonwin
    This is my environment. Opening an interactive prompt, I type
    Code:
    >>> import win32com.client.connect
    >>>
    and this works as supposed to be. Now, if I were to call up connect.py from the command line at c:\> drive,

    Code:
    c:\> python connect.py
    python: can't open 'connect.py': [Errno 2] No such file or directory
    even though pywin32.pth is there in site-packages. Am i doing this correctly?
    Damn! You are so right. .pth in site-packages only works on imports.

    PYTHONPATH environment variable is probably the most straight forward approach.

    Comment

    • ghostdog74
      Recognized Expert Contributor
      • Apr 2006
      • 511

      #17
      Originally posted by bartonc
      Damn! You are so right. .pth in site-packages only works on imports.

      PYTHONPATH environment variable is probably the most straight forward approach.
      well, even if PYTHONPATH set , it's still not working. PYTHONPATH is also used for imports. my script is in d:\> drive
      Code:
      c:\> set PYTHONPATH=d:\script
      c:\> echo %PYTHONPATH%
      d:\script
      c:\> python myscript.py
      python: can't open file 'myscript.py': [Errno 2] No such file or directory

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #18
        Originally posted by ghostdog74
        well, even if PYTHONPATH set , it's still not working. PYTHONPATH is also used for imports. my script is in d:\> drive
        Code:
        c:\> set PYTHONPATH=d:\script
        c:\> echo %PYTHONPATH%
        d:\script
        c:\> python myscript.py
        python: can't open file 'myscript.py': [Errno 2] No such file or directory
        I feel like a fool!
        I tried this, too, running the command prompt pointing at D:. No good either.
        I thought that I had done this in the past. I must be getting old and addle-brained.

        Thanks for all you input on this. I really learned something.

        Comment

        • bartonc
          Recognized Expert Expert
          • Sep 2006
          • 6478

          #19
          Originally posted by bartonc
          I feel like a fool!
          I tried this, too, running the command prompt pointing at D:. No good either.
          I thought that I had done this in the past. I must be getting old and addle-brained.

          Thanks for all you input on this. I really learned something.
          I have a suggestion (this is what I do so that I never type in the path of a Python script):
          On Windows: Make a shortcut to the script in question and double click it. You can even put command-line arguments in the shortcut properties dialog.

          Comment

          • St33med
            New Member
            • Mar 2007
            • 21

            #20
            Why I ask is because some files just say that inputing python 'filename' into the command prompt should do...

            I was able to do this at version 2.3, but now, it seems like someone has removed the feature... or royally screwed it up...

            Comment

            • St33med
              New Member
              • Mar 2007
              • 21

              #21
              Also, what I found weird was when I just put the filename AND ONLY the filename into command prompt, it ran... What I did was just add .PY and .PYW to the PATHEXT variable.

              Like, for example...
              Code:
              C:\Documents and Settings\Andrew Rufkahr>addressbook.py
              
                      1) Add Entry
                      2) Remove Entry
                      3) Find Entry
                      4) List Entries
                      5) Quit and save
              
              Select a choice(1-6):
              Now THAT'S weird! It isn't even in the Current directory I'm in!

              But if I try to open something in the Documents and settings it tells me that there is no such file or directory...

              Comment

              • ghostdog74
                Recognized Expert Contributor
                • Apr 2006
                • 511

                #22
                Originally posted by St33med
                Also, what I found weird was when I just put the filename AND ONLY the filename into command prompt, it ran... What I did was just add .PY and .PYW to the PATHEXT variable.

                Like, for example...
                Code:
                C:\Documents and Settings\Andrew Rufkahr>addressbook.py
                
                        1) Add Entry
                        2) Remove Entry
                        3) Find Entry
                        4) List Entries
                        5) Quit and save
                
                Select a choice(1-6):
                Now THAT'S weird! It isn't even in the Current directory I'm in!

                But if I try to open something in the Documents and settings it tells me that there is no such file or directory...
                it's not weird. PATHEXT is supposed to be like this. you can just type your script name and it will execute.

                Comment

                Working...