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
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]]'
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!
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.
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
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
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.
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)
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.
# 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)
# 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)
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!
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.
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.
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.
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",
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.
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.
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
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.
This app password
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.
cd /path/to/repo.git
sudo chgrp -R {groupname} .
sudo chmod -R g+rwX .
find . -type d -exec chmod g+s '{}' +
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.