Learning Python 3 with the Linkbot/Installation and Setup

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Installing Python and the Linkbot Control Module (PyBarobo)[edit]

For Python programming, you need a working Python installation and a text editor. Python comes with its own editor IDLE, which is quite nice and sufficient for the beginning programmer. As you get more into programming, you will probably switch to some other editor like emacs, vi or another editor.

The Python download page is: http://www.python.org/download. The most recent version is Python 3.4.1 (as of 19th May 2014); Python 2.7 and older versions will not work with this tutorial. There are various different installation files for different computer platforms available on the download site. Here are some specific instructions for the most common operating systems:

Ubuntu Linux Users[edit]

To install everything you need to run this curriculum, which includes Python 3, Python 3 setup tools, and the Barobo Python package, make sure you have an internet connection and run these commands in a terminal window:

sudo apt-get install python3 python3-setuptools python3-numpy idle3
sudo easy_install3 pybarobo

You will also have to add your user account to the "dialout" group. You can do this by using the command:

sudo usermod -a -G dialout $USER

The above command will add whatever user you are logged in as to the "dialout" group. If you wish to add a user account that is not the one that is logged in, replace "$USER" with the user name of the other account. You may have to log out and log back in for the change to take effect.

For other distributions of Linux, follow the instructions provided by either your distribution or on the Python website to get Python 3, NumPy, and PyBarobo installed.

Raspberry Pi (Raspbian) Users[edit]

Raspbian comes with Python 3 and numpy installed by default. To get the Raspberry Pi ready to control the Linkbot, make sure your Pi is connected to the internet and type the following commands:

sudo usermod -a -G dialout $USER
sudo apt-get install python3-setuptools
sudo easy_install3 pybarobo

You may have to log out and log back in again for the changes to take effect.

Mac users[edit]

Starting from Mac OS X (Tiger), Python ships by default with the operating system, but you will need to update to Python 3 until OS X starts including Python 3 (check the version by starting python3 in a command line terminal). Also IDLE (the Python editor) might be missing in the standard installation. If you want to (re-)install Python, get the MacOS installer from the Python download site.

Windows users[edit]

Download the appropriate Windows installer (the x86 MSI installer, if you do not have a 64-bit AMD or Intel chip). Even if you do have a 64-bit chip, I would still recommend downloading the 32-bit version because some of the Barobo Linkbot libraries are pre-built for 32-bit system by default. Start the installer by double-clicking it and follow the prompts. Be sure to include the optional package "pip", which can come in handy for installing additional Python modules and add-ons.

Once Python is installed and the path is configured, open a command prompt and type the following command:

pip install pybarobo

See https://docs.python.org/3/using/windows.html#installing-python for more information.

Configuring your PATH environment variable[edit]

The PATH environment variable is a list of folders, separated by semicolons, in which Windows will look for a program whenever you try to execute one by typing its name at a Command Prompt. You can see the current value of your PATH by typing this command at a Command Prompt:

echo %PATH%

The easiest way to permanently change environment variables is to bring up the built-in environment variable editor in Windows. How you get to this editor is slightly different on different versions of Windows.

On Windows 8: Press the Windows key and type Control Panel to locate the Windows Control Panel. Once you've opened the Control Panel, select View by: Large Icons, then click on System. In the window that pops up, click the Advanced System Settings link, then click the Environment Variables... button.

On Windows 7 or Vista: Click the Start button in the lower-left corner of the screen, move your mouse over Computer, right-click, and select Properties from the pop-up menu. Click the Advanced System Settings link, then click the Environment Variables... button.

On Windows XP: Right-click the My Computer icon on your desktop and select Properties. Select the Advanced tab, then click the Environment Variables... button.

Once you've brought up the environment variable editor, you'll do the same thing regardless of which version of Windows you're running. Under System Variables in the bottom half of the editor, find a variable called PATH. If there is one, select it and click Edit.... Assuming your Python root is C:\Python34, add these two folders to your path (and make sure you get the semicolons right; there should be a semicolon between each folder in the list):

C:\Python34 C:\Python34\Scripts

Note: If you want to double-click and start your Python programs from a Windows folder and not have the console window disappear, you can add the following code to the bottom of each script:

print("Hello World")
#stops console from exiting
end_prog = ""
while end_prog != "q":
        end_prog = input("type q to quit")


Learning Python 3 with the Linkbot
 ← Authors Installation and Setup Intro →