How to run a python command from inside a python script?

1.3k Views Asked by At

I am running windows 7 x64 with python 2.7.6 and I just installed the s3cmd tool following these instructions: s3cmd win7 installation.

The problem is that while I have both the python directory and the python scripts on my path, I can't run s3cmd directly. So, if I fire a cmd and type:

python - it works!

However if I type

s3cmd

or

python s3cmd

they both fail even though my python scripts directory contains the file s3cmd:

In the case of s3cmd the error is s3cmd is not recognized as external command or executable etc... (I am translating here because the error is in a non-english locale). In the case of python s3cmd the error is: python: can't open file 's3cmd': [Errno 2] No such file or directory.

Ideally I'd like to run s3cmd from a python script I am writing and not call it directly from cmd, however I would be happy for any kind of input..!

Thanks.

4

There are 4 best solutions below

2
On

I saw this comment on their site: You can create a batch script to run it by using the %* parameter, example:

@python C:\s3\s3cmd %*

Have you tried it out yet?

0
On

The error messages mean that the script s3cmd isn't on the path.

See this question for details: Adding directory to PATH Environment Variable in Windows

0
On

What happens if you use the full path to s3cmd:

python C:\path to s3\s3cmd

If the path contains whitespace you might need to add Quotes:

python "C:\path to s3\s3cmd"
0
On

This worked for me on Windows 2008 Server:

  • Setup python 2.x - Python 3 is not supported
  • Download s3cmd from www.s3tools.org
  • Add "C:\python2x\" to your global path
  • Add "C:\Python2x\Scripts\" to your global path
  • Run "python setup.py install" from s3cmd path (download path e.g: C:\Users\testuser\Downloads\S3cmd-1.6.0)
  • Rename "C:\Python2x\Scripts\s3cmd" to "C:\Python2x\Scripts\s3cmd.py" (Note: We are renaming "s3cmd" without any extension to "s3cmd.py")
  • Now you should be able to run "s3cmd.py" from anywhere :)