Nono.MA

FEBRUARY 14, 2024

I kept seeing this error when creating a new Yarn Modern project—setting Yarn to the latest version with yarn set version stable—and using the yarn init command.

Usage Error: The nearest package directory doesn't seem part of the project declared in […]

For instance, yarn add -D @types/node wouldn't work.

The fix

There was a package.json and a yarn.lock file in my home directory.

Removing the file fixed the issue.

rm ~/package.json ~/yarn.lock

Create a Yarn Modern project

Then, in any directory, even subfolders of your home directory (~) you can create new yarn projects.

mkdir app && cd app
yarn init -y
yarn add -D @types/node

Doing It Right

When you run yarn set version stable, Yarn Modern creates a package.json with the packageManager property set to the latest stable version of Yarn, such as 4.1.0.

To avoid the above issue, you should first create your project.

yarn create vite my-app --template react-swc-ts

Then, enter the app's directory and only then set the desired Yarn version.

cd my-app
yarn set version stable
yarn
# Yarn Modern will be used here.

FEBRUARY 12, 2024

After I put my M1 MacBook Pro to sleep for a couple of weeks, it woke up with the wrong date and time, set to around two years before the current date.

Here's what fixed it for me.

Open a Terminal window and run the following command.

sudo sntp -sS time.apple.com

This will trigger a time sync with the actual date and time from Apple's clock. But it won't completely fix the issue. If you close the lid and reopen your laptop, the time will return to the wrong time.

After you run the command above, you have to do the following.

  • Open System SettingsGeneralDate & Time
  • Disable Set time and date automatically
  • Enable Set time and delete automatically

That's it. This permanently fixed the issue for me.


If you found this useful, let me know!

NOVEMBER 9, 2023

After upgrading your Mac to macOS Sonoma, you may have encountered this issue with Canon's IJ Scan Utility2, a known issue up to version 2.4.0. In my case, I'm using the Canon CanoScan LiDE 220. But the same software works with LiDE 300 and 400.

An internal error has occurred. Take the following measures.
- Check the scanner status.
- Restart the scanner.
- Restart the computer, then try again.
- Reinstall the scanner driver.

Code:10,202,3

Canon CanoScan LiDE 220

You can Download the latest software on Canon's website—including the IJ Scan Utility2 2.4.1and the ICA Driver Ver.5.0.0—which add macOS Sonoma compatibility.

  • Go to Software & Drivers
  • Set the Operating System to Mac (detected)
  • Set the Version to macOS Sonoma v14
  • Download and install IJ Scan Utility2 Ver.2.4.1 (Mac) (25.42 MB)
  • Download and install ICA Driver Ver.5.0.0 (Mac) (4.71 MB)
  • Download and install ScanGear Starter EX Ver.1.2.0 (Mac) (5.47 MB)

Other scanners

Where to buy

LAST UPDATED DECEMBER 12, 2023

I was running cron jobs that worked with macOS Mojave, Catalina, Big Sur, Monterey, and Ventura but stopped working after I updated to macOS Sonoma.

Here are two sample errors.

ls: .: Operation not permitted
zip error: Nothing to do! (try: zip -qr9 ~/folder/file.zip . -i *)

An "Operation not permitted" error message when running a cron job on macOS typically signals a permission issue.

Fix: Provide Full Disk Access to cron

cron requires the proper permissions to access other commands.

You'll need to grant "Full Disk Access" to cron or to the Terminal app to ensure it can execute jobs properly in macOS Sonoma.

Here's how.

  • Go to System Settings > Privacy & Security > Privacy section.
  • If required, unlock the settings by clicking the padlock at the bottom and entering your password.
  • Select Full Disk Access from the sidebar.
  • Navigate to the /usr/sbin folder with Finder. (You can do that with CMD + SHIFT + G and entering the path.)
  • Select the cron app binary.

ChatGPT helped me get to a solution faster.

JULY 20, 2023

If you're trying to run a Bash script and get a Permission Denied error, it's probably because you don't have the rights to execute it.

Let's check that's true.

