How-to run QGIS 2 and QGIS 3 at the same time in Archlinux or Manjaro


Since QGIS 3 was released, it's a nice and very pleasant upgrade. Unfortunately some plugins I use does still not work with Qgis 3 due to python upgrade from version 2 to 3.
It's possible to upgrade with tools like 2to3 (If interested, I suggest to watch Heikki Vesanto blog : https://gisforthought.com/updating-a-plugin-from-qgis-2-to-qgis-3/ ) but some plugins needs time to debug.

That's why, it's interesting during migration to have Qgis 2 and 3 at the same time in one computer. It's also possible to run Qgis 2 and 3 at the same time due to profile migration. They are not sharing same preferences folder so you are not breaking anything.
It's possible to have Qgis 2 and 3 running at the time with different way like Conda or Docker. But it's lightest to run it natively.

Archlinux/Manjaro is the Linux distribution I use. It have in my opinion a powerfull little thing called AUR (Arch User Repository) which automate installation of software. Furthermore, if you don't happy with compilation parameters and want a custom value added parameters you could modify it by editing a file named PKGBUILD. Archlinux based linux system is a rolling release and now qgis package move from AUR to official package, version 3 is available today. There is still a qgis-ltr version in AUR, version 2.18.19, but this package needs building. As explain before it's not difficult because everything is automated but at this time qgis package is in conflict with qgis-ltr package. So you have only choice to have qgis or qgis-ltr installed, not both.

Let's just edit PKGBUILD and we will be able to have both packages installed.

1) Download PKGBUILD : 

 a) Auto download with yaourt :
From command line just run
yaourt -S qgis-ltr
Then you will be prompt to edit file or not

 b) Download from AUR :
Go here : https://aur.archlinux.org/packages/qgis-ltr/
On the right side there is View PKGBUILD, download it


2) Edit PKGBUILD : 

We need to modify this file to install in different directory. Like INSTALL file from qgis github repository, I installed qgis-ltr in my home

We need to modify these lines :

line 36 : (disable conflicts check between these 2 packages)
from
conflicts=("$_pkgname")
It becomes
conflicts=("")

line 64 : (change installed directory with cmake option)
from
-DCMAKE_INSTALL_PREFIX=/usr \

to
-DCMAKE_INSTALL_PREFIX=${HOME}/apps \

line 93 to 108 : (comment by adding # in front or remove these lines)


3) Build package : 

  a) With yaourt :

At the end of editing PKGBUILD, it will continue alone.


  b) If you download PKGBUILD:

In directory where you download PKGBUILD, run

makepkg  
from command line and wait.


4) Install package : 

  a) With yaourt :

You will be asked to install or not generated package

  b) If you download PKGBUILD:

pacman -U qgis*.pkg.tar.xz

5) Run qgis 2 : 

Open a terminal and launch these commands :

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/apps/lib"
cd ${HOME}/apps/bin
./qgis
6) Automate qgis 2 launcher :

Edit file in /usr/local/bin :

nano /usr/local/bin/qgis2

Put this in it :

#!/bin/bash
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${HOME}/apps/lib"
cd ${HOME}/apps/bin
./qgis

Save and close.
Make it executable :

chmod +x /usr/local/bin/qgis2

Now you could just type in terminal to run Qgis2 :
qgis2



NOTE : Overview of modified PKGBUILD. Available for download here :  https://github.com/giscan/QGIS2_Archlinux

# Maintainer: Doug Newgard
# Contributor: SaultDon
# Contributor: Lantald < lantald at gmx.com >
# Contributor: Thomas Dziedzic < gostrc at gmail >
# Contributor: dibblethewrecker dibblethewrecker.at.jiwe.dot.org
# Contributor: Gerardo Exequiel Pozzi
# Contributor: Eric Forgeot < http://esclinux.tk >

# Globe Plugin and Map Server are disabled in cmake by default.
# Uncomment them in the build() portion if you'd like them enabled.
# You will also need to install osgearth-qt4 or fcgi, respectively, before building.

