Category: TroubleShooting

[Trouble Shooting] NullFunctionError of glutInit in OpenGL

Problem

When trying to call “glutInit()” of PyOpenGL, I got the error “NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling”.

# python source code
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

glutInit()
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) 
 
Error Detail

---------------------------------------------------------------------------
NullFunctionError                         Traceback (most recent call last)
/tmp/ipykernel_14/3289264930.py in <module>
      3 from OpenGL.GLU import *
      4 
----> 5 glutInit()
      6 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)
      7 

/usr/local/lib/python3.9/site-packages/OpenGL/GLUT/special.py in glutInit(*args)
    331     try:
    332         # XXX need to check for error condition here...
--> 333         _base_glutInit( ctypes.byref(count), holder )
    334     finally:
    335         os.chdir( currentDirectory )

/usr/local/lib/python3.9/site-packages/OpenGL/platform/baseplatform.py in __call__(self, *args, **named)
    421                 pass
    422             else:
--> 423                 raise error.NullFunctionError(
    424                     """Attempt to call an undefined function %s, check for bool(%s) before calling"""%(
    425                         self.__name__, self.__name__,

NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

Environment

Windows10
Python 3.9.7

Cause

There are some Recommended Enhancements for PyOpenGL. And some of them, such as GLUT or FreeGLUT, are not contained in PyOpenGL itself.

Solution

Solution1 use binary installer for windows.

The documentation says “Win32 and Win64 binary installers for PyOpenGL include a copy of GLUT”.
So uninstall current pyopengl first.
And download binary installer for windows. Put the downloaded file in some directory, then run the command “pip install <file name>” in the directory where the file is saved.

pip uninstall PyOpenGL
pip install PyOpenGL‑3.1.6‑cp39‑cp39‑win_amd64.whl

Solution2 install GLUT or FreeGLUT separately

Installing and adding GLUT or FreeGLUT to PATH solves this problem.

Build FreeGLUT from source code or download built FreeGLUT from “Download freeglut 3.0.0 for MSVC” in transmissionzero.co.uk/software/freeglut-devel.

Put freeglut\bin\x64\freeglut.dll into C:\Windows\System32.

Add “C:\Windows\System32” to environment variable “PATH” to enable python find the library.

If the error still occurred, check if your library name is in Win32Platform.GLUT() <python>\Lib\site-packages\OpenGL\platform\win32.py

    @baseplatform.lazy_property
    def GLUT( self ):
        for possible in ('freeglut%s.%s'%(size,vc,), 'freeglut', 'glut%s.%s'%(size,vc,)):  # Added 'freeglut' because the library name is freeglut.dll
            # Prefer FreeGLUT if the user has installed it, fallback to the included 
            # GLUT if it is installed
            try:
                return ctypesloader.loadLibrary(
                    ctypes.windll, possible, mode = ctypes.RTLD_GLOBAL
                )
            except WindowsError:
                pass
        return None

These links might help you.
python – Attempt to call an undefined function glutInit
#219 glutInit fails on windows 64-bit
Attempt to call an undefined function glutInit
Python and PyOpenGL Installation

Appendix: How to install GLUT or FreeGLUT on Linux

Use “sudo apt-get install python-opengl” command to install PyOpenGL with dependent library at once.

Error “Docker.ApiServices.WSL2.WslKernelUpdateNotInstalledException”

This is a trouble shooting log.

Problem

I downloaded the installer of Docker-Desktop from download page here. And executed the installer and start Docker. Then the error was displayed after starting Docker-Desktop.

Cause

Let’s see the window behind the exception window by Microsoft .NET Framework.

The WSL 2 Linux kernel is now installed using a separate MSI update package.
Please click the link and follow the instructions to install the kernel update:
http://aka.ms/wsl2kernel.

Press Restart after installing the Linux kernel.

That’s the cause of the error. We should install “WSL 2” by ourselves now.

Solution

Install WSL 2 Linux kernel whose installer is in http://aka.ms/wsl2kernel.

from wsl_update_x64.msi

After installing WSL 2, restart the Docker-Desktop.

The window displayed when started successfully

[Trouble Shooting] Cannot Use Library In Jupyter Notebook

Environment

Python 3.8.4
pip 20.1.1

Problem

I installed “matblotlib” by using pip3 command on the terminal as below. I can import matplotlib on the terminal.

% pip3 install matplotlib 
% python3
Python 3.8.4 (default, Jul 14 2020, 02:58:48) 
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> 

In jupyter notebook,

import matplotlib
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-0484cd13f94d> in <module>
----> 1 import matplotlib

ModuleNotFoundError: No module named 'matplotlib'

Check the situation

The reference path for jupyter notebook might differ from the one of host python3.

Jupyter notebook refers the python 3.8 in jupyterlab/2.2.0/libexec/lib

import sys
print(sys.version)
print(sys.path)

3.8.4 (default, Jul 14 2020, 02:58:48) 
[Clang 11.0.3 (clang-1103.0.32.62)]
['/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python38.zip', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8/lib-dynload', '/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8', '', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8/site-packages', '/usr/local/Cellar/jupyterlab/2.2.0/libexec/lib/python3.8/site-packages/IPython/extensions', '/Users/<username>/.ipython']

On terminal, Python3 is in /usr/local/Cellar.

>>> import sys
>>> print(sys.version)
>>> print(sys.path)

3.8.4 (default, Jul 14 2020, 02:58:48) 
[Clang 11.0.3 (clang-1103.0.32.62)]

['', '/usr/local/Cellar/python@3.8/3.8.4/Frameworks/Python.framework/Versions/3.8/lib/python38.zip', '/usr/local/Cellar/python@3.8/3.8.4/Frameworks/Python.framework/Versions/3.8/lib/python3.8', '/usr/local/Cellar/python@3.8/3.8.4/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload', '/usr/local/lib/python3.8/site-packages']

Cause

In my case, the problem caused by homebrew. Installation of Jupyter Lab or Jupyter Notebook with brew command caused the different reference to python3 as above.

We can check the list of installed items with the following command on the terminal.

% brew list
autoconf	ipython		openssl@1.1	python@3.8	xz
flake8		jupyterlab	pandoc		readline	zeromq
gdbm		libyaml		perl		ruby
gettext		lua		pkg-config	sqlite
icu4c		node		pyenv		vim

Solution

My solutions is to uninstall jupyterlab with brew command and install it again with pip3.

% brew uninstall jupyterlab
Uninstalling /usr/local/Cellar/jupyterlab/2.2.0... (7,150 files, 106.8MB)

% python3 -m pip install jupyterlab
Collecting jupyterlab
  Downloading jupyterlab-3.1.7-py3-none-any.whl (8.5 MB)
     |████████████████████████████████| 8.5 MB 136 kB/s 
...

Start Jupyter Lab from the terminal.

% jupyter lab

I found another it could be a solution for similar problem to install ipykernel. Check ModuleNotFound Error for matplotlib for detail.

[Trouble Shooting] error “fatal: refusing to merge unrelated histories” in Git

Problem

When I tried to pull from remote repository, the error “fatal: refusing to merge unrelated histories” occurred. How can I solve it?

$ git pull origin main
warning: no common commits
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/s-nako/ColorSelector
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main
fatal: refusing to merge unrelated histories

Cause

This error occurs because “pull” command is targeted for 2 branches that has same root. In my case, remote main was generated on GItHub and local main was generated in local directory by “git init”.

Solution

Use “–allow-unrelated-histories” option for pull command as below.

$ git pull origin main --allow-unrelated-histories
From https://github.com/s-nako/ColorSelector
 * branch            main       -> FETCH_HEAD
Merge made by the 'recursive' strategy.
 README.md | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 README.md

How To Fix Texture Colored Pink In Blender

Problem

When I open Blender file, the textured model is rendered with pink single-colored texture. How can I fix it?

Texture node on Node Editor

Environment

Blender 2.8.3(LTS)
Windows10

Cause

Pink means missing texture. Blender couldn’t find the specified texture.

Solution

References: You can find solutions in the followings in most cases.
Why are all the textures in my file pink?
Pink textures in Blender and how to avoid them

However, this sometimes occurred when the texture is just overwritten. In that case, I fixed by following steps below.

1. Disconnect Image Texture Node from Base Color socket of Shader Node.

2. Reset texture in Image Texture Node on Node Editor

3. Reconnect Nodes

Rotate and Scale Don’t Work in Blender

This is trouble shooting.

Problem

I couldn’t resize or rotate widget in Blender.

example) expanding box in the x-axis direction

Environment

Blender 2.83
Windows 10

Check List

Affect Only check box

If the Options > Affect Only > Locations checkbox is on, check it off.

Transform is rocked

If the Rotation and Scale are rocked, the arrows to resize or rotate are not displayed.

How To Use Keymap Preference in Blender

The system of keymap preference in Blender is complex a little.

GOAL

Today’s goal is to summarize how to customize keymaps in Blender. The main contents are how to change keymaps, save and import/export key configuration presets. This article doesn’t contain how to use keymap editor or details of UI.

Environment

Blender 2.83 (Python 3.7.4)
Windows 10

What is keymap preference?

The following is an excerpt from the Blender manual.

The keymap editor lets you adjust your keymap via:

Presets: Predefined keymaps which come with Blender and can be added to.
Preferences: Keymaps may define their own preferences to change the functionality or add additional key bindings.
Key Map Items: You may add/remove/edit individual keymap entries.

from “Keymap” in Blender 2.92 Manual

How to change keymap

Keymaps can be changed in each keymap editor.

(more…)

[AttributeError] module ‘tensorflow’ has no attribute ‘Session’

When I was trying the exercise of TensorFlow Programming Concepts, an error “AttributeError module ‘tensorflow’ has no attribute ‘Session'” occurred.

Error Detail

The code run in Google Colaboratory is the following.Generic HighlightingEnlighterJS Syntax Highlighter

This image has an empty alt attribute; its file name is 38dbab30e4232a9115cd0f972a88d428.png
An attribute error

Cause

tf.Session can be used in tensorflow 1.x version, while it cannot be used in 2.x version.

(more…)

[error]CreateProcess error=2, The system cannot find the file specified in PyCharm

Error Detail

When I try to run python in PyCharm. The error occurred as below. What is venv\Scripts\python.exe?

Error running 'easy_keymaps_ui': Cannot run program "C:\Users\<USER_NAME>\source\test\venv\Scripts\python.exe" (in directory "C:\Users\<USER_NAME>\source\test"): CreateProcess error=2, The system cannot find the file specified

Environment

Windows 10
PyCharm 2020.3
Python 3.8

Cause

The python specified to use as interpreter in PyCharm cannot be found. In my case, the specified python is python that is bundled to the deleted virtual env of PyCharm project.
Check “Configure a virtual environment” for details about virtual env of PyCharm.

Solution

Change the python to use

Right click the program to run. And click “Modify Run Configuratuib…”

Select valid interpreter and click ”OK”.

How to remove and add python interpreters to the project

Open “File > Settings > Python Interpreter”. Click the gear icon and click “Show All” button.

Click “-” button to delete invalid Python.

And click “+” button to add new valid python to use to run python program. I selected my local system python.