# Get the current file permissions.
stat -f %A script.sh
# 644

With 644, the user owner can read and write but not execute.1

Set the permissions to 755 to fix the issue.

chmod 755 script.sh

  1. Chmod 644. CHMOD Calculator. 

NOVEMBER 12, 2022

If you try to serialize a NumPy array to JSON in Python, you'll get the error below.

TypeError: Object of type ndarray is not JSON serializable

Luckily, NumPy has a built-in method to convert one- or multi-dimensional arrays to lists, which are in turn JSON serializable.

import numpy as np
import json

# Define your NumPy array
arr = np.array([[100,200],[300,400]])

# Convert the array to list
arr_as_list = arr.tolist()

# Serialize as JSON
json.dumps(arr_as_list)
# '[[100, 200], [300, 400]]'

OCTOBER 27, 2022

I encountered the following error while trying to run a Python script and import TensorFlow Lite 2.10.0 runtime's interpreter, i.e., tflite_runtime.interpreter.

python -c "from tflite_runtime.interpreter import Interpreter; print(Interpreter)"
# ImportError: /lib64/libm.so.6: version `GLIBC_2.27' not found
# (required by /var/lang/lib/python3.8/site-packages/tflite_runtime/_pywrap_tensorflow_interpreter_wrapper.so)

As of October 25, 2022, tflite-runtime versions 2.8.0, 2.9.1, and 2.10.0 return the same error.

The issue was solved by downgrading to tflite-runtime version 2.7.0.

python -c "from tflite_runtime.interpreter import Interpreter; print(Interpreter)"
# <class 'tflite_runtime.interpreter.Interpreter'>

I haven't found a way to make tflite-runtime 2.10.0 work. If you do, please let me know!

SEPTEMBER 9, 2022

Today, I got the first kernel panic on my new Mac machine running macOS Monterey.

panic(cpu 3 caller 0xfffffe0022cf8a54): "Just destroyed an active LRU node!" @Lru.h:26

I don't have a solution, but a former laptop I bought, a 13-inch MacBook Pro (M1, 2020), had to replace the motherboard after running into successive kernel panics. I hope that's not the case this time.

JUNE 16, 2022

Today I tried to do this on my 13-inch MacBook Pro (M1, 2020).

conda create -n py2 python=2.7 -y

And I continue getting this error.

Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json,
will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available
from current channels:

  - python=2.7

Current channels:

  - https://conda.anaconda.org/conda-forge/osx-arm64
  - https://conda.anaconda.org/conda-forge/noarch

To search for alternate channels that may provide the conda
package you're looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

I can create environments with Python 3 versions without a problem though; say, Python 3.7, 3.8, or 3.9.

conda create -n py2 python=3.9 -y

APRIL 27, 2022

If we try to convert a literal string with decimal points—say, '123.456'—to an integer, we'll get this error.

>>> int('123.456') # Returns 123
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '123.456'

The solution is to convert the string literal into a float first and then convert it into an integer.

int(float('123.456')) # Returns 123

APRIL 2, 2022

I was getting this error when trying to git add and git commit code changes in my repository.

fatal: Unable to create '.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

Simply removing the .git/index.lock file made everything go back to normal.

rm .git/index.lock

Nothing broke and I could immediately add and commit new files.

MARCH 28, 2022

import boto3

# Create an S3 client
s3 = boto3.client('s3')

# Define your object's bucket and key
s3_bucket = 'bucket-name'
s3_key = 'file/key.txt'

# Read an object's HEAD
s3_object_head = s3.head_object(
    Bucket=s3_bucket,
    Key=s3_key,
)

# Get the object's size
s3_object_size = s3_object_head['ContentLength']
print(f'Size is {s3_object_size} bytes.')

This code will throw an error if the object at key s3_key doesn't exist in bucket s3_bucket.

An error occurred (404) when calling the HeadObject operation: Not Found

Here's how to catch and handle that error.

import boto3
import botocore.exceptions

# Create an S3 client
s3 = boto3.client('s3')

