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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • St33med
    New Member
    • Mar 2007
    • 21

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

    Somehow, when I first installed Python 2.5, it wouldn't let me run. I looked up what to do with the environment variables, and it got fixed... Sorta...

    Then when I wanted to run a program off of command prompt, it wouldn't run, giving me an error that said that so and so is not an executable. Now I tried to do this, it screwed up my thing!

    Any help?
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by St33med
    Somehow, when I first installed Python 2.5, it wouldn't let me run. I looked up what to do with the environment variables, and it got fixed... Sorta...

    Then when I wanted to run a program off of command prompt, it wouldn't run, giving me an error that said that so and so is not an executable. Now I tried to do this, it screwed up my thing!

    Any help?
    Right click My Computer. Go to Properties: Advanced tab. Click Environment Varialbles button (at the bottom). In User Variables for Your Name, make sure that someting like "D:\python2 5;" is in the PATH variable. That should do it.

    Comment

    • St33med
      New Member
      • Mar 2007
      • 21

      #3
      Well that worked... After I had to revert to a System Restore to go back before I changed ANYTHING to the Environment Variables, then I had to update a few programs... just a mess...

      Anyway, now that I have python working, how do I get the programs to run in it?

      Something about PATHEXT, I'm sure. But I don't know how to label it.

      Comment

      • ghostdog74
        Recognized Expert Contributor
        • Apr 2006
        • 511

        #4
        Originally posted by St33med
        Well that worked... After I had to revert to a System Restore to go back before I changed ANYTHING to the Environment Variables, then I had to update a few programs... just a mess...

        Anyway, now that I have python working, how do I get the programs to run in it?

        Something about PATHEXT, I'm sure. But I don't know how to label it.
        to get your script to run, just type
        c:\> python file.py

        Comment

        • St33med
          New Member
          • Mar 2007
          • 21

          #5
          Originally posted by ghostdog74
          to get your script to run, just type
          c:\> python file.py
          No, no. I said the wrong thing. What I meant to say is that if I want to open a file like what you told me, I have to put the whole entire file's path, because, if I don't, it will tell me that there is no such file or directory.

          Example: python C:\Python25\add ressbook.py

          But if I try to open something that resides in the Documents and Settings, it won't accept it because of the spaces in documents and settings.

          Example: python C:\Documents and Settings\addres sbook.py
          python: can't open file 'C:\Documents': [Errno 2] No such file or directory.

          But if I enclose the whole thing in quotes, it works... I want to get rid of the whole entire path being written out!

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by St33med
            No, no. I said the wrong thing. What I meant to say is that if I want to open a file like what you told me, I have to put the whole entire file's path, because, if I don't, it will tell me that there is no such file or directory.

            Example: python C:\Python25\add ressbook.py

            But if I try to open something that resides in the Documents and Settings, it won't accept it because of the spaces in documents and settings.

            Example: python C:\Documents and Settings\addres sbook.py
            python: can't open file 'C:\Documents': [Errno 2] No such file or directory.

            But if I enclose the whole thing in quotes, it works... I want to get rid of the whole entire path being written out!
            There are three ways to tell python where your files may be found:
            the PYTHONPATH environment variable
            sys.path
            .pth files
            The easiest thing is to add a .pth file to the site-packages directory with the path of your working directory.

            Comment

            • St33med
              New Member
              • Mar 2007
              • 21

              #7
              Originally posted by bartonc
              There are three ways to tell python where your files may be found:
              the PYTHONPATH environment variable
              sys.path
              .pth files
              The easiest thing is to add a .pth file to the site-packages directory with the path of your working directory.
              I'm sorry, I don't understand what you mean... what site-packages directory? What is in the .pth file? Are you talking about Linux, because I'm on Windows.

              Comment

              • bartonc
                Recognized Expert Expert
                • Sep 2006
                • 6478

                #8
                Originally posted by St33med
                I'm sorry, I don't understand what you mean... what site-packages directory? What is in the .pth file? Are you talking about Linux, because I'm on Windows.
                site-packages is where almost all things that you add to python will be stored.
                On my system it's "D:\Python24\Li b\site-packages". Yours may be slightly different.

                In that folder, make a text file with paths in it that you want python to search every time you call python from the command-line or do an import. ie

                MyPathFile.pth
                C:\My Documents\etc.. .

                Comment

                • ghostdog74
                  Recognized Expert Contributor
                  • Apr 2006
                  • 511

                  #9
                  Originally posted by St33med
                  No, no. I said the wrong thing. What I meant to say is that if I want to open a file like what you told me, I have to put the whole entire file's path, because, if I don't, it will tell me that there is no such file or directory.

                  Example: python C:\Python25\add ressbook.py

                  But if I try to open something that resides in the Documents and Settings, it won't accept it because of the spaces in documents and settings.

                  Example: python C:\Documents and Settings\addres sbook.py
                  python: can't open file 'C:\Documents': [Errno 2] No such file or directory.

                  But if I enclose the whole thing in quotes, it works... I want to get rid of the whole entire path being written out!
                  it has to do with the OS shell, not Python. The OS will not know where your addressbook.py is found unless you provide the path. Putting double quotes around file paths with spaces is the correct thing to do in windows command prompt.

                  Comment

                  • bartonc
                    Recognized Expert Expert
                    • Sep 2006
                    • 6478

                    #10
                    Originally posted by ghostdog74
                    it has to do with the OS shell, not Python. The OS will not know where your addressbook.py is found unless you provide the path. Putting double quotes around file paths with spaces is the correct thing to do in windows command prompt.
                    I think that I had it right:
                    Originally posted by St33med
                    <snip>I want to get rid of the whole entire path being written out!

                    Comment

                    • ghostdog74
                      Recognized Expert Contributor
                      • Apr 2006
                      • 511

                      #11
                      Originally posted by bartonc
                      site-packages is where almost all things that you add to python will be stored.
                      On my system it's "D:\Python24\Li b\site-packages". Yours may be slightly different.

                      In that folder, make a text file with paths in it that you want python to search every time you call python from the command-line or do an import. ie

                      MyPathFile.pth
                      C:\My Documents\etc.. .
                      sorry quite confused on OP's requirement now. If i understand correctly, OP doesn't want to type in the full path name of his script such that he can just type
                      c:\> python myscript.py
                      while his myscript.py is stored in say, C:\somedir\some subdir , right?
                      Here's an example of what I interpreted, I am calling os.py ( the os module) from , say C:\ drive

                      Code:
                      c:\Python24\Lib> python os.py <--- runs without error, because we are in actual directory where os.py is
                      
                      c:\Python24\Lib> cd \
                      
                      c:\>python os.py  <-- change to C:\ drive,
                      python: can't open file 'os.py': [Errno 2] No such file or directory
                      Is this what OP is trying to do?

                      Comment

                      • St33med
                        New Member
                        • Mar 2007
                        • 21

                        #12
                        Yes, that is what I'm trying to do. I'm trying to have command prompt be able to go to the file I specify for python, but without the entire path being written out (unless necessary for two files that have the same name...

                        Can you guys do that without the path? Or do you have to put in the entire path?

                        Comment

                        • ghostdog74
                          Recognized Expert Contributor
                          • Apr 2006
                          • 511

                          #13
                          Originally posted by St33med
                          Yes, that is what I'm trying to do. I'm trying to have command prompt be able to go to the file I specify for python, but without the entire path being written out (unless necessary for two files that have the same name...

                          Can you guys do that without the path? Or do you have to put in the entire path?
                          Not that i know of , AFAIK.
                          there's no harm trying the .pth method as descibed though, and see if you can get the results you want.

                          Comment

                          • bartonc
                            Recognized Expert Expert
                            • Sep 2006
                            • 6478

                            #14
                            Originally posted by St33med
                            Yes, that is what I'm trying to do. I'm trying to have command prompt be able to go to the file I specify for python, but without the entire path being written out (unless necessary for two files that have the same name...

                            Can you guys do that without the path? Or do you have to put in the entire path?
                            Yes. See reply #8.

                            Comment

                            • ghostdog74
                              Recognized Expert Contributor
                              • Apr 2006
                              • 511

                              #15
                              Originally posted by bartonc
                              Yes. See reply #8.
                              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?

                              Comment

                              Working...