Python For Mac Os Mojave

broken image


  • 1Installing GNU Radio on MacOS X / macOS
    • 1.5From Source
    • 1.8Typical Errors and Warnings

GNU Radio has been compiled and installed on OSX 10.4 ('Tiger') through 10.15 ('Catalina') running any compatible version of Xcode on all recent and many older Macs -- whether Intel or PowerPC/PPC. There is very little support for getting the background libraries and applications installed on OSX 10.5 or earlier, nor 32-bit Intel or any PPC, though all of these should be possible. Primary support is for 64-bit Intel-based Macs running OSX 10.6 or newer.

I am running MacOS Mojave (10.14.6) and want to install python 3.7. Currently I have python 3.6 installed: $ python -V Python 3.6.9 There seems to be python 3.7 available: $ brew search python &. Python 2 (and Apple ships a vintage version of it) is on /usr/bin/python whereas Python 3 usually gets installed on /usr/bin/python3. The corresponding versions of pip, ipython and others usually get the '3' suffix. That's what Canonical and Red Hat do. If you need Python 2, you can install it yourself. Open a folder for Python workspace by going to Files Open Select or create a folder if the finder window and open it. This will be your Python workspace. Now, open the Command Palette, by pressing Shift, Command and P keys. In the Command Palette, type in and select Python: Select Interpreter.

Learn how to get the most our of macOS Mojave, the latest operating system for your Mac. I'll guide you through macOS Mojave with more than 80 video tutorials and more than 8 hours of video instruction. I begin by showing you the basics of getting around the Mac. I then cover features of the Mac in more detail including the Menu Bar, Dock. Python on a Macintosh running Mac OS X is in principle very similar to Python on any other Unix platform, but there are a number of additional features such as the IDE and the Package Manager that are worth pointing out. Getting and Installing MacPython ¶ Mac OS X 10.8 comes with Python 2.7 pre-installed by Apple.

Prerequisite: X11.app, recommended via XQuartz[edit]

Running almost any GNU Radio graphical interface (GUI) will require downloading and installing X11/XQuartz first. Through OSX 10.8, Apple provided a means to install X11.app, but XQuartz has always been more up to date and hence is recommended for use. Staring in OSX 10.9, Apple no longer provided a full working version of X11.app. Hence, just use XQuartz from the get-go. Note that unless you experiment with using the Quartz interface to various graphical toolkits (e.g., GTK), you must use X11.app as the terminal interface for GNU Radio GUI applications including GRC, the GNU Radio Companion.

A note about DYLD_LIBRARY_PATH and other DYLD environment variables[edit]

On OSX, the library search path is set primarily by the environment variable DYLD_LIBRARY_PATH (and the few other DYLD_* variables). Because of the way the OSX dynamic library loader works, this variable works differently than the LD_LIBRARY_PATH on Linux. Its primary purpose is in finding libraries in a local path, such as when testing software before installing it (we use it in make test in GR), or inside an application. We strongly recommend against setting this variable globally as is typically done with Linux and LD_LIBRARY_PATH. Setting any DYLD_* environment variable for general use is highly discouraged, because doing so, in our experience, leads to problems down the road that are very difficult to diagnose. OSX provides robust means for correcting DYLD-based issues even after dependencies are installed.

Via MacPorts (recommended)[edit]

If you do not already have MacPorts installed, you will need to install it first. Make sure to follow the MacPorts shell environment changes needed such that MacPorts installed executables are found before all others. These are the only changes to the shell environment needed to execute any MacPorts-installed executable!

Once MacPorts is installed, GNU Radio and all of its dependencies can be installed by executing

This method of installing GNU Radio is actively kept up to date by Michael Dickens, and hence is the recommended way to install GNU Radio on Mac OS X.

The latest developments in GNU Radio can be installed via

Please note that the gnuradio-devel port, while tested for basic compilation and functionality, is not a formal release and hence should be considered beta software which might contain bugs or major issues.

Other Package Managers[edit]

Fink and HomeBrew might provide a simple way to install GNU Radio; they are untested (as of early 2020). Conda through conda-forge is another alternative for installing pre-built binaries; see the conda install guide.