pkgname=qgis-ltr
_pkgname=${pkgname//-ltr}
pkgver=2.18.19
pkgrel=1
pkgdesc='Geographic Information System (GIS) that supports vector, raster & database formats; Long Term Release'
url='https://qgis.org/'
license=('GPL')
arch=('i686' 'x86_64')
depends=('expat' 'gcc-libs' 'gdal' 'geos' 'glibc' 'libspatialite' 'postgresql-libs' 'proj'
         'qt4' 'qca-qt4' 'qjson' 'qscintilla-qt4' 'qwt-qt4' 'qwtpolar-qt4' 'spatialindex' 'sqlite'
         'python2' 'python2-httplib2' 'python2-future' 'python2-qscintilla-qt4' 'python2-sip' 'python2-six')
makedepends=('cmake' 'gsl' 'perl' 'txt2tags')
optdepends=('gpsbabel: GPS Tool plugin'
            'gsl: Georeferencer plugin'
            'python2-gdal: DB Manager plugin; Processing plugin'
            'python2-jinja: MetaSearch plugin'
            'python2-owslib: MetaSearch plugin'
            'python2-psycopg2: DB Manager plugin; Processing plugin'
            'python2-pygments: MetaSearch plugin; DB Manager plugin'
            'python2-pyspatialite: DB Manager plugin; Processing plugin'
            'python2-yaml: Processing plugin'
            'saga-gis-ltr: Saga processing tools')
provides=("$_pkgname=$pkgver")
conflicts=("")
source=("https://qgis.org/downloads/$_pkgname-$pkgver.tar.bz2")
md5sums=('49a5d6803974f1adefe98ed9af55db1e')

prepare() {
  cd $_pkgname-$pkgver

  # Make sure we find the -qt4 versions of qwt and qwtpolar
  sed -i '/QWT_LIBRARY_NAMES/ s/qwt /qwt-qt4 /' cmake/FindQwt.cmake
  sed -i '/PATH_SUFFIXES/ s/qwt$/&-qt4/;/LIBRARY NAMES/ s/qwtpolar/&-qt4/' cmake/FindQwtPolar.cmake

  # Fix references to "python"
  sed -i 's/\(env \|\/usr\/bin\/\)python$/&2/' $(find . -iname "*.py")

  # Remove mime types already defined by freedesktop.org
  sed -e '/type="image\/tiff"/,/<\/mime-type>/d' \
      -e '/type="image\/jpeg"/,/<\/mime-type>/d' \
      -e '/type="image\/jp2"/,/<\/mime-type>/d' \
      -e '/type="application\/x-adobe-mif"/,/<\/mime-type>/d' \
      -i debian/qgis.xml

  [[ -d build ]] || mkdir build
}

build() {
  cd $_pkgname-$pkgver/build

  cmake -G "Unix Makefiles" ../ \
    -DCMAKE_INSTALL_PREFIX=${HOME}/apps \
    -DQGIS_MANUAL_SUBDIR=share/man \
    -DENABLE_TESTS=FALSE \
    -DWITH_QTWEBKIT=FALSE \
    -DWITH_INTERNAL_QWTPOLAR=FALSE \
    -DWITH_INTERNAL_{MARKUPSAFE,OWSLIB,DATEUTIL,PYTZ,YAML,NOSE2,SIX,FUTURE}=FALSE \
#    -DWITH_SERVER=TRUE \
#    -DWITH_GLOBE=TRUE

  make

  # Rebuild srs database, QGIS distributes an old, buggy one
  LD_LIBRARY_PATH="$PWD/output/lib/" make synccrsdb
  mv /tmp/srs.db ../resources/
}

package() {
  cd $_pkgname-$pkgver/build

  # Add optional deps based on selected or autodetected options
  [[ -n "$(sed -n '/^GRASS_PREFIX:/  s/.*=//p' CMakeCache.txt)" ]]      && optdepends+=('grass6: GRASS6 plugin')
  [[ -n "$(sed -n '/^GRASS_PREFIX7:/ s/.*=//p' CMakeCache.txt)" ]]      && optdepends+=('grass: GRASS7 plugin')
  [[ "$(sed -n '/^WITH_SERVER:/ s/.*=//p' CMakeCache.txt)" == "TRUE" ]] && optdepends+=('fcgi: Map Server')
  [[ "$(sed -n '/^WITH_GLOBE:/  s/.*=//p' CMakeCache.txt)" == "TRUE" ]] && optdepends+=('osgearth-qt4: Globe plugin')

  make DESTDIR="$pkgdir" install

  cd "$srcdir/$_pkgname-$pkgver"

  # install desktop files and icons
#  install -Dm644 debian/{qgis,qbrowser}.desktop -t "$pkgdir/usr/share/applications/"
#  for _icon in qgis-icon{,-16x16,-60x60} qbrowser-icon{,-60x60}; do
#    local _resolution="${_icon##*-}"; [[ "$_resolution" == "icon" ]] && _resolution="512x512"
#    install -Dm644 images/icons/$_icon.png "$pkgdir/usr/share/icons/hicolor/$_resolution/apps/${_icon%%-*}.png"
#  done
#  for _prog in qgis qbrowser; do
#    install -Dm644 images/icons/${_prog}_icon.svg "$pkgdir/usr/share/icons/hicolor/scalable/apps/#$_prog.svg"
#  done

#  install mime information and icons
#  install -Dm644 debian/qgis.xml -t "$pkgdir/usr/share/mime/packages/"
#  install -Dm644 images/icons/qgis-mime-icon.png "$pkgdir/usr/share/icons/hicolor/128x128/mimetypes/qgis-mime.png"
#  for _type in asc ddf dem dt0 dxf gml img mime mldata qgs qlr qml qpt shp sqlite; do
#    install -Dm644 images/icons/qgis_${_type}_icon.svg "$pkgdir/usr/share/icons/hicolor/scalable/#mimetypes/qgis-$_type.svg"
#  done


  # compile python files, since the cmake option doesn't seem to account for DESTDIR
  python2 -m compileall -q "$pkgdir"
}

Commentaires

Posts les plus consultés de ce blog

Disposer du support de l'ECW sous Ubuntu

Mise à jour Paquet ECW pour Ubuntu