Installing Python Packages (Part 2)

In the Installing Python Packages (Part 1) post, you discovered the easiest method of installing new packages when working with Beginning Programming with Python For Dummies, Python for Data Science for Dummies, and Machine Learning for Dummies. Using the pip command is both fast and easy. However, it doesn’t provide much in the way of feedback when things go wrong. To overcome this issue, you can use the conda command in place of pip when you have Anaconda installed on your system. Like pip, conda supports a wide variety of commands. You can find a listing of these commands at http://conda.pydata.org/docs/using/pkgs.html.

You need to know a few things about working with conda. The first is that you need to open an Anaconda prompt to use it. For example, when working with Windows, you use the Start ⇒ All Programs ⇒ Anaconda<Version> ⇒ Anaconda Prompt command to open a window like the one shown here where you can enter commands. (Your Anaconda Prompt may look different than the one shown based on the platform you use and the version of Anaconda you have installed.)

Use the Anaconda Prompt to gain access to the conda command.
The Anaconda Prompt

You can easily discover the features the conda command supports by typing conda -h and pressing Enter. You see a list of command line switches similar to the ones shown here:

Use the conda command line switches to perform various tasks.
A Listing of Conda Switches

As you can see, there are quite a few tasks you can perform. To determine whether you have a package installed, use the Conda search <package name> command.  For example, if you want to determine if you have Pandas installed, you type Conda search Pandas and press Enter.  You see a list of Pandas versions installed, assuming that Pandas is installed, like this:

Use the search switch to locate a particular package installation.
A Listing of Pandas Information

The information you get from conda is far more in depth than pip provides. To determine what you have installed, just go down the list and determine whether you have the version of Pandas that you need.  If you don’t, then type Conda update pandas and press Enter (notice the case used).  On the other hand, let’s say you want to install BeautifulSoup.  Well, the first time through, try typing Conda install BeautifulSoup and pressing Enter.  You see an error message that tells you what to type like this:

The conda command provides you with helpful error information.
Using Error Information

Since you want to install the latest BeautifulSoup, type Conda install beautiful-soup and press Enter.  After searching for the required update information, conda will ask if you want to proceed.  Type y and press Enter.  You’ll see a whole bunch of activity take place, but eventually, you have a new version of BeautifulSoup, plus all the supporting functionality, installed correctly in the correct locations.  Here’s how things looked on my system:

Conda provides detailed information about the installation process.
Viewing the Result of an Installation

At this point, you have BeautifulSoup installed. Installing other packages follows the same path. Using conda does require a little more expertise than using pip, but you also gain additional flexibility and garner more information. When everything goes well, either tool does an equally good job of getting the installation or update task done, but conda excels in helping you past troublesome installations. Let me know your thoughts about using conda to install the packages required by my books at John@JohnMuellerBooks.com.

 

Supporting Creative People

I work really hard to support my readers and so do many other authors. In fact, most creative people are in creative trades because they like to communicate with others using a variety of methods. The simplest goal is to provide something of intangible value to others—be it a painting, sculpture, dance, music, or writing. It’s well known that creative people are often underpaid (hence the cliché, starving artist). Because the starving artist (and most of them truly are starving) makes little money, it’s important that people do support them whenever possible. That’s why the piracy of Intellectual Property (IP) is such a problem. I’ve written about this topic before from a writing perspective (see Piracy and the Reader), but IP theft has become a serious enough problem that we’re beginning to lose many good creative people simply because they no longer have enough money coming in to make a living.

The problem is that many people would support the creative people whose IP they use, but they don’t really understand that they need to pay for this material. For example, there are many sites online now that offer my books free of charge. Just viewing the site doesn’t provide a clue that anyone is stealing anything. These sites have a clean appearance and simply offer IP in the form of downloadable music, books, and so on. In fact, many of these sites are fully searchable. The reasons that someone would do something like this varies, but it pays to employ some critical thinking when you see something free that possibly looks a bit too good to be true. Many people download viruses, spyware, and other sorts of malware along with their free download. In the long run, it’s actually less expensive to buy the IP, than to have a computer compromised by some of the crud that comes with these free downloads.

For the record, my books are never free. You need to pay for your copy of my book in order to support the various things of value that I provide to you as a reader, including this free blog. It isn’t my goal to become rich—if that were my goal, I’d be in some other line of work (believe me when I say authors aren’t paid particularly well), but I do need to make enough to pay my expenses, just as you do. Even though I know many people do download my books free, I still support everyone that I can with good advice on how to get the most from the books I write. To me, coming in each day and working with all of you is one of the benefits of being an author. I truly do want people to use my books to get ahead in life. If you’d like to discuss the effects of piracy on you as a consumer of IP, please write me at John@JohnMuellerBooks.com.

 

Choosing to Use Graphics