From Source[edit]

Background Dependencies[edit]

There are a number of background libraries and applications that must be installed from source or binary in order to compile or execute GNU Radio. These can be obtained by using MacPorts, Fink, HomeBrew, and/or from source / scratch. MacPorts tends to be more up-to-date with respect to new releases, which can be both a blessing and a curse since sometimes new released are untested and result in build or runtime errors. MacPorts, HomeBrew, and Fink offer thousands of ready-to-install libraries and applications, and hence they are highly recommended to use instead of installing from source / scratch.

NOTE: We highly recommended that you install all dependencies via the same package manager! When issues arise, they are much easier to track down, and your updating to newer versions is also much easier.

Many GNU Radio developers first install GNU Radio using MacPorts in order to get all of the necessary background dependencies installed, then remove just GNU Radio via

Compiling GNU Radio using Kate Temkins build script[edit]

Kate Temkin's GitHub repository gnuradio-for-mac-without-macports provides a build script that automate the entire process of building and installing GNUradio, it's dependencies, and a number of SDR hardware backends.

Compiling GNU Radio from Source[edit]

Installing GNU Radio from source follows the standard build guide, with changes to the cmake command such that it always finds the correct version of Python, uses the desired compiler, and finds Sphinx to build documentation.

For example, using Xcode 5 or later's Apple GCC (llvm flavor), MacPorts installed into /opt/local (the default), and for Python 2.7 (as installed by MacPorts), issue the following commands from within the GNU Radio source directory:

If make succeeds, then you can test the build for errors via

$ make test

To install the build, issue

$ sudo make install

Selecting another compiler is as simple as changing the CC and CXX pre-arguments to the cmake command. Note that all of the -DPYTHON* defines must point to the same install of Python, otherwise runtime errors are likely to occur. GR_PYTHON_DIR sets the location into which GNU Radio's Python and SWIG files are to be installed.

By default, the location where cmake built projects will be installed is /usr/local. To change this location, add -DCMAKE_INSTALL_PREFIX=/path/to/new/location to the cmake command line, substituting in the actual desired path for /path/to/new/location. For example, to install into /opt/local, use -DCMAKE_INSTALL_PREFIX=/opt/local. Although we do not generally recommend installing into the same location as some other package manager does, this technique can be useful for debugging purposes; just remember to sudo make uninstall before installing via the owning package manager.

A note about GR_PYTHON_DIR CMake setting and the PYTHONPATH environment variable[edit]

In the above cmake command, we use the flag GR_PYTHON_DIR to tell GNU Radio where to install its Python scripts and related SWIG libraries. The path noted in that command will work for the MacPorts installed python2.7 command. All of the rest of the installed files will be under the /usr/local prefix -- the default CMake setting for when -DCMAKE_INSTALL_PREFIX is not specified.

If you either do not set the GR_PYTHON_DIR flag, or use some other location, you might need to tell Python where to find the installed files. This is done by setting the environment variable PYTHONPATH to include this path. For example, if no GR_PYTHON_DIR or CMAKE_INSTALL_PREFIX flag is specified on the cmake command, then the default install directory will be /usr/local/lib/python2.7/site-packages, and you'll want to set the PYTHONPATH such as the folllwing

export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

This setting might be in the file ~/.profile, ~/.bashrc, or ~/.bash_profile.

When using a package manager such as MacPorts, for most users it is recommended to use the version of GNU Radio provided by the package manager, which will not require changing the PYTHONPATH since that package manager will automatically install the GNU Radio Python files where its Python will find them.

Python

Upgrading to a new version of OSX on the same computer[edit]

When you upgrade OSX, you'll generally need to reinstall GNU Radio (and, all of its dependencies). If you are using MacPorts, you can follow their migration guide to do the reinstallation. You can always just remove all of the old installed files and/or reinstall over them.

Typical Errors and Warnings[edit]

Library not found[edit]

