CSC 240: Computer Graphics

Solutions for common Python and commandline issues

  • Python version is 2.7 by default

    Common issue: in the commandline, running

    python --version 
    returns 2.7.6, or one of the other 2.7 versions. This is happening because the default version of python is 2.7, even if you have 3.4 installed. One solution is to run
    python3 --version 
    instead, which hopefully should return 3.4.3, or one of the other 3.4 versions. To create a short-term solution, on Linux or Mac, you can run:
    alias python=python3 
    However, this will only work for the current terminal instance. If you open up a new terminal later on, you'll have to type this again. To create a long-term solution, run:
    cd ~ 
    emacs .bash_profile
    This will first bring you to your home directory, then open up the file .bash_profile. At the end of this file, add the line:
    alias python=python3 
    Then save the file (CTRL-x CTRL-s) and exit emacs (CTRL-x CTRL-c). This will make the change to Python 3.4 permanent.

  • Windows: python not recognized

    If you are using a Windows machine, you make have gotten the following error when typing "python" into the commandline (cmd):

    'python' is not recognized as an internal or external command,
      operable program or batch file. 
    This is happening because, by default, the folder containing python is not added to your path. One solution is to navigate to where python is located and work from there, but this is not a great long-term solution. One solution is instead of typing "python" each time, type the full path, i.e.:
    c:\Python34\python --version 
    A better solution is to add the location of python to you PATH variable, as described below. These instructions are from this stack overflow question , which also contains several other workarounds if this doesn't work for you.

    1. From the desktop, right-click My Computer and click Properties.

    2. In the System Properties window, click on the Advanced tab.

    3. In the Advanced section, click the Environment Variables button.

    4. Highlight the PATH variable in the Systems Variable section and click the Edit button.

    5. Add the path of your python executable (c:\Python34\). Each different directory is separated with a semicolon. (Note: do not put spaces between elements in the PATH. Your addition to the PATH should read ;c:\Python34\ NOT ; c:\Python34\)

    6. Apply the changes. You might need to restart your system, though simply restarting cmd.exe should be sufficient.

    7. Launch cmd and try again. It should work.

  • Commandline tips

    One reason we're using the commandline in this class is that it's a great life skill! Usually we use a graphical user interface (GUI) to navigate between folders, to create, edit, and delete files, and to execute programs. But almost all of this we can do through the commandline. Here are a few tips for getting started.

    1. Navigation. To enter a folder (say "Documents"), run
      cd Documents/ 
      To see what folders are available in your current directory, type "cd", then a space, then hit the tab key a few times. Also, once you start typing a folder name, hit tab anytime to auto-complete the name (or see what other folders match so far). To move up a folder, run
      cd .. 
    2. Repeating commands. If you want to run the same command (or a similar one) again, hit the up arrow key to get the command you just ran. Pressing up more than once will go through all your previous commands.

    3. Listing files. To list what files and folders are in your current directory, run