0

I am trying to use a python script that imports a script that imports another script. However, it changes versions of python when doing so, making the syntax invalid. Is there a way to make python use a specific version?

NOTE: I do not have su privileges

Edit 1:

2.7.9 (default, May  2 2016, 17:03:26) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
2.6.6 (r266:84292, Jul 23 2015, 15:22:56) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)]
Traceback (most recent call last):
 File "script.py", line 29, in <module>
  from folder1 import script1
 File "folder/script1.py", line 6, in <module>
  from folder2 import script2
 File "folder2/script2.py", line 234
  covered_isoform_fraction_max = {id_isoform: isoforms_covered_fraction[id_isoform] for id_isoform in ids_isoforms_max}
                                                                                      ^
SyntaxError: invalid syntax
BioFalcon
  • 51
  • 5
  • How does it change the version? Could you provide some text showing what it's importing? – Mangohero1 Oct 19 '16 at 00:31
  • I'm guessing its importing the wrong script from some older version. check you sys.path – tesseract Oct 19 '16 at 00:33
  • I run it like `python2.7 script.py`, i get the message I will put on an edit. To follow the python versions, I put on the script the command `print(sys.version)`. – BioFalcon Oct 19 '16 at 00:38
  • So the error message is pretty clear: there is a syntactical error in your script2.py at the given line. The caret `^` indicates where the Python parser first runs into problems. –  Oct 19 '16 at 00:50
  • 1
    Possible duplicate of [Create a dictionary with list comprehension in Python](http://stackoverflow.com/questions/1747817/create-a-dictionary-with-list-comprehension-in-python) –  Oct 19 '16 at 00:52
  • While the question may not be phrased as such (the title of this question is *completely* misleading), the duplicate question will have the answer to your problem. –  Oct 19 '16 at 00:53
  • Your syntax error has nothing to do with the version of python you are using. It's a syntax error – enderland Oct 19 '16 at 00:54
  • @Evert yes, but it is because python version is changing while importing the different scripts, and I do now know if there is a workaround without su privileges. – BioFalcon Oct 19 '16 at 00:54
  • @Evert it is not just that one line, I did change it earlier, however, there are multiple scripts that do this in general (different sintax errors), and I cannot fix them all since I would have to find all the syntax differences between python 2.7 and 2.6 – BioFalcon Oct 19 '16 at 00:56
  • What's in `script.py` (up to line 29)? –  Oct 19 '16 at 01:09
  • You shouldn't be changing versions of python when importing a script – jamylak Oct 19 '16 at 01:13
  • How about you just change line 234 in `folder2/script2.py` to: `covered_isoform_fraction_max = dict((id_isoform, isoforms_covered_fraction[id_isoform]) for id_isoform in ids_isoforms_max)` and then paste the errors from that, like @Evert suggested. And yes, it IS to do with which python version is being used @enderland. – Eugene Oct 19 '16 at 02:06

0 Answers0