# Define your object's bucket and key
s3_bucket = 'bucket-name'
s3_key = 'file/key.txt'

try:
  # Read the object's HEAD
  s3_object_head = s3.head_object(
      Bucket=s3_bucket,
      Key=s3_key,
  )

  # Get the object's size
  s3_object_size = s3_object_head['ContentLength']
  print(f'Size is {s3_object_size} bytes.')
except botocore.exceptions.ClientError as error:
  # Handle s3.head_object error
  if error.response['Error']['Code'] == '404':
    print(f'S3 object not found at s3://{s3_bucket}/{s3_key}.')
  else:
    print(error)

JANUARY 31, 2022

The argparse.BooleanOptionalAction feature is only available in Python 3.9 and above.

If you try to run this code in Python 3.8 and below.

parser = argparse.ArgumentParser(
    description='Description of my argument parser.')
parser.add_argument(
    '-f',
    '--feature',
    action=argparse.BooleanOptionalAction,
    default=False,
    help='Description of your feature.',
)

You'll get this error.

python script.py              
Traceback (most recent call last):
  File "script.py", line 12, in <module>
    action=argparse.BooleanOptionalAction,
AttributeError: module 'argparse' has no attribute 'BooleanOptionalAction'

In Python 3.8, you can do the following.

parser = argparse.ArgumentParser(
    description='Description of my argument parser.')
parser.add_argument(
    '-f',
    '--feature',
    action='store_true',
    help='Description of your feature.',
)

Let's see a complete example of how you'd use the --feature flag or its -f shorthand.

Example for Python 3.9.

# Python 3.9
# script.py
#!/usr/bin/env python
# coding: utf-8
import argparse

parser = argparse.ArgumentParser(
    description='Description of my argument parser.')
parser.add_argument(
    '-f',
    '--feature',
    action=argparse.BooleanOptionalAction,
    default=False,
    help='Description of your feature.',
)
opt = parser.parse_args()
print(opt.feature)

Example for Python 3.8.

# Python 3.8
# script.py
#!/usr/bin/env python
# coding: utf-8
import argparse

parser = argparse.ArgumentParser(
    description='Description of my argument parser.')
parser.add_argument(
    '-f',
    '--feature',
    action='store_true',
    help='Description of your feature.',
)
opt = parser.parse_args()
print(opt.feature)

Running the program

Then, here's what's returned when the script is executed on the command line.

python script.py
# False

python script.py --feature
# True

python script.py -f
# True

I hope that helped!

JANUARY 24, 2022

I started seeing this warning after updating my version of phpMyAdmin.

The configuration file now needs a secret passphrase (blowfish_secret).

I had previously installed phpMyAdmin with Homebrew—brew install phpmyadmin—and could easily access its information with brew info phpmyadmin.

› brew info phpmyadmin | grep config
# The configuration file is /opt/homebrew/etc/phpmyadmin.config.inc.php

Opening that configuration file on your favorite code editor. You'll find this around line 12.

/opt/homebrew/etc/phpmyadmin.config.inc.php
/**
 * This is needed for cookie based authentication to encrypt password in
 * cookie. Needs to be 32 chars long.
 */
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

If you type a 32-character sequence by hand, e.g. AWdxXWoQrRCyqgmxDkpgBgljO4Wves, you may see the following message.

The secret passphrase in configuration (blowfish_secret) is too short.

Instead, you need 32 chars, which can be generated with the following command.

openssl rand -base64 32
# aMpXYTsPmvGm7GVNSwnH7SUU+agXXu1cIA77R4vcuP8=

Then add that as your blowfish_secret password.

/opt/homebrew/etc/phpmyadmin.config.inc.php
/**
 * This is needed for cookie based authentication to encrypt password in
 * cookie. Needs to be 32 chars long.
 */
$cfg['blowfish_secret'] = 'aMpXYTsPmvGm7GVNSwnH7SUU+agXXu1cIA77R4vcuP8='; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

The warning should now be gone.

NOVEMBER 18, 2021

I found this approach to install unzip on SageMaker Studio with yum in the Terminal.

