2017-01-30 107 views
1

enter image description here我有这样的测试代码:pycharm python3错误

inputs = list(map(int, input().split())) 
print(n) 
print(inputs) 

当我在下面的控制台输入3 4;我收到以下错误:

Traceback (most recent call last): 
    File "/Users/Labhesh/PycharmProjects/algotoolbox/assignment1/test.py", line 2, in <module> 
    inputs = list(map(int, input().split())) 
    File "<string>", line 1 
    3 4 
    ^
SyntaxError: unexpected EOF while parsing 

Process finished with exit code 1 

当我运行命令行相同的代码,没有任何问题:

>> python3 test.py 
>> 3 4 
>> [3, 4] 

是有一些特殊的设置我必须做的,使这个简单的代码工作在PyCharm?

编辑

看来,在pycharm项目解释是不一样的运行配置。 要设置运行配置 - 使用运行 - >编辑配置,然后选择python解释器。

你也可以做

import sys 
print(sys.version) 

打印的运行时版本

回答

1

看来,PyCharm可以使用Python的2.X版本。

当PyCharm使用python 3.5运行:

"C:\Program Files (x86)\Python35-32\python.exe" "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59807 --file C:/src/testcode/test.py 
pydev debugger: process 12684 is connecting 

Connected to pydev debugger (build 163.10154.50) 
3 4 
[3, 4] 

Process finished with exit code 0 

当PyCharm使用Python 2.7运行:

C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59813 --file C:/src/testcode/test.py 
pydev debugger: process 16920 is connecting 

QSslSocket: cannot resolve SSLv2_client_method 
QSslSocket: cannot resolve SSLv2_server_method 
Connected to pydev debugger (build 163.10154.50) 
3 4 
Traceback (most recent call last): 
    File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 1596, in <module> 
    globals = debugger.run(setup['file'], None, None, is_module) 
    File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 974, in run 
    pydev_imports.execfile(file, globals, locals) # execute the script 
    File "C:/src/testcode/test.py", line 13, in <module> 
    inputs = list(map(int, input().split())) 
    File "<string>", line 1 
    3 4 
    ^
SyntaxError: unexpected EOF while parsing 
+0

看到我刚才添加的截图(我原来的职位),项目解释器是3.5 – labheshr

+0

项目解释器不一定与运行时相同。 EG:看看我发布的内容,它来自同一个项目。 –

+0

你是正确的,打印(sys.version)给我2.6.6。如何将运行时设置为3.5? – labheshr