简体   繁体   中英

pycharm python3 error on input

在此处输入图片说明 I have this test code:

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

When I input 3 4 in the console below; I get the following error:

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

When I run the same code from command line, there are no issues:

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

Is there some special setting I have to do to make this simple code work in PyCharm?

EDIT

It seems that in pycharm project interpreter is not the same as run configuration. To set Run configuration - use Run --> Edit Configuration and then choose the python interpreter.

You can also do

import sys
print(sys.version) 

to print the runtime version

It appears that PyCharm may be using a 2.x version of Python.

When run using python 3.5 in PyCharm:

"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

When run using Python 2.7 in PyCharm:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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