不能 运行 python 3.5 和 python 2.7.4 在 Windows 10 中
Cannot run python 3.5 along with python 2.7.4 in Windows 10
我正在尝试安装 Python 3.5.0 和 Python 2.7.4。
C:\Users\Animesh>python
Python 2.7.4 (default, Apr 6 2013, 19:55:15) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\Users\Animesh>py
Python 2.7.4 (default, Apr 6 2013, 19:55:15) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\Users\Animesh>py -2
Python 2.7.4 (default, Apr 6 2013, 19:55:15) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\Users\Animesh>py -3
Fatal Python error: Py_Initialize: unable to load the file system codec
File "E:\Python27\Lib\encodings\__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: invalid syntax
Current thread 0x00003514 (most recent call first):
我尝试了一系列如上所示的命令,但 python 3.5 似乎不起作用。我什至尝试使用 Python 3.5 解释器在 PyCharm 上创建一个项目,但它给出了同样的错误。
我该如何纠正这个错误?
Python 的官方安装程序将在 C:\Program Files\Python 3.5
中安装 3.5。
它会自动将此路径添加到您的 PATH
变量(如果您告诉它)。您似乎没有启用此选项。
在您的 PATH
(不是 PYTHONPATH
)设置中。
您可以转到“设置”应用程序并搜索环境,然后单击 "Edit environment variables for your account" - 这将打开一个属性 window;单击底部的 Environment Variables
加载您帐户的设置。
您需要手动将路径添加到 PATH
变量,并删除 E:\Python2.7
路径。
执行此操作,然后重新启动命令提示符,默认 Python 版本将为 3.5。
对于PyCharm,您可以在设置中添加一个新的本地解释器(CTRL+ALT+S) 并直接指向你安装 Python 3.5.
的位置
由于两个解释器都被命名为 python.exe
,因此将执行在您的 PATH
中找到的第一个解释器。实际上,这意味着 PATH
中的任何内容都是系统的默认 Python。要执行其他版本,您需要明确指向它。
如果您在 E:\Python2.7
中有 Python 2.7 并且在 C:\Program Files\Python 3.5
中有 Python 3.5,请选择您希望成为默认值的那个并在其中添加路径您的 PATH
环境变量 - 您始终可以通过键入 python.exe
文件的完整路径来引用其他安装。
C:\>python.exe # this will launch whatever is found first in your `PATH`
C:\>E:\Python2.7\python.exe # explicitly launch the 2.7 version.
就 PyCharm 而言,它将读取 PATH
并选择默认解释器,您可以通过浏览到它的位置在您的设置中添加另一个。
然后,在创建新项目时,您可以选择要使用的版本。
我正在尝试安装 Python 3.5.0 和 Python 2.7.4。
C:\Users\Animesh>python
Python 2.7.4 (default, Apr 6 2013, 19:55:15) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\Users\Animesh>py
Python 2.7.4 (default, Apr 6 2013, 19:55:15) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\Users\Animesh>py -2
Python 2.7.4 (default, Apr 6 2013, 19:55:15) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
C:\Users\Animesh>py -3
Fatal Python error: Py_Initialize: unable to load the file system codec
File "E:\Python27\Lib\encodings\__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: invalid syntax
Current thread 0x00003514 (most recent call first):
我尝试了一系列如上所示的命令,但 python 3.5 似乎不起作用。我什至尝试使用 Python 3.5 解释器在 PyCharm 上创建一个项目,但它给出了同样的错误。
我该如何纠正这个错误?
Python 的官方安装程序将在 C:\Program Files\Python 3.5
中安装 3.5。
它会自动将此路径添加到您的 PATH
变量(如果您告诉它)。您似乎没有启用此选项。
在您的 PATH
(不是 PYTHONPATH
)设置中。
您可以转到“设置”应用程序并搜索环境,然后单击 "Edit environment variables for your account" - 这将打开一个属性 window;单击底部的 Environment Variables
加载您帐户的设置。
您需要手动将路径添加到 PATH
变量,并删除 E:\Python2.7
路径。
执行此操作,然后重新启动命令提示符,默认 Python 版本将为 3.5。
对于PyCharm,您可以在设置中添加一个新的本地解释器(CTRL+ALT+S) 并直接指向你安装 Python 3.5.
的位置由于两个解释器都被命名为 python.exe
,因此将执行在您的 PATH
中找到的第一个解释器。实际上,这意味着 PATH
中的任何内容都是系统的默认 Python。要执行其他版本,您需要明确指向它。
如果您在 E:\Python2.7
中有 Python 2.7 并且在 C:\Program Files\Python 3.5
中有 Python 3.5,请选择您希望成为默认值的那个并在其中添加路径您的 PATH
环境变量 - 您始终可以通过键入 python.exe
文件的完整路径来引用其他安装。
C:\>python.exe # this will launch whatever is found first in your `PATH`
C:\>E:\Python2.7\python.exe # explicitly launch the 2.7 version.
就 PyCharm 而言,它将读取 PATH
并选择默认解释器,您可以通过浏览到它的位置在您的设置中添加另一个。
然后,在创建新项目时,您可以选择要使用的版本。