python - pycharm python3 输入错误

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

enter image description here我有这个测试代码:

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) 

打印运行时版本

最佳答案

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

关于python - pycharm python3 输入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41927778/

相关文章:

Python请求模块没有从响应中获取cookie

python - Django - 每个模板中的通用数据

python - 属性错误: 'WindowsPath' object has no attribute 'endswith'

python - 下载带有依赖的python包,无需安装

Python多线程不是并行执行的

python - 如何在 PyQt5 InputDialog 中获得更多输入文本?

python - 如何使用 Panda 中的第一列保存结果

python - Richardson–Lucy 算法是如何工作的?代码示例?

python - 用另一个数据框 pandas 的第一个值填充 0 和 1 系列的数据框

python - 类型错误 : data type not understood in Python fromfile