Error detected while processing function jedi#init_python[11]..26_display_exception:

While using Vim in a Python virtual environment created using the venv module, this error pops up when opening a Python script:

Error detected while processing function jedi#init_python[11]..26_display_exception:
line 19:
Error: jedi-vim failed to initialize Python: jedi#setup_python_imports: ModuleNotFoundError: No module named ‘jedi’ (in function jedi#init_python[4]..26_init_python[27]..jedi#setup_python_imports, li
ne 27). See :messages and/or :JediDebugInfo for more information.

Let’s gather some information about the working environment:

Vim version:

:vers

VIM - Vi IMproved 8.1 (2018 May 18, compiled Mar 19 2020 13:12:18)
Included patches: 1-875, 878, 884, 948, 1046, 1365-1368, 1382, 1401

OS information:

cat /etc/os-release
NAME="Ubuntu"
VERSION="19.10 (Eoan Ermine)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 19.10"
VERSION_ID="19.10"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=eoan
UBUNTU_CODENAME=eoan

Current status of the jedi-vim plugin installation:

dpkg -l |grep vim-python-jedi

Package: vim-python-jedi
Version: 0.14.1-1
Priority: optional
Section: universe/python
Source: python-jedi
Origin: Ubuntu
Maintainer: Ubuntu Developers
Original-Maintainer: Piotr Ożarowski
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 117 kB
Depends: python3-jedi, vim-nox | vim-python
Recommends: vim-addon-manager
Homepage: https://github.com/davidhalter/jedi
Download-Size: 24.0 kB
APT-Manual-Installed: yes
APT-Sources: http://ca.archive.ubuntu.com/ubuntu eoan/universe amd64 Packages
Description: autocompletion tool for Python - VIM addon files
Jedi is an autocompletion tool for Python. It works. With and without
syntax errors. Sometimes it sucks, but that's normal in dynamic languages.
But it sucks less than other tools. It understands almost all of the basic
Python syntax elements including many builtins.
.
`vim-addons install python-jedi` will create all needed symlinks in
~/.vim/

Vim plugins using the OS package installer (for Debian/Ubuntu based distros) are handled by the vim-addons utility.

To list all the installed Vim plugins:

vim-addons list


editexisting
espeak
justify
matchit
python-jedi

The version provided by Ubuntu for jedi-vim is older than the latest one publicly available. For more details about the releases: jedi-vim releases

Since version 8, Vim has now a native plugins management.

For more details:


:h packages
:h package-create

To install the vanilla version of jedi-vim and have it available at Vim startup:


unzip -d jedi-vim ~/Downloads/jedi-vim-0.10.0.zip
mkdir -p ~/.vim/pack/vendor/start/jedi-vim
cp -rf jedi/vim/* ~/.vim/pack/vendor/start/jedi-vim/

~./vim/pack/vendor/start is the destination folder for any packages that contain plugins for Vim and automatically enabled at startup.

The plugin is now available and ready to be used in Vim.

If Vim is used in a Python virtual environment, the following error pops up:

jedi-vim: Error when loading the jedi python module (module ‘jedi’ has no attribute ‘__version__’). Please ensure that Jedi is installed correctly (see Installation in the README.

Furthermore, the Python code autocompletion feature provided by jedi-vim is not available in Vim.

2 options are available to fix this issue:

Either install the Python module jedi within the virtual environment using pip

Or re-create the virtual environment and enable access to the system site-packages dir (https://docs.python.org/3.7/library/venv.html) as follows:

python3 -m venv --system-site-packages my_new_env

Enable this new virtual environment:

cd $HOME/my_new_env

source bin/activate

python -c 'import jedi'

If there is anything wrong with loading this module:

Traceback (most recent call last):
File “”, line 1, in
ModuleNotFoundError: No module named ‘jedi’

This module will be picked up from the version installed using the OS package manager. For Ubuntu, jedi is provided by the python3-jedi package.

How to begin thinking like a programmer

Some notes regarding this video presentation of Andy Harris:

Youtube video: How to begin thinking like a programmer

Slides for this presentation

Programming is about:

  • Programming isn’t about languages
  • The language ultimately doesn’t matter much
  • There’s not a lot of memorizing
  • Most programming isn’t about math
  • Programming languages are simpler than human ones
  • Programming is really about solving problems
  • It’s about explaining things to the idiot computer

Coding isn’t about language is about:

  • Most beginners think they don’t understand what code to write
  • The real problem is they don’t really understand the problem they’re trying to solve

Failure is WONDERFUL

  • Did you tell it what to do incorrectly ?
  • Or did you tell it to do the wrong thing?
  • Most beginners assume it’s an implementation problem
  • Usually it’s really an algorithm problem

How to not go crazy

  • The art of teaching is knowing what NOT to teach
  • Learn it and do it before you learn something else
  • This is NOT a spectator sport
  • Teaching yourself means you have an amateur teacher
  • You don’t have to know everything

Please set the ICU_VERSION environment variable to the version of ICU you have installed.

This runtime error pop up while installing Python module dataset with pip in a virtual environment on a Linux VM running Ubuntu 18.04.1 LTS.

The dataset Python module requires several dependencies, pyicu being one of them.

As mentioned on the PyICU Github project webpage, this is a Python extension wrapping the ICU C++ libraries.

Using the apt-file tool, icu-config is provided by the libicu-dev Ubuntu package.

After installing it with the package manager, dataset Python module is now properly installed.

glib.error : g-io-error-quark : cannot autolaunch D-Bus without X11 $DISPLAY

To send simple notifications on your Linux desktop, pydbus can be used for such task.

PyDBus details

Pretty straightforward if you run it in a script from your shell.

If you need to automate it using cron, then 2 environment variables must be set :

import os
os.environ['DBUS_SESSION_BUS_ADDRESS'] = 'unix:path=/run/user/USERID/bus'
os.environ['DISPLAY'] = ':0'

You can tweak the example from the official Github repos for this project :

Send a desktop notification

From

from pydbus import SessionBus

bus = SessionBus()
notifications = bus.get('.Notifications')

notifications.Notify('test', 0, 'dialog-information', "Hello World!", "pydbus works :)", [], {}, 5000)

To

Send a desktop notification from Cron

from pydbus import SessionBus
import os
os.environ['DBUS_SESSION_BUS_ADDRESS'] = 'unix:path=/run/user/USERID/bus'
os.environ['DISPLAY'] = ':0'

bus = SessionBus()
notifications = bus.get('.Notifications')

notifications.Notify('test', 0, 'dialog-information', "Hello World!", "pydbus works :)", [], {}, 5000)

Tested successfully for Python 3

NB : You can retrieve your user id using the id command.

Python namespace concept

Python 3 official documentation provides a detailed definition about the namespace concept.

https://docs.python.org/3/tutorial/classes.html#python-scopes-and-namespaces

Below, this concept is explained differently and in an easier manner :

https://www.programiz.com/python-programming/namespace

https://code.tutsplus.com/tutorials/what-are-python-namespaces-and-why-are-they-needed–cms-28598

https://www.python-course.eu/namespaces.php

A guide to Python Namespaces

http://sebastianraschka.com/Articles/2014_python_scope_and_namespaces.html

Method Resolution Order – Object Oriented Programming

https://blog.confirm.ch/python-namespaces/

TypeError: an integer is required

While executing a Python program, if you get this message “TypeError: an integer is required” , check which modules are imported. In fact, there are two methods for open(). One is a built-in function whereas the other is part of the os module.

So, if you do an import of all the methods of the os module like this way “from os import *“,  then your program will not use the open() built-in fonction. It will use os.open() instead.

Be careful !


Installation of Python cx_Oracle module for Debian Squeeze

Here is a HOWTO to access an Oracle base with Python.

There are two main ways : by compiling the cx_Oracle module source or transforming into a Debian package an ready-to-install rpm package.

I chose the second way. Download the rpm file suited for “CentOS 5 i386 RPM (Oracle 10g, Python 2.5)” at this address :

http://cx-oracle.sourceforge.net/

Check that the command-line program “alien” is present :

root@localhost:~# alien cx_Oracle-5.0.2-10g-py25-1.i386.rpm

A debian package is created : cx-oracle_5.0.2-2_i386.deb

To install it :

root@localhost:~# dpkg -i cx-oracle_5.0.2-2_i386.deb

To check that the module cx_Oracle is available :

fool@localhost:~$ python

Python 2.5.2 (r252:60911, Jan  4 2009, 17:40:26)
[GCC 4.3.2] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> import cx_Oracle
>>>

You can now connect to the database Oracle through Python.

For more information about Python Database API Specification v2.0 :

Python Database API Specification v2.0

The official cx_Oracle documentation :

The official cx_Oracle documentation