Intel MKL FATAL ERROR

Last August, I got a new system from the office and I took this opportunity to upgrade my python 3.5 to python 3.7.

Everything was working fine except for this error

(py37) C:\Users\Sukhbinder\Desktop\Projects\fill_in_the_blanks>fillin -h
Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll.

I searched for mkl_intel_thread.dll and could see them in the correct env folder. Many in StackOverflow advised moving the dll one folder up. Since this was an office laptop, I did not have the option of moving Dll. So I was stuck.

After a few more google searches and trial and error, I Solved the problem by just doing this.

conda install cython

After the cython install all dll’s were in the proper place.

I have seen this dll problem come up so often, that its worth knowing this solution.

Snake and the Saw

My daughter’s English teacher has a habit of sending moral stories to her students.

I have heard most of them, some I have shared here in this blog.

Her latest story which I have not heard before is about snake and a saw. Liked it enough to post it here.

One night a snake, looking for food, entered a carpenter’s workshop. The carpenter, who was a rather untidy man, had left several of his tools lying on the floor. One of them was a saw.

As the snake went round and round the shop, it climbed over the saw, which gave it a little cut. At once, thinking that the saw was attacking it, the snake turned around and bit it so hard that its mouth started to bleed. This made the snake very angry. So the snake decided to roll around the saw as if wanting to suffocate it with his whole body. As the snake squeezed the saw the snake got hurt even more. Because of that, the snake thought it had to attack harder so it squeezed even more. This went on until one of them lost the battle.

Moral of the story:

Sometimes in life, it is better to ignore certain situations that arise, the insults and wrongdoings people say and do to you. Because fighting every “battle” you are provoked with will not help you live a successful and happy life. Some battles will take much more from you than you will get from them if you win them.

Do you know any such story? Do share in comments.

4-7-8

This was one of the forwards from the HR team when the pandemic started for everyone’s well being.

4-7-8 Breathing technique to calm your mind. It was cool and just for the sake of it, did develop a mini-app in python that helps do this from command line.

Here’s a demo.

Works in windows, Linux and Mac.

As always, code available on github

Distributing python code without the code

Most of the distribution of python code happens through wheels.

They are self-contained and follow a common pattern which helps the distribution of python code a non-issue.

But if you want to somehow obscure code and do not want a casual person to view the code making a wheel with pyc code could be an option.

By default when a wheel is created, the actual py files are included in the wheel. This means anyone can hunt down to the site-packages and check the code.

If you want to prevent this, creating a wheel just with a pyc file could be an option. Here’s a batch script that I use to do the same.

@echo off
python setup.py build
cd build
python -m compileall -q -b -r 3 lib
del /s /f /q lib\*.py > t.txt
del t.txt
cd ..
python setup.py bdist_wheel --skip-build

You should be mindful that doing this means that the wheel will only work on pc with similar architecture and python. If there is a change in the target environment, the wheel will fail.

Paper Ships

“If you love to read, or learn to love reading, you will have an amazing life. Period. Life will always have hardships, pressure, and incredibly annoying people, but books will make it all worthwhile. In books, you will find your North Star, and you will find you, which is why you are here.

Books are paper ships, to all the worlds, to ancient Egypt, outer space, eternity, into the childhood of your favorite musician, and — the most precious stunning journey of all — into your own heart, your own family, your own history and future and body.

Out of these flat almost two-dimensional boxes of paper will spring mountains, lions, concerts, galaxies, heroes. You will meet people who have been all but destroyed, who have risen up and will bring you with them. Books and stories are medicine, plaster casts for broken lives and hearts, slings for weakened spirits. And in reading, you will laugh harder than you ever imagined laughing, and this will be magic, heaven, and salvation. I promise.”

Source: A Velocity of Being: Letters to A Young Reader by Anne Lamott

Taking a Break with Schtasks

Taking a break from the computer has become essential in this WFH environment. In the office, it was natural and happened often but at home, this is not the case.

I have tried many things.

Setting up a timer that is displayed on my desktop to remind me to take a break. This failed as resetting the countdown timer every time added the friction to render the whole exercise fruitless

Then I tried to use the outlook calendar to remind me to take a break.

This failed as slowly the calendar reminders were ignored.

Both of these approaches failed.

Needed something more visual. So this is my current setup. All done using standard available tools.

No software or installation required.

schtasks /create /tn take_a_break /sc HOURLY /mo 2 /st 08:30 /et 18:00 /tr "https://large-type.com/#Take%20a%20Break"

Every 2 hours it launches the default browser with the big fonts telling me to take a break. Much more intuitive and useful than anything I have tried earlier.

Another beauty of the system is that if this doesn’t get me started, I can configure this to lock my screen at that moment. A slight inconvenience but something that I will try if this big pop up doesn’t work.

How do you deal with this?

Intense Ideology

“Another thing I think should be avoided is extremely intense ideology because it cabbages up one’s mind. … When you’re young it’s easy to drift into loyalties and when you announce that you’re a loyal member and you start shouting the orthodox ideology out, what you’re doing is pounding it in, pounding it in, and you’re gradually ruining your mind.”

Charlie Munger – USC Law Commencement Speech, May 2007

This constant pounding leads the stories you are telling yourself.

As Richard Feynman said.

How to Install and Use the Django Expense App

A cousin of mine wanted to use the Django-expense app that I shared a few weeks back, so here are the instructions I sent him.

Step 0:
Get python

Step 1:
Install the required modules using the below requirement.txt