If you are compiling an out of tree module from source, some of them do not set the INSTALL_NAME by default. Without a correct set INSTALL_NAME, the library's self-id will be incorrect and the SWIG library will fail to be able to find the module's primary library. The actual runtime error will look like

Running otool -L on the libraries returns just the dependent library name without path, e.g.,

This issue has been fixed within GNU Radio and is in modtool, and has been propagated to many GR projects. The simple solution is to paste the following chunk of code into the module's top-level CMakeLists.txt file (just after GR_LIBRARY_DIR is defined):

Another solution is to change the installed main and SWIG libraries to have the correct settings. In the case above for gr-air-modes, one could do the following to fix the issue:

Warnings: GTK[edit]

When executing a GNU Radio GUI, including gnuradio-companion, GTK will produce the following warnings on OSX 10.8; they can safely be ignored:

Error: Unusable DISPLAY[edit]

When executing a GNU Radio GUI, including gnuradio-companion, from a terminal window (e.g., Terminal.app, iTerm2.app, X11.app) when not the primary user or when the DISPLAY environment variable is not correctly set, one typically sees the following, regardless of OSX version:

followed by a host of related failed assertions and errors.

If you are using Terminal.app, you'll need to switch to another terminal application such as XQuartz/X11.app or iTerm2.app .

If you are already using an application that correctly sets the DISPLAY environment variable, then you'll want to make sure you're logged in as the primary user (e.g., not as su to another user). If all else fails, try quitting and restarting the application. Try rebooting your computer. When all else fails, contact Michael.

Fatal error: 'unistd.h' file not found[edit]

If your install fails and you notice a line in the reported log file that says something like Fatal error: 'unistd.h' file not found, it's likely due to the path to the active developer tools not correctly setup. To fix, simply execute the following command:

xcode-select --install

A confirmation dialog box will pop-up and the tools will be installed. From here, re-kickstart the gnuradio installation and you should be good to go.

Retrieved from 'https://wiki.gnuradio.org/index.php?title=MacInstall&oldid=8063'

WARNING: You must install and use the specific Python versions on this page. Newer versions of Python, such as Python 3.8, are unstable.

Python comes in several shapes and sizes. To make sure that everything works properly, we require that every single person in the course use the same version of Python. You are free to either work in the labs or to use your laptop. But whatever the case, your version of Python must be the same as what we are using in the labs. Hence, even if you already have Python installed on your computer, we ask that you install a new version (see instructions below) so you can be consistent with everyone else.

As you will see, these instructions are a bit long. Installing Python is often much more complicated than simply using it. As many people in this class have not programmed before,we have tried to make installation as simple as possible via step-by-step instructions. You are not expected to understand what many of these steps are doing. Furthermore, these instructions are lengthy mainly because we are trying to support as many operating systems as possible. In practice, you should be able to finish the installation in 15-20 minutes.

If you have problems, and if you have a laptop, the best thing to do is to bring it in to someone to look at. Any of the course staff can help you with this. If you cannot bring in your computer, we have provided you with some instructions below. If you are having difficulty with these instructions, please post on Piazza or send email to Kevin Cook.

Table of Contents

  • Installing Python
  • Getting Started with Python

Installing Python

While installing the base Python package is usually straight-forward, getting add-onsfor Python can be a bit tricky. That is why we have decided to standardize on the Anaconda version of Python.This is a free version of Python that is used by many courses on campus. It contains a lot of add-ons, limiting the number of things you need to install later.

Once you have the base Python install, you need to install the 'Cornell Extensions'. These are 3rd party extensions packaged by us (and sometimes made by us) to fit into Python. These extra packages include things like graphics capabilities to make games and flashy applications.

Before you install these, be sure to completely read the instructions for your operating system. While you are unlikely to make any mistakes, it is best foryou to do things in exactly the order we tell you to. As we said, you do not needto understand what is going on here.

Installing on Windows

Python for mac os mojave

Upgrading to a new version of OSX on the same computer[edit]

When you upgrade OSX, you'll generally need to reinstall GNU Radio (and, all of its dependencies). If you are using MacPorts, you can follow their migration guide to do the reinstallation. You can always just remove all of the old installed files and/or reinstall over them.

