简体   繁体   English

PyDev不适用于Python 3.2

[英]PyDev doesn't work with Python 3.2

I want to make my first steps in Python 3, so I have installed Eclipse 4.3.1 and install the latest version of the PyDev Plugin. 我想使用Python 3迈出第一步,所以我已经安装了Eclipse 4.3.1并安装了最新版本的PyDev插件。 I have created two configurations for Python 2.7 and Python 3.2 (both versions are installed on my machine). 我为Python 2.7和Python 3.2创建了两个配置(这两个版本都安装在我的计算机上)。 I can run and debug my test program using Python 2.7 but I can only run my program using Python 3.2. 我可以使用Python 2.7运行和调试测试程序,但只能使用Python 3.2运行程序。 If I want to debug my program, I get an error message saying "Unexpected error setting up the debugger Socket closed". 如果要调试程序,则会收到一条错误消息,提示“关闭调试器套接字时发生意外错误”。 In the console I get 在控制台中,我得到

File "/home/he/PyDev/plugins/org.python.pydev_3.2.0.201312292215/pysrc/pydevd.py", line 914
    if text.startswith(u'REPLACE:'):
                                 ^
SyntaxError: invalid syntax

The test program is: 测试程序为:

#!/usr/bin/env python3
print("Hello, World!")

How can I fix this? 我怎样才能解决这个问题? I am using Ubuntu 12.04. 我正在使用Ubuntu 12.04。

Python 3.0 ~ 3.2 does not support explicit unicode literal ( u'....' ). Python 3.0〜3.2不支持显式unicode文字( u'....' )。

Unicode literal is supported in Python 2.x, Python 3.3+. Python 2.x,Python 3.3+支持Unicode文字。 (See PEP 414 -- Explicit Unicode Literal for Python 3.3 ) (请参阅PEP 414-Python 3.3的显式Unicode文字


To make it run in Python 3.2, replace following line: 要使其在Python 3.2中运行,请替换以下行:

if text.startswith(u'REPLACE:'):

with: 有:

if text.startswith('REPLACE:'):

By replacing the code as above, in Python 2.7, the literal 'REPLACE:' denotes byte string. 通过替换上面的代码,在Python 2.7中,文字'REPLACE:'表示字节字符串。 If you want 'REPLACE:' work as unicode string like in Python 3.x, you can use __future__ . 如果希望像Python 3.x一样将'REPLACE:'作为Unicode字符串使用,则可以使用__future__

Add following line at the top of the source code: 在源代码顶部添加以下行:

from __future__ import unicode_literals

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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