473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

21
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?
Mar 27 '07 #1
21 2478
bartonc
6,596 Expert 4TB
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:\python25;" is in the PATH variable. That should do it.
Mar 27 '07 #2
St33med
21
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.
Apr 2 '07 #3
ghostdog74
511 Expert 256MB
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
Apr 2 '07 #4
St33med
21
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\addressbook.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\addressbook.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!
Apr 2 '07 #5
bartonc
6,596 Expert 4TB
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\addressbook.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\addressbook.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.
Apr 2 '07 #6
St33med
21
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.
Apr 2 '07 #7
bartonc
6,596 Expert 4TB
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\Lib\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...
Apr 2 '07 #8
ghostdog74
511 Expert 256MB
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\addressbook.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\addressbook.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.
Apr 2 '07 #9
bartonc
6,596 Expert 4TB
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:
<snip>I want to get rid of the whole entire path being written out!
Apr 3 '07 #10
ghostdog74
511 Expert 256MB
site-packages is where almost all things that you add to python will be stored.
On my system it's "D:\Python24\Lib\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\somesubdir , right?
Here's an example of what I interpreted, I am calling os.py ( the os module) from , say C:\ drive

Expand|Select|Wrap|Line Numbers
  1. c:\Python24\Lib> python os.py <--- runs without error, because we are in actual directory where os.py is
  2.  
  3. c:\Python24\Lib> cd \
  4.  
  5. c:\>python os.py  <-- change to C:\ drive,
  6. python: can't open file 'os.py': [Errno 2] No such file or directory
  7.  
Is this what OP is trying to do?
Apr 3 '07 #11
St33med
21
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?
Apr 3 '07 #12
ghostdog74
511 Expert 256MB
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.
Apr 3 '07 #13
bartonc
6,596 Expert 4TB
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.
Apr 3 '07 #14
ghostdog74
511 Expert 256MB
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:
Expand|Select|Wrap|Line Numbers
  1. #.pth file for PyWin32 extensions
  2. win32
  3. win32\lib
  4. Pythonwin
  5.  
This is my environment. Opening an interactive prompt, I type
Expand|Select|Wrap|Line Numbers
  1. >>> import win32com.client.connect
  2. >>>
  3.  
and this works as supposed to be. Now, if I were to call up connect.py from the command line at c:\> drive,

Expand|Select|Wrap|Line Numbers
  1. c:\> python connect.py
  2. python: can't open 'connect.py': [Errno 2] No such file or directory
  3.  
even though pywin32.pth is there in site-packages. Am i doing this correctly?
Apr 3 '07 #15
bartonc
6,596 Expert 4TB
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:
Expand|Select|Wrap|Line Numbers
  1. #.pth file for PyWin32 extensions
  2. win32
  3. win32\lib
  4. Pythonwin
  5.  
This is my environment. Opening an interactive prompt, I type
Expand|Select|Wrap|Line Numbers
  1. >>> import win32com.client.connect
  2. >>>
  3.  
and this works as supposed to be. Now, if I were to call up connect.py from the command line at c:\> drive,

Expand|Select|Wrap|Line Numbers
  1. c:\> python connect.py
  2. python: can't open 'connect.py': [Errno 2] No such file or directory
  3.  
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.
Apr 3 '07 #16
ghostdog74
511 Expert 256MB
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
Expand|Select|Wrap|Line Numbers
  1. c:\> set PYTHONPATH=d:\script
  2. c:\> echo %PYTHONPATH%
  3. d:\script
  4. c:\> python myscript.py
  5. python: can't open file 'myscript.py': [Errno 2] No such file or directory
  6.  
Apr 3 '07 #17
bartonc
6,596 Expert 4TB
well, even if PYTHONPATH set , it's still not working. PYTHONPATH is also used for imports. my script is in d:\> drive
Expand|Select|Wrap|Line Numbers
  1. c:\> set PYTHONPATH=d:\script
  2. c:\> echo %PYTHONPATH%
  3. d:\script
  4. c:\> python myscript.py
  5. python: can't open file 'myscript.py': [Errno 2] No such file or directory
  6.  
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.
Apr 3 '07 #18
bartonc
6,596 Expert 4TB
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.
Apr 3 '07 #19
St33med
21
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...
Apr 3 '07 #20
St33med
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...
Expand|Select|Wrap|Line Numbers
  1. C:\Documents and Settings\Andrew Rufkahr>addressbook.py
  2.  
  3.         1) Add Entry
  4.         2) Remove Entry
  5.         3) Find Entry
  6.         4) List Entries
  7.         5) Quit and save
  8.  
  9. 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...
Apr 3 '07 #21
ghostdog74
511 Expert 256MB
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...
Expand|Select|Wrap|Line Numbers
  1. C:\Documents and Settings\Andrew Rufkahr>addressbook.py
  2.  
  3.         1) Add Entry
  4.         2) Remove Entry
  5.         3) Find Entry
  6.         4) List Entries
  7.         5) Quit and save
  8.  
  9. 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.
Apr 4 '07 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Richard Shea | last post by:
Hi - Is there a tool available which given a set of PHP scripts will analyse them and show you which function is called by which other function ? I'm looking for something which would allow me to...
4
by: George Hester | last post by:
So what's this? a is a ASP page. Clicking on a link there goes to the b ASP page. Clicking a link on that goes to the c ASP page. The idea here is to keep the visited attribute throughout the...
4
by: Mark | last post by:
I have a COM object that calls into a C# Forms library. The library can throw exceptions and I want to handle the exceptions in COM. Adam Nathan wrote a Microsoft sponsored book titled .Net and Com...
2
by: Marco Ippolito | last post by:
Hi guys, what options are there to use, for example, a string stored in the Session context by an ASP.NET page, from within, say, a PHP script? Thanks! - Marco
2
by: Magnus Blomberg | last post by:
Hello! I am trying to write a simple aspx page with You are logged on as <% getuser(); %> in the body text. In my code-behind I write (for test: public String getuser() { String s =...
16
by: kerberoz | last post by:
which is faster? If strMessage <> String.Empty Then End If or If Not strMessage Is Nothing Then
8
by: davihigh | last post by:
My Friends: I am using std::ofstream (as well as ifstream), I hope that when i wrote in some std::string(...) with locale, ofstream can convert to UTF-8 encoding and save file to disk. So does...
0
by: Anton | last post by:
Hi All, I would like to be able to check whether there are any remaining plain text variables left in a word document after it has been built based on a template. At this stage, I roll through a...
13
by: Sebastian Faust | last post by:
Hi, I hava a somehow strange problem. I hope I am not wrong in this group; if this is the case please let me know. I am trying to compile a rather simple C program. As long as I use: #include...
56
by: Zytan | last post by:
Obviously you can't just use a simple for loop, since you may skip over elements. You could modify the loop counter each time an element is deleted. But, the loop ending condition must be...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.