I've been learning Python using version 3.4. I recently started learning Web.py so have been using Python 2.7 for that, since web.py not supported in Python 3.4. I have nose 1.3.4 module installed for both Python 3.4 and 2.7. I need to run the nosetests command on some Python code written in 2.7 that uses the Web.py module. However, when I type nosetests command it automatically uses Python 3.4, so is throwing an error as unable to import the Web.py module in my Python code. Is there a way to force nosetests to use Python 2.7? Macbook Pro running OS X Yosemite.
Asked
Active
Viewed 2,849 times
6
-
Well, it is most likely calling /usr/bin/python which is pointing to 3.4, so just change the link to point at 2.7. – Tymoteusz Paul Oct 27 '14 at 00:56
-
sorry for sounding dumb but I'm relatively new to programing. Can you specify what you mean. How do I change the link? – diggers Oct 27 '14 at 00:59
-
I could but I won't! Instead I will point you to read up about symlinks, and how to switch python versions on OS X somewhere in depths of google. – Tymoteusz Paul Oct 27 '14 at 01:00
-
Puciek's guidance is good, but you probably don't want to change your global python version every time you switch projects. Instead, use a separate [virtualenv](http://virtualenv.readthedocs.org/en/latest/virtualenv.html) for each project. – Ryne Everett Oct 27 '14 at 01:16
-
1I guessed that a virtualenv is the correct approach. But, reverting to my original question, is there a terminal command to to force it to run the nosetests in Python 2.7, instead of 3.4? – diggers Oct 27 '14 at 01:21
-
4Try `python2.7 -m nose` instead of running `nosetests`. – dano Oct 27 '14 at 02:32
-
That worked! Thank you! Can you explain how that works? What does the -m do? – diggers Oct 27 '14 at 03:11
-
Was hoping to use this same mechanism to do a 2.6 sanity check since I have a dev 2.7 but a jenkin 2.6 right now. No luck though; `/usr/bin/python2.6: nose is a package and cannot be directly executed` – kiminoa May 21 '15 at 18:31