Typical Errors and Warnings[edit]

Library not found[edit]

If you are compiling an out of tree module from source, some of them do not set the INSTALL_NAME by default. Without a correct set INSTALL_NAME, the library's self-id will be incorrect and the SWIG library will fail to be able to find the module's primary library. The actual runtime error will look like

Running otool -L on the libraries returns just the dependent library name without path, e.g.,

This issue has been fixed within GNU Radio and is in modtool, and has been propagated to many GR projects. The simple solution is to paste the following chunk of code into the module's top-level CMakeLists.txt file (just after GR_LIBRARY_DIR is defined):

Another solution is to change the installed main and SWIG libraries to have the correct settings. In the case above for gr-air-modes, one could do the following to fix the issue:

Warnings: GTK[edit]

When executing a GNU Radio GUI, including gnuradio-companion, GTK will produce the following warnings on OSX 10.8; they can safely be ignored:

Error: Unusable DISPLAY[edit]

When executing a GNU Radio GUI, including gnuradio-companion, from a terminal window (e.g., Terminal.app, iTerm2.app, X11.app) when not the primary user or when the DISPLAY environment variable is not correctly set, one typically sees the following, regardless of OSX version:

followed by a host of related failed assertions and errors.

If you are using Terminal.app, you'll need to switch to another terminal application such as XQuartz/X11.app or iTerm2.app .

If you are already using an application that correctly sets the DISPLAY environment variable, then you'll want to make sure you're logged in as the primary user (e.g., not as su to another user). If all else fails, try quitting and restarting the application. Try rebooting your computer. When all else fails, contact Michael.

Fatal error: 'unistd.h' file not found[edit]

If your install fails and you notice a line in the reported log file that says something like Fatal error: 'unistd.h' file not found, it's likely due to the path to the active developer tools not correctly setup. To fix, simply execute the following command:

xcode-select --install

A confirmation dialog box will pop-up and the tools will be installed. From here, re-kickstart the gnuradio installation and you should be good to go.

Retrieved from 'https://wiki.gnuradio.org/index.php?title=MacInstall&oldid=8063'

WARNING: You must install and use the specific Python versions on this page. Newer versions of Python, such as Python 3.8, are unstable.

Python comes in several shapes and sizes. To make sure that everything works properly, we require that every single person in the course use the same version of Python. You are free to either work in the labs or to use your laptop. But whatever the case, your version of Python must be the same as what we are using in the labs. Hence, even if you already have Python installed on your computer, we ask that you install a new version (see instructions below) so you can be consistent with everyone else.

As you will see, these instructions are a bit long. Installing Python is often much more complicated than simply using it. As many people in this class have not programmed before,we have tried to make installation as simple as possible via step-by-step instructions. You are not expected to understand what many of these steps are doing. Furthermore, these instructions are lengthy mainly because we are trying to support as many operating systems as possible. In practice, you should be able to finish the installation in 15-20 minutes.

If you have problems, and if you have a laptop, the best thing to do is to bring it in to someone to look at. Any of the course staff can help you with this. If you cannot bring in your computer, we have provided you with some instructions below. If you are having difficulty with these instructions, please post on Piazza or send email to Kevin Cook.

Table of Contents

  • Installing Python
  • Getting Started with Python

Installing Python

While installing the base Python package is usually straight-forward, getting add-onsfor Python can be a bit tricky. That is why we have decided to standardize on the Anaconda version of Python.This is a free version of Python that is used by many courses on campus. It contains a lot of add-ons, limiting the number of things you need to install later.

Once you have the base Python install, you need to install the 'Cornell Extensions'. These are 3rd party extensions packaged by us (and sometimes made by us) to fit into Python. These extra packages include things like graphics capabilities to make games and flashy applications.

Before you install these, be sure to completely read the instructions for your operating system. While you are unlikely to make any mistakes, it is best foryou to do things in exactly the order we tell you to. As we said, you do not needto understand what is going on here.

Installing on Windows

