【问题标题】:pycharm python3 error on inputpycharm python3输入错误
【发布时间】:2017-01-30 01:11:27
【问题描述】:

我有这个测试代码:

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) 

打印运行时版本

【问题讨论】:

    标签: python python-2.7 python-3.x input pycharm


    【解决方案1】:

    看来 PyCharm 可能使用的是 2.x 版本的 Python。

    在 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
    

    【讨论】:

    • 看我刚刚添加的截图(到我的原帖),项目解释器是3.5
    • 项目解释器不一定与运行时相同。 EG:看看我发布的内容,它来自同一个项目。
    • 你是对的,print(sys.version) 给了我 2.6.6。如何将运行时设置为 3.5?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    相关资源
    最近更新 更多