Graphics can be a tricky issue in technical writing. Some authors use graphics at the drop of a hat. Often, the graphic shows something that the reader can readily understand from the text or contains nothing of value to the reader. For example, some books contain images of objects that don’t have any intrinsic value of themselves and possibly contain a little text that the author could easily include in the text. However, some authors err to the other extreme. Some abstract concepts lend themselves to pictorial representation. For example, a block diagram can often convey relationships that would be impossible to describe using text alone. Consequently, the issue of whether to use graphics within a text or not often hinges on the graphic’s ability to convey meaning that words alone can’t.

However, the decision to use graphics often involves more than simply conveying information. The quality of the graphic also matters. Graphics that appear too small in the book make it impossible for readers to make out details and render them useless. Designing a graphic that provides all the required details can be time consuming. However, including a less than useful graphic in the book is generally a waste of space. In some cases, the solution is to provide a reference to an external source (such as the Internet) for the graphic, rather than include the graphic directly in the book. Some authors have a strong desire not to use external sources because they tend to change, but using poorly designed graphics that fail to convey the desired information to most readers is equally problematic.

Focusing the graphic is also a problem. When a graphic contains too much detail or contains elements that have nothing to do with the discussion, the message can become lost. Using a cropped graphic helps focus attention and reduces the amount of space the graphic consumes in the book. By focusing reader attention on specific details, it also becomes easier to convey a specific message. Most important of all, keeping individual graphics small (yet easily readable) is essential to allowing use of as many graphics as is needed for the book as a whole.

The bottom line is that authors who use graphics effectively are able to communicate a great deal of information to readers in a modicum of space. In addition, using graphics presents the reader with another way to learn the material. Many people don’t learn well just by reading text, they also require graphics, hands on activities, exercises, and the like in order to learn a topic well. When choosing to use graphics, you must consider all aspects of how the graphic will appear to the reader. Let me know your thought on graphics usage at John@JohnMuellerBooks.com.

 

Installing Python Packages (Part 1)

My Python-related books, Beginning Programming with Python For Dummies, Python for Data Science for Dummies, and Machine Learning for Dummies use various libraries to perform book-specific tasks. The books do provide instructions as needed, but, based on reader input, sometimes these instructions aren’t as clear as necessary, located in precisely the right location, or possibly as specific as needed. This post will help you get the packages containing the libraries you need installed in order to get more from the books.

It’s essential to remember that Beginning Programming with Python for Dummies relies on the 3.3.4 version of Python. The other two books rely on Python 2.7.x versions. The reason for using the older version of Python in these two books is that these books rely on libraries that Python 3.x doesn’t support. If you try to install these libraries on Python 3.x, you’ll get an error message of somewhat dubious usefulness.

In most cases, the easiest way to install a package is to open a command prompt with Administrator privileges and rely on the pip (for Python 2.x) or pip3 (for Python 3.x) command to perform the installation. For example, to install BeautifulSoup, you can type pip install beautifulsoup4 and press Enter. Installing any other package follows about the same route.

The only problem with the pip utility is that you don’t get it with every version of Python. When using an older version of Python, such as 3.3.4, you actually need to install the pip utility to use it. Fortunately, the installation instructions at https://pip.pypa.io/en/latest/installing/ aren’t difficult to use and you’ll be up and running in a few minutes.

Some readers have also complained that pip doesn’t provide much information when it comes to errors. The lack of information can prove problematic when an installation doesn’t go as planned. Next week I plan to cover the conda utility that comes with Anaconda. This utility isn’t as easy to use in some respects as pip, but it does provide considerably more information. If you have any questions about using the pip utility with my books, please contact me at John@JohnMuellerBooks.com.

 

Mac Gatekeeper Error

A number of my books, such as C++ All-In-One for Dummies, 3rd EditionBeginning Programming with Python For Dummies, Python for Data Science for Dummies, and Machine Learning for Dummies ask readers to download an IDE or other code and install it on their Mac systems. The problem is that the Mac system won’t always cooperate. For example, you might see an error dialog like the one shown for Code::Blocks:

The Gatekeeper error tells you that it won't allow you to install software from unknown publishers.
Your Mac won’t let you install software.

The problem is one of permissions. The default permissions set for newer Mac systems restrict you to getting your apps from the Mac App Store or from vendors who have signed their files. Fortunately, you can overcome this problem either temporarily or permanently, depending on how you want to use your Mac. The Fix the “App can’t be opened because it is from an unidentified developer” Error in Mac OS X blog post provides you with illustrated, step-by-step directions to perform the task using either method. Let me know if you encounter any other problems getting your Mac to install the software required to use my books at John@JohnMuellerBooks.com.

 

Using Notes, Tips, and Warnings Effectively