We require that all students with Windows use Windows 10. This version has been out longenough that no one should be running Windows 8 or 7 anymore. If you are using an older version of Windows, we recommend that you upgrade now before the semester starts. If your machine cannot support Windows 10you will need to work on the lab computers.

For this class, we need to use Python version 3.7.6. This is not the most recent version of Python. However, our tests have shown that more recent versions of Pythonare not stable, and are not capable of completing the course assignments. If you have installed a more recent version of Python, you will need to install this version to 'roll it back*. Even if you have Anaconda installed already, it is safest if you install from the button below to guarantee that you have the correct version.

Installing Anaconda for Python 3.7.6

Use one of the two links above to install the correct version for your operatingsystem. Most modern Window installations are 64-bit. However, if you are unsure, download the 32-bit version. The 32-bit version is guaranteed to work on all systems.

The file that you download is an installer app. Simply double click on it and followdirections. At one point in the installer, it will ask you whether you want to installfor yourself or for all users. Select the option 'All Users (requires admin privileges)', as shown below.

On the next page it will ask you what directory you want to install in. By default, it will install in C:ProgramDataAnaconda3. We need this folder for Cornell Extensions, so leave this alone and click Next.

Finally, you will see a page with check boxes talking about your Path. You must selectthe top box, even though it warns you not to. If you do not check this box, you will not be able to use Python from the PowerShell.

When you are done installing, you will receive some information about an applicationcalled PyCharm. While you are not prohibited from installing this program, we will notbe using it this semester, and we will not provide help on how to use it.

Installing the Cornell Extensions

Download the file from the link above. After downloading, you will see that this is a folder with a zipper on it. Double click on the folder. This will open an Explorer Window with another folder inside of it called CornellExtensionsInstallDrag the CornellExtensionsInstall folder on to your Desktop. This is important, as the installation is not guaranteed to work if you click on the installer while it is still inside the folder with the zipper (files inside of zipped foldersare not 'real' until you pull them out).

Now that you have a copy of CornellExtensionsInstall on your Desktop, open this folder (again, not the one in the zipped folder!). Inside, you should see the following two items:

Double-click on the file that is named install. This will pop up a window with a lot of scrolling text in it. Do not close the Window until you see the line thatsays 'Installation Complete', and asking you to hit a key. If you close the Window too early, you will have to install a second time.

On some Windows systems, the security settings may prevent you from installing CornellExtensions. On those systems, you will see a security message like the one below.

If this happens to you, click on the 'More info' link. When you do that, the informationmessage should now look like this:

Click the 'Run anyway' button to complete the installation.

Once you have finished with the Cornell Extensions, you should test your installation

Installing on Macintosh

WARNING: Pay close attention to your specific version of MacOS. Installing the wrong version will prevent you from running the test scripts.

While Macs are a great platform to run Python on, there is a major problem with Mac andPython caused in the past year. Apple broke something in Mojave (10.14), and did not fix it until they released Catalina (10.15). So you cannot run the latest Python with Mojave.The obvious solution is to upgrades to Catalina. Except that Apple stopped supporting32-bit applications in Catalina. If you have a lot of applications older than 3 or 4years old, this can be an issue (your instructor lost half his Steam library). So wecan understand if you do not want to upgrade to Catalina.

The correct version of Python to install therefore depends on your operating system. Ifyou do not know what you are running, go to the Apple menu and choose about this Mac.If you are running Catalina, you need to install Python version 3.7.6. This is not the most recent version of Python. However, our tests have shown that more recent versions of Python are not stable, and are not capable of completing the course assignments. If you have installed a more recent version of Python, you will need to install this version to 'roll it back*. Even if you have Anaconda installed already, it is safest if you install from the button below to guarantee that you have the correct version.

If you are running Mojave, you need to install an even older version of python, Python version 3.6.5. We do not use any of the new features in Python 3.7, so you will be okay if you use this older version of Python. Versions of MacOS older thanMojave should also use version 3.6.5.

Installing Anaconda for MacOS

Use the above link to install the correct version for your operating system. The file that you download is an installer app. Simply double click on it and follow directions. You may wish to change the install location on this page:

