• How to editing .bashrc so that the terminal uses python2.7 instead of python 3?


    I am trying to use the nosetests but I’m getting errors about print not having parentheses.
    I noticed that after the update Antergos from 3.12 to 3.14 python 3 became default. To run python scripts syntactically written in python 2.7 I would just invoke python2.7(e.g. $ python2.7 script.py). However I am learning how to create project skeletons and using different tools like python nose, virtualenv, etc and the exercises are done in python2.7.

    I don’t want to change the default python to 2.7 as this might break something on my system. After doing some research I read that adding a path to .bashrc is a safer way to tell the terminal to use python2.7 instead of 3.4. I added the following to .bashrc:

    export PATH=/usr/bin/python2.7:$PATH

    but nothing has changed unfortunately. I still get the same error message.

    What am I doing wrong?

    Thanks in advance.

  • @groudie You could use python 3 by just using the python command, python 2.7 is python2.

    example for python 2.7
    python2 script.py

    example for python 3.4:
    python script.py

    gmail: [email protected]
    irc: [email protected]

  • @herbie He can use python 3 or 2 by just calling the script with python (for python 3) or python2, or access the interpreter the same way just without a script location after the command.

    gmail: [email protected]
    irc: [email protected]

  • Not to be a smart-ass but isn’t the operative word here ‘should’.
    I just Googled and found that page and thought it might help… Guess not.
    Learn something new everyday… lol

  • @herbie said:

    Not to be a smart-ass but isn’t the operative word here ‘should’.
    I just Googled and found that page and thought it might help… Guess not.
    Learn something new everyday… lol

    Unless he uninstalled python or python2 package he CAN. I’ll edit that for you. ;)

    Edit:
    More information here.

    https://wiki.archlinux.org/index.php/python

    gmail: [email protected]
    irc: [email protected]

  • I would assume, and that is dangerous, that he didn’t. Can’t think of a reason why to uninstall so it would appear he is good to go on your recommendation.

  • @herbie And i wasn’t dismissing your information, plenty of useful information on that page. From what i understood i though he was just over complicating it because didn’t know he could just call a script with the python2 command or python (python3).

    gmail: [email protected]
    irc: [email protected]

  • Sometimes overthinking is our worst enemy.

  • @herbie @detrimental Thank for the help guys. I did try to invoke python2.7 in the terminal, which works for running “normal” scripts however it doesn’t work for the nosetests command. I did however edit bashrc and added the line alias python=python2.7 . When I type “python” in the terminal the default version being used is now 2.7.9 but nosetests still keep giving me errors relating to print not having parentheses.

  • I found this in the Arch forum

    https://bbs.archlinux.org/viewtopic.php?id=124564

    Sounds similar…

  • Kind of new to Antergos but I just noticed this too. I changed the link so that /usr/bin/python points to python2 instead of python3. The command to do this is changing into the /usr/bin directory and then running sudo ln -sf python2 python.

    Cheers

  • @iambox @herbie It turns out the nosetests I was using was for Python 3: pacman -S python-nose

    What I needed was the version for python 2: pacman -S python2-nose

    Everything works fine now. Thanks guys!

Posts 13Views 3067
Log in to reply