[英]Python2.7: What is wrong with this program? It runs but the weird traceback error
[英]Python 2.7 traceback error in sublime. Wrong version of python
我在崇高中得到这个错误。 即使它说的是2.7,我仍以为我安装了3.5.2。 我查看了目录,找不到找不到的文件。
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:
我不知道如何开始调试此错误。
在终端中键入以下命令以查看Python 3.5的位置:
which python3.5
您可能还希望将以下shebang添加到脚本中:
#!/usr/bin/env python3.5
HTH。
您可能尚未将sublime配置为使用python3。您可以使用上述shebang或配置sublime来解决此问题(看起来就像https://forum.sublimetext.com/t/select-which-version- of-python-to-run-build / 1695/8 )。
如果使用MacPorts安装了python3(这就是我所做的),则应注意,它可能不在正常的env搜索路径中。 如果是这样,您可以检查已安装的python3端口以及它们的python可执行文件所在的位置:
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
这应该给你这样的结果:
python34: /opt/local/bin/python3.4
python35: /opt/local/bin/python3.5
然后可以在您的shebang中使用它,例如
#!/opt/local/bin/python3.5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.