However, there is something weird with the MacOS installer when you do this. In particular,you may see the following error:

This problem is easy to solve. If you just click on the house, it will now look like this.

It is okay for you to install Anaconda this way. However, we would prefer that you install it for all users instead. Select the hard drive icon below the house. When youare done, it should look like this.

Select the button Choose Folder to the right. This will tell it where to putAnaconda. We recommend that you put it in the Applications folder.

If you are using Catalina (10.15), you should be aware that MacOS has significantly increased security restrictions in this version of the OS. You must give permissionto everything that the system thinks is unusual. This installer is one of those unusual things. The installer will appear to stall for a while, and then you will get thismessage:

Click OK and the installation should complete.

When you are done installing, you will receive some information about an applicationcalled PyCharm. While you are not prohibited from installing this program, we will notbe using it this semester, and we will not provide help on how to use it.

Installing the Cornell Extensions

The last step is to install the Cornell Extensions for CS 1110. Download this filefrom the link above. After downloading the file, double click on it to unzip the contents into a folder somewhere on your computer.

Once again, you see will a package installer. Double click thid installer. You may see a warning telling you that this is not an official installer (because we made it). If that happens, you will need to control-click the installer and select Open from the drop-down menu.

If the installer launches properly, you will see the following window:

Follow the directions for the installer. Your installation is now complete.
Once this is done, you are now are ready to test your installation.

Installing on Linux

Linux installation is possible, but it is not as straight-forward as the two mainOS options. In particular, to install on Linux, you have to be comfortable with theTerminal and be ready to install files with a package installer. If this sounds daunting to you, you might want to rethink about whether you want to use Linux just yet.

For this class, we need to use Python version 3.7.6. This is not the most recent version of Python. However, our tests have shown that more recent versions of Pythonare not stable, and are not capable of completing the course assignments. If you have installed a more recent version of Python, you will need to install this version to 'roll it back*. Even if you have Anaconda installed already, it is safest if you install from the button below to guarantee that you have the correct version.

In the past, we have had install parties for Linux users. We have worked to makethe instructions more self-sufficient this year. However, if there is still demandfor a Linux install party, post your request on Piazza.

Installing Anaconda for Python 3.7.6

Use one of the two links above to install the correct version for your operatingsystem. If you are in doubt, use the Intel version, as it is unlikely that youare working with a PowerPC machine.

This is not a graphical installer. To install it, you must navigate to the folderwith the downloaded file and run it with bash. For example, if you downloadedthe 64-bit version, you would type:

You must use the 'bash' command even if you are not using the bash shell.

You may install Anaconda where ever you wish. By default, it installs in your homedirectory. However, we prefer to install it in /usr/local. The choice isup to you.

Installing the Cornell Extensions

Because Linux platforms are so different, there is no one-click installer for Linux.In particular, we would need to know whether you are using apt-get (Debian, Ubuntu)or yum to install software. So we will let you do this on your own. There aretwo important steps.

Installing Kivy

Kivy is the graphics library that we will be using for several of the assignments in this class. In the past, students have had to compile this library from source code. However, Kivy now has installers for several flavors on Linux.
Look at the downloads page for more information.

For Ubuntu, you will notice that the instructions suggest using apt-get. Thisonly works for installing Kivy into the the official Ubuntu Python 3. This version ofPython is old and missing a lot of packages. Therefore, we suggest that you installusing PIP. The exact sequence for installing on Linux (assuming you are running Python 3.7.6) is as follows:

If this does not work, and you are using Anaconda, you may want to use the condacommand instead. Kivy is an optional Anaconda package using Conda Forge. Simply use the command

Python For Mac Os Mojave Dmg

Installing introcs

If you got Kivy working, then you are almost done. The last step is the easiest. Youneed to install the introcs package using PIP. The command is

Once this is installed, you are are ready to test your installation.

Using An Alternate Version of Python

If anything goes really wrong, you may just want to use the built-in Python 3 providedby your version of Linux. It is not ideal (most are still using 3.5 or are even usingthe problematic 3.8), but it will get you through the course. However, if you go your own way, there are several packages that you must install (using PIP). All of these packages are in addition to Kivy and introcs.

