My Avatar

LanternD's Castle

An electronics enthusiast - survive technically

Install Vim on Raspberry Pi with Python3 Support

2021-03-24

Install the latest version of vim on Raspberry Pi (4B in my case).

Why

We need to have +python3 in vim --version output.

Before (vim by sudo apt install vim):

1
2
3
$ vim --version | ag "python"
+cmdline_hist      +langmap           -python            +visual
+cmdline_info      +libcall           -python3           +visualextra

After (my manually installed vim):

1
2
3
4
$ vim --version | ag "python"
+comments          +libcall           -python            +visual
+conceal           +linebreak         +python3           +visualextra
Linking: gcc -lrt -L/usr/local/lib -Wl,--as-needed -o vim -lSM -lICE -lXt -lX11 -lXdmcp -lSM -lICE -lm -ltinfo -ldl -L/usr/local/lib/python3.8/config-3.8-arm-linux-gnueabihf -lpython3.8 -lcrypt -lpthread -ldl -lutil -lm -lm

How

To find the detail steps for installing vim in local machine: Install Vim for Local User (My previous post).

What makes it special is that I install my own python version (3.8 in my case) on the Raspberry Pi.

Key step:

1
./configure --prefix=$HOME/.local --enable-python3interp --with-python3-config-dir=/usr/local/lib/python3.8/config-3.8-arm-linux-gnueabihf --with-python3-command=/usr/bin/python

Note:

You need to see the following in the output of ./configure to guarantee the success of compilation:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
checking --enable-pythoninterp argument... no
checking --enable-python3interp argument... yes
checking --with-python3-command argument... /usr/bin/python
checking Python version... 3.8
checking Python is 3.0 or better... yep
checking Python's abiflags...
checking Python's install prefix... /usr/local
checking Python's execution prefix... /usr/local
checking Python's configuration directory... (cached) /usr/local/lib/python3.8/config-3.8-arm-linux-gnueabihf
checking Python3's dll name... libpython3.8.a
checking if -pthread should be used... yes
checking if compile and link flags for Python 3 are sane... yes
checking if -fPIE can be added for Python3... yes
...

Wrong example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
checking --enable-pythoninterp argument... no
checking --enable-python3interp argument... yes
checking --with-python3-command argument... /usr/bin/python
checking Python version... 3.8
checking Python is 3.0 or better... yep
checking Python's abiflags...
checking Python's install prefix... /usr/local
checking Python's execution prefix... /usr/local
checking Python's configuration directory... (cached) /usr/local/lib/config-3.8-arm-linux-gnueabihf/config
cat: /usr/local/lib/config-3.8-arm-linux-gnueabihf/config/Makefile: No such file or directory
auto/configure: line 6766: cd: /usr/local/lib/config-3.8-arm-linux-gnueabihf/config: No such file or directory
checking Python3's dll name...
checking if -pthread should be used... yes
checking if compile and link flags for Python 3 are sane... yes
checking if -fPIE can be added for Python3... yes
...

If Python3's dll name... output is NULL, then you need to double check your python config dir again. Otherwise you will encounter the following error during make:

1
2
3
4
5
/usr/bin/ld: /usr/local/lib/libpython3.8.a(thread.o): undefined reference to symbol 'pthread_getspecific@@GLIBC_2.4'
/usr/bin/ld: //lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
link.sh: Linking failed
make: *** [Makefile:2134: vim] Error 1

If no error prompt out, then just make && make install.

Do not forget to set your vim alias in your .bashrc or .zshrc.

If you need +python support, locate Python 2.7 related paths accordingly.

Read More



Disqus Comment 0