安装了Python 3,运行时出错 [英] Python 3 installed, error when running

查看:52
本文介绍了安装了Python 3,运行时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Mac 上安装了 Python 3.5.1安装了 Python 2.7.10.当我运行 python --version 时,它返回 Python 2.7.10,当我运行 python3 --version 时,它返回 Python 3.5.1,这应该确认正确安装了 Python 3.但是,每当我尝试在 终端 中使用 python3 运行命令或文件时,都会出现以下错误:

I installed Python 3.5.1 on my Mac, alongside Python 2.7.10. When I run python --version, it returns Python 2.7.10, and when I run python3 --version, it returns Python 3.5.1, which should confirm that Python 3 correctly installed. However, whenever I try to run a command or file with python3 in Terminal, it gives me this error:

Python 致命错误:Py_Initialize:无法加载文件系统编解码器文件"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/init.py",第 123 行引发 CodecRegistryError,\^ 语法错误:无效语法

Fatal Python error: Py_Initialize: unable to load the file system codec File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/init.py", line 123 raise CodecRegistryError,\ ^ SyntaxError: invalid syntax

当前线程 0x00007fff72bb4000(最近调用优先):Abort陷阱:6 Farshids-MacBook-Pro-2:mysite Sasha$ python3 Fatal Python错误:Py_Initialize:无法加载文件系统编解码器文件"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/init.py",第 123 行引发 CodecRegistryError,\^ 语法错误:无效语法

Current thread 0x00007fff72bb4000 (most recent call first): Abort trap: 6 Farshids-MacBook-Pro-2:mysite Sasha$ python3 Fatal Python error: Py_Initialize: unable to load the file system codec File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/init.py", line 123 raise CodecRegistryError,\ ^ SyntaxError: invalid syntax

当前线程 0x00007fff72bb4000(最近调用优先):Abort陷阱:6

Current thread 0x00007fff72bb4000 (most recent call first): Abort trap: 6

并且还弹出一条消息说Python意外退出." 正如您在错误中看到的那样,它提到了2.7,这意味着它可能试图使用2.7运行代码.

and also pops up with a message saying "Python quit unexpectedly." As you can see in the error, it mentions 2.7, which means that it was probably trying to run the code using 2.7.

我该如何解决这个问题?顺便说一句,我安装了 Python 3 以遵循 Django 教程,该教程在没有 Python 3 的情况下无法运行,而且我对 Python 非常了解,因此能够进行调整.

How do I fix this? By the way, I installed Python 3 to follow a Django tutorial that does not work without Python 3, and I'm so knowledgeable about Python to be able to adjust.

推荐答案

很可能 $PYTHONPATH 设置为使用您的 Python2.x.验证此类型

Most probably $PYTHONPATH is set to use your Python2.x. To verify this type

echo $PYTHONPATH

如果您看到与 Python2.x 相关的路径,请尝试取消设置.

If you see path related to Python2.x, try unsetting it.

unset PYTHONPATH

这篇关于安装了Python 3,运行时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