asgiref==3.3.1
cycler==0.10.0
Django==3.1.7
git+https://github.com/sukhbinder/django-exp.git@b699077cc0846dbe40dfd1b2a17c1c164d1bc0aa#egg=django_exp
djangorestframework==3.12.2
et-xmlfile==1.0.1
kiwisolver==1.3.1
matplotlib==3.2.0
numpy==1.20.1
openpyxl==3.0.7
pandas==1.2.3
Pillow==8.1.2
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2021.1
six==1.15.0
sqlparse==0.4.1
xlrd==2.0.1

pip install -f requirements.txt

Step 2:
Create a new Django project

django-admin startproject expensesite

expensesite can be any name you want to call the website

cd expensesite

Step 3:

In the settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Add these two lines
    'rest_framework',
    'exp',
]

Step 4:

python manage.py makemigrations
python manage.py migrate

Step 5:

python manage.py runserver

This should launch the website.

Code as always is available at my github repo

Deploying Django App with PythonAnywhere

Recently wanted to deploy a learning app I have developed for my kids on the web. The main reason behind this was to make the app accessible from anywhere and from any device.

This was necessitated by the our travel back to kids grandparents, where the laptop was not always online and on.

After research ( few google searches and blog reads…:) ) heroku and pythonanywhere.com were the two method that I settled on.

I have previous use heroku to deploy one of my previous app, so this time turned to pythonanywhere.com Heroku has ton of tutorials on how to deploy a python django app on heroku, but there were not many for pythonanywehere.com, so here’s a pictorial demo of the process I took.

Here’s an overview of the steps involved.

  1. Create an pythonanywhere account
  2. Upload your code to PythonAnywhere
  3. Set up a virtualenv and install Django and any other requirements
  4. Set up your web app using the manual config option
  5. Add any other setup (static files, environment variables etc)
Continue reading

How to Determine Memory usage of a Python Function

In enginnering software development or other software developement projects, most programmers are solving a problem and this always starts by writing a naive implementation and then optimizing it in various ways.

Many a times, instead of focusing on timing, we are also interested in memory usage so we can explore those tradeoffs of caching a table or re-computing as needed.

Fortunately python, with its batteries included philosophy has just the module that is needed to memory profile your code.

import tracemalloc

tracemalloc.start()

# Function to profile memory
call some_function()

snapshot = tracemalloc.take_snapshot()
snapshot.dump("trace_dump")
tracemalloc.stop()


And later this trace_dump can be queried as bellow

snapshot =tracemalloc.Snapshot.load("trace_dump")
 
snapshot.statistics("filename")

snapshot.statistics("lineno")

On Writing

Some of the things I think I think, I find don’t make any sense when I start trying to write them down. You ought to be able to explain why you’re taking the job you’re taking, why you’re making the investment you’re making, or whatever it may be. And if it can’t stand applying pencil to paper, you’d better think it through some more

Writing crystallises thinking than any thing else.

Determine if a given string is a URL

Recently while working on a side project in python and web, needed to find if a string is a url or not?

Here’s a solution using python standard library

from from urllib.parse import urlparse

def is_url(text):
    parsed = urlparse(text)
    if (parsed.scheme) and (parsed.netloc):
        return True
    else:
        return False

if __name__ == "__main__":
    print(is_url("http://www.google.com"))

Love this simple small snippets using the standard library. Do you know of such a hidden gem?

Others

This is something that is still the same.

When the Black Death plague entered England in 1348, the Scots up north laughed at their good fortune. With the English crippled by disease, now was a perfect time for Scotland to stage an attack on its neighbor.

The Scots huddled together thousands of troops in preparation for battle. Which, of course, is the worst possible move during a pandemic.

“Before they could move, the savage mortality fell upon them too, scattering some in death and the rest in panic,” historian Barbara Tuchman writes in her book A Distant Mirror.

There’s a powerful urge to think risk is something that happens to other people. Other people get unlucky, other people make dumb decisions, other people get swayed by the seduction of greed and fear. But youMe? No, never us. False confidence makes the eventual reality all the more shocking.

Some are more susceptible to risk than others, but no one is exempt from being humbled.

Via this

Managing Housing Society Expenses

Last summer, while in home quarantine, received an update from the housing society committee on the general group, that nominations are invited for new managing committee. I ignored it. Come September, learnt that many ignored the same and now by way of a lottery system I was one of the chosen few to take up a role in the managing committee.


This is how I landed the job of the Treasurer of the housing society. The responsibilities sounded simple when it was explained but in practice it proved too much work.

Ad-hoc expenses, regular expenses. It was hard to manage. The only advise I received from the leaving Treasurer was, record the expense as soon as you incur it.


I bought a diary and started doing this but it became evident that recording expenses in diary and then transferring it to an excel sheet will be time consuming. The volume and variety of expenses from various sources overwhelmed my paper based system.

This is the problem that was beckoning to be solved and I turned to python.


Here’s the result of the solution.

Developed a Django webapp that can be accessed from anywhere, on any of my devices. The web app allows not only allows adding expenses but also shows and consolidate the expenses.


It was fun experience building this. The site is solely used by me now and has made logging of expenses straight forward. Solving this, turned my attention to another problem that had bigger time-toll in my duties as treasurer, but that’s a topic for another post.

The Hardest Financial Skill

The hardest financial skill is getting the goalpost to stop moving.

If expectations rise with results there is no logic in striving for more because you’ll feel the same after putting in extra effort. It gets dangerous when the taste of having more—more money, more power, more prestige—increases ambition faster than satisfaction

Modern capitalism is a pro at two things: generating wealth and generating envy. Perhaps they go hand in hand; wanting to surpass your peers can be the fuel of hard work. But life isn’t any fun without a sense of enough.

Happiness, as it’s said, is just results minus expectations.

From the book Psychology of Money by Morgan Housel