I have a python file but when I attempt to run it on my command line it wants to run it using Python 2.
I have #!/usr/bin/env python3 as the first line of code but it still wants to run it using Python 2.  If it helps I'm on OSX.
            Asked
            
        
        
            Active
            
        
            Viewed 494 times
        
    1
            
            
         
    
    
        card100
        
- 76
- 1
- 7
- 
                    1try "python3" as command, worked for me a while ago – Banana Feb 07 '18 at 06:07
- 
                    1Use _python3_ command to run file using python3. – PyMaster Feb 07 '18 at 06:07
- 
                    1how do you run this program? – Sush Feb 07 '18 at 06:08
- 
                    How are you invoking the command? – Stephen Rauch Feb 07 '18 at 06:08
- 
                    I was running it as `python filename.py` – card100 Feb 07 '18 at 06:10
- 
                    1Run `which python3` and then put that path on the shebang line, or just use `python3 filename.py` – cs95 Feb 07 '18 at 06:10
- 
                    https://docs.python.org/3/tutorial/interpreter.html – whackamadoodle3000 Feb 07 '18 at 06:11
- 
                    Great! `python3` worked. – card100 Feb 07 '18 at 06:11
1 Answers
1
            Either,
- Use - python3 filename.py, or
- Create an alias. Add - alias python=python3in- ~/.bash_profile, run- source ~/.bash_profile, and then- python filename.pyshould invoke python3, or
- Run - which python3, copy the path and add it at the top of your script as the shebang line. For me, the command returns- /Library/Frameworks/Python.framework/Versions/3.4/bin/python3. It may be different for you, or
- You can also use - pyenv, which supports multiple python environments simultaneously.
 
    
    
        cs95
        
- 379,657
- 97
- 704
- 746