Writing is all about emotion—I’ve mentioned this need quite a few times in the past. There are many ways to create emotion in technical writing. Of course, word choice, sentence structure, and other tools of the trade come into play, just as they do for every other form of writing. You can answer the six questions in a specific way or you can set material aside in a sidebar. However, one of the approaches that is truly different in technical writing is the use of notes, tips, and warnings. In all three cases, you create a single paragraph sidebar-like structure, but the emphasis and nuance of the inclusion is different from other sorts of writing:

  • Notes: Information that you want to include as an aside to the main text. You might choose to document the information source, the location of additional information, or augment parts of the main text in some way. The emotional impact of a note is the feeling of being special. When the reader sees a note, it should evoke a feeling that this is peculiar or extraordinary information that could impact the reader’s use of technology.
  • Tips: Information that is extra in nature. You might choose to include a personal technique that you haven’t seen documented anywhere else, the location of goodies that won’t necessarily affect the reader’s use of technology described in the book, but will add to the readers appreciation of that technology, or some sort of gift-like source, perhaps a free download. The emotional impact of a tip is one of surprise. When a reader sees a tip, it should evoke a sense of getting extra value from the book—something unexpected that adds value to the reading experience. A reader should get the tingly feeling that one gets when receiving an unexpected present.
  • Warnings: Information that is dire in nature. Reserve warnings for those times when a reader’s incorrect action could cause personal, data, or other sorts of damage. The emotional impact of the warning is dread. The reader should see a warning as a notification that incorrect actions are rewarded negatively—they’re the stick that goes with the carrot of notes and tips.

It’s important to remember that these three constructs aren’t the main event. Your body text is still the main event and these three elements serve only to emphasize that material in some way. Depending on the book you write, you may have other specialized paragraphs at your disposal. Each of these unique paragraph types should evoke a particular emotion. Unfortunately, the emotion they should evoke is seldom documented, so you need to figure it out for yourself. It’s essential that you do take the time to discover what emotion the paragraph is supposed to evoke (or simply not use the special paragraph in your writing).

Unlike sidebars, notes, tips, and warnings are rarely more than a paragraph long. You could possibly make an argument for two paragraphs in rare circumstances. The paragraph should contain two or three sentences with the first sentence providing a summary and the second providing details. A third sentence provides ancillary information as needed. The structure and content of your special paragraph should reflect the kind of paragraph you’re creating—as with a good actor, keep your paragraph in character. After all, it’s a performer on the stage of your book and presents the reader with a special feature that is unavailable elsewhere.

Using the special paragraphs at your disposal in the correct way can mean the difference between communicating effectively with your reader and losing the reader’s attention completely. Let me know your thoughts about the use of notes, tips, warnings, and other special paragraphs at John@JohnMuellerBooks.com.

 

Working with Code in e-Books

Most of my technical readers now use e-books instead of paper books. Of course, there is a convenience factor to storing your entire library on a Kindle, even if it’s a software version of the Kindle. Of course, there are all sorts of e-book formats for your desktop system as well. The point is that electronic format makes a lot of sense when dealing with technical books.

However, e-books can cause some interesting problems and I’ve encountered a few with a number of readers now. The most important consideration is that you can’t cut and paste code from an e-book directly into your IDE and expect it to work. There are all sorts of reasons for this exclusion. For example, cutting and pasting may insert special characters into the output stream or the resulting paste may not have white space in the right places. A common problem is that publishers often convert regular single and double quotes into curly quote equivalents. The two kinds of quotes (both single and double) are completely different and the second type definitely won’t compile.

The best option when working with an e-book is to view the code in the e-book, but still get the downloadable source code for the book from the publishers website. I always provide a blog post detailing where to obtain the downloadable source for a book, when you need source code to use the book. If you can’t find the downloadable source, always feel free to contact me at John@JohnMuellerBooks.com. I want to be sure you have a great reading experience, which means having source code that actually runs in your development environment.

Another potential problem with e-books is that you may see unfortunate code breaks (despite the efforts of the publisher and myself). When you need to understand how white space works with a programming language, always review the downloadable source. The fact that the downloadable source compiles and runs tells you that all the of white space is in the right place and of the correct type. Typing the source code directly out of your e-book could result in added carriage returns or other white space errors that will cause the code to fail, even though the commands, variables, and other parts of the code are all correct.

As always, I’m open to your questions about my books. If you don’t understand how things work, please contact me—that’s why I’m here.

 

Using the Correct Product with MATLAB for Dummies

A reader recently wrote in with a problem with the example on pages 311 and 312 of MATLAB for Dummies. In this case, the reader was using the R2015b academic license edition. What the reader saw was this error:

>> A = magic(4)

A =

    16     2     3    13
    5    11    10     8
    9     7     6    12
    4    14    15     1

>> factor(sym(A))
Error using sym/factor (line 50)
The first argument must be a scalar.

It turns out that the newer version of MATLAB doesn’t provide the same support as the R2013b release used for the book. As a result, the example code doesn’t work as expected because the newer version requires different code that looks like this:

