Python not showing up in Command Prompt after first input

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Python not showing up in Command Prompt after first input



I'm currently trying to install a package on python that can only be installed on Python 3. I have both 3.6 and 2.7. I'm on a Windows machine. Whenever I type "python" into a newly opened command prompt it returns python 2.7. Then whenever I type "python" it says


Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined



I believe python 3.6 is set as an environment variable on my path. Can someone offer some advice on how to switch these over? I've read py.exe from python 3's installion should switch between python 2 and 3, but I do not see how I am supposed to run that command other than clicking on it in my File Explorer and that does nothing.





Are you saying that you are typing the command "python" into the python REPL?
– Paul Rooney
Aug 8 at 4:18






And if that's what you're doing, why are you doing it? What do you expect to happen?
– Chris
Aug 8 at 4:23




2 Answers
2



You type python in python repl


Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined



You should open a new command prompt or type ctrl+Z or quit() in the python repl



For switching python 2 and 3



Use


py -3
py -2



Once you type in python, you go into Python's interpreter mode, where you can type Python code and get the result. You can type quit to leave that mode. If you want to run a script, you need to run, instead of just python, python filename.py, with the appropriate filename.


python


quit


python


python filename.py



But you want to do that outside of the interpreter mode (otherwise known as REPL).



Note that the above will probably cause Python 2.X to be used to run your script, so if you want to run Python 3.X you will want to include this at the top of your script


#!/usr/bin/env python3



and then just run it from a newly opened command prompt (or any command prompt that is not in Python's interpreter mode) like filename.py.


filename.py



See this question for more information.





/usr/bin/env python3 may not work on windows
– James Liu
Aug 8 at 4:42






Great! That makes a ton of sense. So that works for me just fine. When I try to install the package with pip I get this error pip install tensorflow File "<stdin>", line 1 pip install tensorflow
– Mrl
Aug 8 at 4:42



pip install tensorflow File "<stdin>", line 1 pip install tensorflow





@JamesLiu it should!
– Bruno Ely
Aug 8 at 4:45





@Mrl same thing with the pip commands, try using them from the command prompt rather than the Python interpreter!
– Bruno Ely
Aug 8 at 4:46


pip





@Mrl Don't use pip in python, use it in the command prompt
– James Liu
Aug 8 at 4:47






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered