1

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.

card100
  • 76
  • 1
  • 7

1 Answers1

1

Either,

  1. Use python3 filename.py, or

  2. Create an alias. Add alias python=python3 in ~/.bash_profile, run source ~/.bash_profile, and then python filename.py should invoke python3, or

  3. 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

  4. You can also use pyenv, which supports multiple python environments simultaneously.

cs95
  • 379,657
  • 97
  • 704
  • 746