Keep in mind that this option may require you to build Kivy from source.If you cannot figure out how to do that, you may want to rethink using Linuxfor the semester.

Getting Started with Python

Now that you have installed Python, it is a good idea to test it out. While you do not need to know anything about Python yet, you do need to learn how to run Python programsthat are already made for you.

Running the Python Shell

The first thing that you need to do is to familiarize yourself with command shell foryour OS. The command shell is a text-based version of the Windows Explorer or Finder;you can use it to move and rename files and folders. It is also how we will run Python in this class.

Using the command shell requires a bit of practice, so wehave created a separate page of instructions for this. Right now, all you need to know is how to start up the command shell. You do not need to know any special commands. Start the command shell for your OS and type

Install Python For Mac

This will put you in the 'Python Interactive Shell'.

The Python Interactive Shell looks exactly like the command shell except that ittakes Python commands (and does not respond to operating system commands to listfiles or change the working directory). While the command shells are differentfor all operating systems, the Python Interactive Shell should look and behave exactly the same way for everyone. On Windows, it will look something like this.

The >>> symbols are the prompt. To get the shell to do something,just type a Python command. For example, type

and hit Return (do not type the >>>; it is already there).See what happens?

To exit the Python Interactive Shell, type quit() and hit Return.You can also exit by typing Control-D. Vlc converter mac free download.

Python On Mac Os

Testing a Script

It is possible to run Python script from the command shell as well. A scriptis a file (ending in suffix .py) containing Python code. We willuse them throughout the course. To run a script, you type

from the command shell. Do not try to type this in the Python InteractiveShell. This can be a bit confusing at first; it is important to keep the following straight:

  • The command shell is a program for accessing files via text based commands. You start Python in this program, but it is not Python.
  • The Python Interactive Shell is a program that runs inside the command shell. You can tell it is running by the presence of the >>> prompt.

Running a module does not start the Python Interactive Shell. It runs all of thecommands in the file, and then quits immediately when done with the file.

To test that your installation is working properly, we have a cute Python modulethat displays a GUI with the phrase 'Hello World!' inside it, as shown below.

To try out this module, download the file hello_tk.pyand put it in some easy to find folder. Open up a command shell and navigate to thisfolder using the drag-and-droptrick for changing directories. Then type the command

If you get the window shown above, congratulations! You have successfully installedthe proper version of Python necessary for this class.

WARNING: If you are a Mac user, running hello_tk.py may cause your computer to reboot. If this happens, you have installed the wrong version of Python.

If the Window does not show, look very carefully at the error messages. If it saysit cannot find the file hello_tk.py, then you did not use the drag-and-drop trick correctly. We recommend that you practice with the command shell tutorial some more. Otherwise, there is a problem with your installation of Python. Post your error message to Piazza and we will try to help you out.

If you have the message working we recommend one more test. There are actually twodifferent ways to create GUIs in Python. One is called TCL/Tk. The other is Kivy (which you installed as part of Cornell Extensions). The test above is for TCL/Tk.You should test out Kivy as well. To do that, download the filehello_kivy.pyand repeat what you did with hello_tk.py. That, is navigate to the folder with thefile and type

The window that pops up should look pretty much the same as before, except that it will be of a different size and in a different location. If this script fails, but the TCL/Tk script worked, that means you did not properly install Cornell Extensions. Contact a staff member if you need help.

Troubleshooting Catalina

Catalina (MacOS 10.15) is a notoriously problematic upgrade that has caused problemsfor people all across the industry. That is because it changed so many things abouthow the Mac used to work. First of all, it eliminated 32 bit apps. But it also didsomething else that directly affects us in this class: it changed how the Terminalworks.

The Terminal relies on a special program called a shell that tells it how to processthe text based commands. For many years, MacOS – just like the vast majority of Unix –used the bash shell. In Catalina, they changed to zsh. It seems that, if you area new Mac user – so you are using Catalina and have never used an older version of MacOS – the lack of any bash settings is confusing the Anaconda installer.

