1

I want to run a python script using the terminal in macOS.

$ python main.py

I would like to have the option of switching between python 2.7 and 3.6 versions. I have installed both the versions using homebrew. When I run the above command, it runs using Python 3.6 by default, but i need to run using 2.7. How can I do it?

Thanks, Vinil

  • Hi, The answer mentioned in that question uses Python2 as an alias to run the script. In my case, 'command not found' error is coming if I use 'python2 main.py' in terminal. please help. – Vinil Thombrey Jul 16 '18 at 15:32
  • what does `which python` give you? – wkzhu Jul 16 '18 at 15:33
  • The version of Python 2.7 that Apple pre-installs doesn’t quite follow the recommendations for distros. It includes the optional `python2.7` alias, but doesn’t include the required `python2` alias. So, either you make your own symlink or bash alias or whatever, or you use `python2.7` to run it. – abarnert Jul 16 '18 at 15:46

1 Answers1

0

I use python main.py for python 2, and python3 main.py for python 3.

You should see the environment variables in your PATH file to resolve any problems.

Also, you can create a virtualenv with -p python3 parameters.

Gabriel Panza
  • 309
  • 2
  • 10