0

Ok, so I'm creating a script on python 3 to do some silent installations.
My problem is that I do not know if the server is going to have python 3 available. Its possible that it has by default python 2 or some Unix Engineer installs python 3.
Now, my question is. Is it possible to run a python 3 script on a python 2?
Should I export the modules I need?

Thanks

radicaled
  • 2,369
  • 5
  • 30
  • 44

2 Answers2

0

Kindof. There is the six module. Its goal is

Six is a Python 2 and 3 compatibility library. It provides utility functions for smoothing over the differences between the Python versions with the goal of writing Python code that is compatible on both Python versions.

It won't do you any good if you need python 3 functionality. Its easy to install python 3 next to python 2 on most systems, so there really isn't much reason to try to struggle with it, though.

tdelaney
  • 73,364
  • 6
  • 83
  • 116
0

I recommend the python-future package for writing code that is compatible with Python 2.7 and Python 3.3+. It is somewhat more convenient than six and allows you to simply write idiomatic Python 3 almost everywhere.

wonce
  • 1,893
  • 12
  • 18