sudo yum install -y unzip

Now you can use unzip --version to verify unzip is installed, and unzip file.zip to extract the contents of a compressed file.


An alternative approach which didn't work for me

Run the following command (note the bang!) inside of a Jupyter notebook or Python console in SageMaker Studio to install unzip.

!conda install -y -c conda-forge unzip

After running that command, I don't seem to be able to run unzip in Terminal yet.

OCTOBER 18, 2021

I found the following error while trying to execute PORT=4444 node ./bin/server.js on my Node.js application.

SyntaxError: Cannot use import statement outside a module

I solved it by adding the following into the package.json file of my NPM project.

  "type": "module",

SEPTEMBER 29, 2021

Nesting <a> HTML elements is forbidden. Here's an example:

<a href="https://nono.ma">
  Go to my website, or to my
  <a href="https://nono.ma/about">
    about page
  </a>.
</a>

A link to the about page is nested inside of a link to the root of this site.

SEPTEMBER 21, 2021

If you're trying to remove a directory using the os.rmdir function, but it contains other files, you'll probably hit the following error.

OSError: [Errno 66] Directory not empty:

You can ignore this error by using the shutil library instead of os.

import shutil
shutil.rmtree(path)

Note that Python won't prompt you to confirm this deletion action and this may lead to deleting files by mistake.

MAY 17, 2021

dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib
dyld: Library not loaded: /opt/homebrew/opt/icu4c/lib/libicuio.68.dylib
  Referenced from: /opt/homebrew/bin/php
  Reason: image not found
zsh: abort      composer

Install (or update) the Xcode developer tools.

xcode-select --install

Reinstall icu4c.

brew reinstall icu4c

Make sure no errors prevent Homebrew from installing icu4c properly. For instance, I had to remove a few php folders and re-run the brew reinstall icu4c command.

sudo rm -rf /opt/homebrew/Cellar/php@7.4/7.4.15
sudo rm -rf /opt/homebrew/Cellar/php/8.0.2

MAY 1, 2021

When you use two-factor authentication to sign in to your Gmail account (or to "Sign in with Google") you access your account with your email, password, and a verification code generated by Google Authenticator or other authenticator apps (such as Duo).

You might get an error like the one that follows when trying to sign in to Gmail with your Google password.

Authentication failed. Please check your username/password and Less Secure Apps access for mail@example.com.
Server returned error: "534-5.7.9 Application-specific password required. Learn more at 534 5.7.9 https://support.google.com/mail/?p=InvalidSecondFactor l25sm248619lfe.188 - gsmtp , code: 534"

When the service you're trying to use your Gmail account with doesn't allow you to "Sign in with Google," you need to create an app-specific password as detailed in the support Url provided by the error message.

Create a Google App Password

This app password

  • Go to your Google account
  • Security
  • Sign in to Google
  • App passwords
  • Choose the service type — e.g., Mail, Calendar, Contacts, YouTube, or Other (custom)
  • Choose the device type — e.g., iPhone, iPad, Mac, Windows, etc.
  • Generate

You'll get an app-specific password like this one — dbkdwckcplvgaktc — that will let you log in to the authorized service with your email and this password.

In my case, I use this password to be able to "Send as" from Gmail from an email address that has two-factor authentication turned on.

APRIL 20, 2021

cd /path/to/repo.git
sudo chgrp -R {groupname} .
sudo chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +

Source

JANUARY 13, 2021

I got this error while trying to pip3 install tensorflow. I tried python3 -m pip install tensorflow as well — it didn't work.

ERROR: Could not find a version that satisfies the requirement tensorflow
ERROR: No matching distribution found for tensorflow

As was my case, the reason for this error might be that you are using pip from a Python version not yet supported by any version of TensorFlow. I was running Python 3.9 and TensorFlow only had compatibility up to Python 3.8. By creating a new environment with Python 3.8 (or reverting the current environment to use 3.8) I could pip3 install tensorflow successfully.

Want to see older publications? Visit the archive.

Listen to Getting Simple .