No symlink in zsh with venv

The problem:

Unable to symlink '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3' to '/Users/mcadams/Documents/ ... /env/bin/python3'

This is, I think, an issue with the new Z shell (zsh) in MacOS Catalina. What I had attempted was my usual virtualenv command, at the bash prompt:

python3 -m venv env

That gave me the “Unable to symlink” pain. So I opened my .zshrc file with nano and added this line:

export PATH="/usr/local/opt/python/libexec/bin:/usr/local/bin:$PATH"

THIS FIXED NOTHING.

So then I changed the command to:

python3.8 -m venv env

And it worked. source env/bin/activate and I was in my new env, just like normal.

If you aren’t sure which Python 3 version you’ve got, type: python3 --version and you’ll find out. Note again, this is MacOS, not Windows.

Changing the prompt in zsh

In Mac OS 10.15 Catalina and later, the default shell in Terminal is zsh instead of bash. This is fine. All I wanted to do was change the command prompt in zsh. This is not difficult, but it was damned hard to find out exactly how to do it without installing a theme and using Homebrew and a thousand other things I didn’t want to do.

So here’s how to just change the prompt and nothing else.

The default prompt in zsh is like this:

mcadams@Mindys-MacBook-Air ~ %

What I like is to keep my username (mcadams), get rid of the machine name (Mindys-MacBook-Air), and add the name of the current directory. So if I’m in Documents/python/scraping, I want the prompt to look like this:

mcadams scraping %

Note that the % sign is the prompt character in zsh, not $ as in bash.

First, you might like to play around with the prompt you want by just testing things before you write your final choice into the .zshrc file. If you do write it into the file and you don’t like it, you can change it later.

This article was a big help to me: Customizing the zsh Prompt.

To test out the modified prompt shown above, in Terminal, type or paste this:

PROMPT='%n %1d %# '

If you’d rather have the dollar sign instead of the percent sign, try this:

PROMPT='%n %1d $ '

If you’d like to make the zsh prompt a different color:

PROMPT='%F{yellow}%n %1d $ %f'

There’s a limited list of color words we can use, but 256 colors are available by number. Just change the word yellow to a number from the “Xterm Number” column there.

Once you’ve hit on a prompt you love, you need to add it to the .zshrc file in your user directory. The file might not exist yet. That’s okay. First, make sure you’re in your user directory and not elsewhere:

cd

Press Return. Then type:

nano .zshrc

You’re in the nano text editor now. Copy and paste or type the line that makes the prompt you desire, such as:

PROMPT='%F{yellow}%n %1d $ %f'

If there’s already something in the file, just add that line at the bottom. Then, two steps:

  1. Control O (that’s an uppercase letter O) to write out the changes.
  2. Control X to quit nano.

You will not see the new prompt until you open a new Terminal window.

I also found this longer article helpful: Zsh (Z shell on MacOS).

Better form processing with fetch()

I finally put the time in and wrestled with the JavaScript fetch() API until I understood it well.

Here’s the script.

I also learned how to use the FormData constructor to easily grab all the values from an HTML form on submission. Same script. This is something I used to do with jQuery’s $( this ).serialize().

Data science

Data science is recognized as a field distinct from computer science; it has been called “the child of statistics and computer science” (Blei & Smyth, 2017, p. 8689 doi: 10.1073/pnas.1702076114).

Many universities have whipped up degree programs in data science. I’ve searched and examined a lot of the curricula, and my favorite is the master’s program at the University of San Francisco, because it seems very comprehensive, and the faculty have solid credentials.

There’s a block of “foundation courses” from which students must complete two:

  • MSDS 501 – Computation for Analytics
  • MSDS 502 – Review of Linear Algebra
  • MSDS 504 – Review Probability and Stats

Then there are 33 units of required courses:

  • MSDS 593 – EDA and Visualization
  • MSDS 601 – Linear Regression Analysis
  • MSDS 603 – Product Analytics
  • MSDS 604 – Time Series Analysis
  • MSDS 605 – Practicum I
  • MSDS 610 – Communications for Analytics
  • MSDS 621 – Intro to Machine Learning
  • MSDS 625 – Practicum II
  • MSDS 626 – Case Studies in Data Science
  • MSDS 627 – Practicum III
  • MSDS 629 – Experiments in Data Science
  • MSDS 630 – Advanced Machine Learning
  • MSDS 631 – Special Topics in Analytics
  • MSDS 632 – Practicum IV
  • MSDS 633 – Ethics in Data Science
  • MSDS 689 – Data Structures and Algorithms
  • MSDS 691 – Relational Databases
  • MSDS 692 – Data Acquisition
  • MSDS 694 – Distributed Computing
  • MSDS 697 – Distributed Data Systems
  • MSDS 699 – Machine Learning Laboratory

In addition, students must attend seminars and take 10 hours of interview skills training.

This is a one-year full-time residential program that includes 15 hours/week of practicum for nine months of the program.

Some of the things that most impress me about the curriculum:

  • Three courses on machine learning
  • A course devoted to ethics
  • A course on exploratory data analysis and visualization
  • The 2-unit course on data acquisition focuses on web scraping with Python (check out the course description for this!)
  • A communications course for learning how to present data to clients and stakeholders
  • Use of both R and Python; omission of unnecessary programming languages
  • A course on SQL databases and a separate course on MongoDB
  • A course on conducting experiments

I have no stake in this master’s degree program (in fact I work at a different university in another state), but when I’ve looked at other programs with “data science” in the title, I’ve concluded that most do not compare favorably with this one.

Mainly I am interested in the intersection of journalism and data science, so I’m continually making comparisons between data-focused journalism projects and the work of data scientists.

Related post: Python, data work, and O’Reilly books

Packaging apps

This is a summary of a news nerds discussion in early November 2019.

  • Grunt and Gulp are old news, although still used.
  • Webpack is difficult but widely used.
  • Rollup is simpler than Webpack, and good.
  • Microbundle is even easier than Rollup, and suitable for smaller modules.
  • The Airbnb JavaScript Style Guide is opinionated but useful for establishing and following conventions.

A long but clear explanation of the whole module-bundling process is Modern JavaScript Explained For Dinosaurs (2017).