0

I am trying to launch a python 2.7 script called pp.py from a Python 3.6 script.

I am working on Windows 7

This is the 2.7 script:

#! C:\Python27\python.exe

import sys

sys.stdout.write("Hello from version %s\n" % (sys.version,))

If I launch it from the cmd window, it will return that it is using the 2.7 version, but if I call it from the 3.6 script with this instruction:

exec(open("pp.py").read())

then it will answer that it is using Python 3.6

Any ideas?

Stamos
  • 3,938
  • 1
  • 22
  • 48

1 Answers1

0

Python exec executes a string of code in the current version. I think you'll have to run a new process using the python version you want. If you need to read return values, use the Pipes, as described here

Follow the step here, and you'll have a distinction between python 2 and 3 (or use aliases in linux).

Then, you can use the Process class to to run your script.

OVi
  • 21
  • 6