Python 3.7 input() doesnt work but raw_input does

2019-08-17 08:34发布

So classic beginner problem here... Ive been trying to use Python on various text editors like VSCode and Atom and none of them seem to work (After installing python 3.7). If I ask for a simple input the program crashes labelling the input as undefined, but when I use raw_input() it works just fine for some reason. However, raw_input() was changed to input() in Python 3 so why does this keep happening to me?

3条回答
Evening l夕情丶
2楼-- · 2019-08-17 09:08

You need to be using virtual environments. Since you're running on a Mac I would suggest you use the Anaconda distribution of Python. Instructions are here. This simplifies the process of making virtual environments. It's as easy as conda create -n myenv python=3.6 and more detailed instructions are found here. Once conda is installed you can use commands like conda install scipyto install python packages. Once you have virtual environments installed and activated your command should work. Try it in the python 3.6 environment.

查看更多
ら.Afraid
3楼-- · 2019-08-17 09:09

Strange,

I guess something wrong with installation,

Please check what:

import sys
print(sys.version)

Outputs,

and also see what this outputs:

import platform
print(platform.python_version())

And see if this works:

print 'hello'

If it does work, you're on python 2, also see what sys.version and platform.python_version() outputs

查看更多
冷血范
4楼-- · 2019-08-17 09:10

As U9-Forward has mentioned in his answer, similarly...

Check that the installtion of Python 3.7 is correct by entering the follwoing into the Python 3.7 native IDLE Shell (you may have been using the IDLE of an older Python version):

import sys
print(sys.version)

and...

import platform
print(platform.python_version())

If any of this produces an error, you will know if there was a problem with installation.

It's possible that you have multiple versions of Python installed. Check to see what versions you do have installed. If you have other versions besides Python 3.7 uninstall them.
If the problem persists uninstall Python 3.7 and reinstall it.

The problem as you described can occur when one attempt to install a newer version of Python when older version(s) are still installed.

查看更多
登录 后发表回答