[New-bugs-announce] [issue26400] SyntaxError when running Python 2.7 interpreter with subprocess.call

giumas report at bugs.python.org
Sun Feb 21 09:39:43 EST 2016

New submission from giumas:

On Windows, I am getting a `SyntaxError` when I try to input commands after having launched a Python 2.7.x interpreter with `subprocess.call`. 

This is a minimal example: 

    import os
    import subprocess
    def python_env_path(python_path):
        env = os.environ.copy()
        python_scripts = os.path.join(python_path, "Scripts")
        python_bin = os.path.join(python_path, "Library", "bin")
        path_env = "%s;%s;%s;" % (python_path, python_scripts, python_bin)
        env['PATH'] = path_env.encode()
        return env
    def open_python_prompt(python_path):
        env = python_env_path(python_path)
        prc = subprocess.call(["start", "python"],
                              shell=True, cwd=python_path, env=env)
        if prc != 0:
            print("Unable to open a Python prompt")
            return False
        return True

When I try to write whatever simple command for the interpreter I get:

    >>> a = 0
      File "<stdin>", line 1
        a = 0
    SyntaxError: invalid syntax

I did not find SO questions that solve my issue.
The same code works fine with Python 3.x.
The same Python installation works fine if I open a shell and call the interpreter using a batch file.

components: Extension Modules, Windows
messages: 260612
nosy: giumas, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: SyntaxError when running Python 2.7 interpreter with subprocess.call
type: crash
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list