But we have a fix for you Catalina users. You need to do the following steps:

  1. First make sure you are running zsh and not bash. To check, type
  2. While inside of the Terminal type
  3. Find the correct path (with all of the slashes to Anaconda). We talk about pathsin the videos of Lesson 0. The default Python 2.7 is at path

    Most (but not all of you) should have installed Anaconda at

  4. Open up .zshrc in TextEdit by typing (in the Terminal)
  5. Add the following line to this file

    with those quotation marks, but putting in the correct path. So in most cases,this will be

  6. Save and quit the file.
  7. Quit and restart the Terminal.

This should fix your installation. If it does not, please see a consultant for help.

Installing Atom

The last program to install is Atom Editor. Unlike Python, you will not use this program right away. In fact, we will not start to use it until the third week of class. The purpose of Atom is to make these mysterious modules that you tested in the previous step.

Technically, you can write Python modules in any text editor (e.g. a Word processor that only produces text and does not have fonts or fancy formatting). NotePad and WordPad are text editors in Windows, while TextEdit is provided by MacOS. The reason we use Atom is that it is the same across all platforms. That allows you to collaborate with partners who might be working on other operating systems. Some people preferSublime Text, but that program is not free. Theprogram VS Code is an acceptable alternative, but it is not properly configured for Python out of the box and requires significant customization.

To install Atom, click the button above to take you to the Atom website. You should see a yellow 'Download' button, which has your computer system's OS information above it. Click on that button.

If you are using a Windows computer, the downloaded file will be an .exe file. Double click it and Atom should install automatically. For Linux computers, install the .deb file and then double click on it. You should then be able to install it using your package manager.

If you are using a Mac computer, the downloaded file should be a .zip. Double click on that .zip file, and then drag the resulting Atom.app to your applications folder. The first time you attempt to open it, it may warn that it is an unverified application from the internet. Ignore this and click open on the window that pops up.

Configuring Preferences

One of the most controversial aspects of Python is that it treats spaces and tabs very differently. If you accidentally put a tab in your program, it will cause your program will crash. And you will have a hard time finding it because both tabs and spaces look exactly the same.

Most of the time, this is not a problem. However, we must first configure Atom so that indentation is consistent across all of our files. First, open Atom. Then, open the Settings menu option; in Windows, it is under the File category, and in Mac, it is under Atom (and is named Preferences). Then, in the settings window that opens, select the Editor category, and scroll down. First, check the boxes 'Show Indent Guide' and 'Show Invisibles' so that your settings match this image:

Click for Bigger Image

This will allow you to see both tabs and spaces, and to tell the difference between both. Spaces will look like light dots which are centered vertically on each line. Tabs will look like two ‘>' characters next to each other. These are illustrated in the examples below.

Atom with Tabs (Bad)Spaces Only (Good)

Continue scrolling down. Change the value in 'Tab Length' to 4, and click on the valuein 'Tab Type'. This should open a drop-down menu. Select 'soft'. This will make Atom automatically replace all Tabs you input with 4 spaces. After configuring, these two settings should look like this:

Click for Bigger Image

Using GitHub

We do not require the use of GitHub for this course, as it is a bit too advanced for many students. However, we know that some of you will use it anyway, particularly forsharing assignment code with your partner. Because of our academic integrity policy,we need to put strict rules on its use.

The free accounts that you get from github.com are publicly viewable. That meansanyone can see them, and anyone can download code from them. This means that if you putyour code on GitHub, and another student downloads it, you will be held liable for cheating, even though you may have no idea who this other person is. In fact, any codewe find in publicly visibile in GitHub will constitute and academic integrity violationwhether or not anyone copies it.

If you want to use a code repository, you should use the official Cornell GitHub instead. Any projects that you put here will be protected and cannot be accessed by other students. You will not be held liable for security leaks that are not your fault.

We know that this is inconvenient for students that would like to show code to prospectiveemployers. However, there has been enough abuse of this in recent years that we have hadto take a stricter approach to GitHub. We recommend that you share your code through a private repository or else work on another Python project in your own time.





broken image