A=magic(4)
for i=1:4
    for j=1:4
        B{i,j}=factor(A(i,j));
    end
end

To get all factors double click on B in the workspace window. This workaround is needed because the newer version no longer supports the old method of performing the task.

The point is that the book is written to use a specific version of MATLAB, R2013b, so you must have that version in order to get good results. Fortunately, you can still get the R2013b release. All you need to do is go to the Mathworks site at: http://www.mathworks.com/downloads/select_release. Simply choose the R2013b release from the Download Earlier Release list after you have logged in. Please let me know if you have any questions or concerns at John@JohnMuellerBooks.com.

 

Developing Good Work Habits

Writing, like any kind of work, requires a certain amount of discipline. However, unlike many sorts of work, pounding away at the keyboard is only helpful when you have ideas to get onto paper (digital in most cases today, but the idea is the same as writing in the past). In order to become more productive, you must develop good work habits. Part of the task is to base your work habits on the kind of writing you do, your personality, and the requirement to get a certain amount of work done in a given time. It’s also important to consider your work environment.

I normally work a 12 to 14 hour work day, but I don’t spend all that time at the keyboard. My work day is split into one hour segments with 15 minute breaks. The day always begins with chores and breakfast for me. After all, everyone has to eat. During my first segment, I’ll answer e-mail, and then it’s usually time to take a break. I get some cleaning done or get the wood stove ready for the evening fire. The point is to get out of the office for 15 minutes so that I can rest, but also remain productive.

During the second segment I normally write as much text as I can. Sometimes this means pressing pretty hard in order to get the task done, but you need words on paper to move forward. Last week’s post mentioned some ways in which I get the job done. This segment usually goes by so fast that it seems as if I’m just starting when my timer goes off. Yes, I use a timer on my computer to keep a routine in place. Pacing yourself is important. At the end of the second segment it’s usually time to check the chickens and get any eggs they’ve laid. A walk outside is nice too. Sometimes I play Frisbee with the dogs or do some cleaning or even just enjoy some sunshine while I read the newspaper.

The third segment sees me editing the text I’ve written during the second segment and augmenting it. I usually end up with half again the number of pages that I had at the end of the second segment. The point is that the book has advanced, but that the text is also in better shape by the end of the third segment.

Depending on how everything has gone, I can sometimes fit in a fourth segment that I use to research new book material. I write ideas for the current chapter directly into the remaining blank spots so that I can start working on them immediately after lunch.

Lunch is an hour long. Afterward, I check on the animals again, check out the orchards and gardens as needed, and generally get things cleaned up. You’ll notice I do a lot of little cleaning segments during the day. For me, it’s better than trying to clean the entire house all in one fell swoop. Plus, I like a clean environment in which to work, some people actually do work better in clutter. There isn’t any right or wrong to the question of environment, just what works for you.

The rest of the day goes pretty much like the first part of the day went. I’ll have a robust writing segment after lunch, followed by an editing segment, followed by a research segment. It may seem mundane and potentially quite boring, but it’s an efficient way for me to work. Of course, you have to come up with your own routine—whatever seems to work for you. Keep trying different ways to approaching your writing until you come up with an approach that’s both efficient and rewarding. Yes, I’m quite tired by the end of the day, but I also feel quite happy with what I’ve gotten done. Let me know your ideas on writing workflow at John@JohnMuellerBooks.com.

 

Spring and Happy Chickens!

It’s getting toward spring and my chickens are definitely happy about it. I’ve discussed winter egg laying beforeproduction really does decrease. This is the point in the year where things start to turn around. My twelve birds really have become much happier and are now starting to lay six eggs on average per day. Some of those eggs still have calcium nodules, but I’m finding that even the number of calcium nodules is decreasing. The point is that they’re laying more eggs. Of course, this is the human view of happiness.

The chicken view of happiness is different. I can let the chickens out on most days now. When I enter the coop in the morning, I put down their food and then open the coop door. Now, you’d think the chickens would eat breakfast first and then run out of the coop. However, that isn’t what happens. They forget all about the food and fight each other to get out of that door designed for two birds at most as quickly as possible. It really is quite insane looking. They go out and stand around the water bucket discussing chicken events of the day (not that I quite know what to think of their discussions).

Of course, there is always an exception. Violet, the oldest chicken in the coop, just watches the fracas bemused, waits to be petted, and then calmly enjoys the quiet while she eats breakfast without the jostling of other birds to contend with. It’s hard to believe that chickens can become wiser with age, but somehow it happens. This old bird has gotten set in her ways over the years and many a fledgling has felt her beak where the feathers are fewest. Just watching my chickens each day reminds me of how individuals appear in every environment and that the need for individuality is universal. Let me know your thoughts on chickens with wisdom at John@JohnMuellerBooks.com.