1

I'm trying to launch a simple server from a Python script:

    server = Popen(['python' ,'-m', 'SimpleHTTPServer', '9090'], stderr=STDOUT, stdout=PIPE)
    output = server.communicate()[0]  # <- DEBUG

Reading the output, I see:

'/usr/bin/python: Import by filename is not supported.'

What's the problem? How to solve it?

7
  • Works fine for me. Make it log to the screen directly. Let's see what it says. Also, don't import Popen and the rest of subprocess into your current namespace. Commented Jun 1, 2012 at 13:00
  • can't log to the screen as it is withing a library and it's not a console application. Commented Jun 1, 2012 at 13:02
  • I tested your code on windows and it works fine. Commented Jun 1, 2012 at 13:18
  • 3
    +1 to Noufal - my guess is that it's environmental - the "python" being invoked by Popen ('/usr/bin/python' based on the output) might be a different version, but one of the PYTHON...PATH environment variables might be pointing somewhere else... Commented Jun 1, 2012 at 13:49
  • 2
    Try sys.executable instead of 'python'. Commented Jun 1, 2012 at 14:03

1 Answer 1

1

I suggest change to code to this:

import SimpleHTTPServer
import SocketServer

PORT = 9090

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "serving at port", PORT
httpd.serve_forever()
Sign up to request clarification or add additional context in comments.

1 Comment

This has the decided disadvantage that the script cannot perform other tasks while the server runs in the background.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.