简体   繁体   中英

Python 2.7 traceback error in sublime. Wrong version of python

I'm getting this error in sublime. Even though it says 2.7, I thought I installed 3.5.2. I looked at the directory and can find no files that shouldn't be there.

   Traceback (most recent call last):
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/py_compile.py", line 170, in <module>
    sys.exit(main())
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/py_compile.py", line 162, in main
    compile(filename, doraise=True)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/py_compile.py", line 106, in compile
    with open(file, 'U') as f:

I have no idea how to start debugging this error.

Type the following command in your terminal to see the location of Python 3.5:

which python3.5

You might also want to add the following shebang to your script:

#!/usr/bin/env python3.5

HTH.

You may not have sublime configured to use python 3. You can address this by using the shebang mentioned above, or by configuring sublime (looks like this is how https://forum.sublimetext.com/t/select-which-version-of-python-to-run-build/1695/8 ).

If you installed python3 using MacPorts (that is what I did), then you should note that it may not be in the normal env search paths. If so, you can check which python3 ports you have installed and where their python executable is with:

port echo python3* and active and not python3_select | cut -d' ' -f1 | while read pn; do echo "$pn: $(port contents $pn | grep -E '/opt/local/bin/python.*[0-9]$')"; done

And this should give you a result like:

python34:   /opt/local/bin/python3.4
python35:   /opt/local/bin/python3.5

Which you can then use in your shebang like

#!/opt/local/bin/python3.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM