Can't install Proj 8.0.0 for cartopy linux

Question:

I am trying to install Cartopy on Ubuntu and need to install proj v8.0.0 binaries for Cartopy. However when I try to apt-get install proj-bin I can only get proj v6.3.1. How do I install the latest (or at least v8.0.0) proj for cartopy?

Asked By: Recessive

||

Answers:

I’m answering my own question here partly to help others with this problem, and partly as an archive for myself so I know how to fix this issue if I come across it again. I spent quite a while trying to figure it out, and wrote detailed instructions, so see below:

Installing cartopy is a huge pain, and I’ve found using conda to be a very bad idea (it has bricked itself and python along with it multiple times for me)

THIS INSTALLATION IS FOR LINUX.

Step 0. Update apt:

apt update

Step 1. Install GEOS:

Run the following command to install GEOS:

apt-get install libgeos-dev

In case that doesn’t do it, install all files with this:

apt-get install libgeos-dev libgeos++-dev libgeos-3.8.0 libgeos-c1v5 libgeos-doc

Step 2. Install proj dependencies:

  • Install cmake:
apt install cmake
  • Install sqlite3:
apt install sqlite3
  • Install curl devlopment package:
apt install curl && apt-get install libcurl4-openssl-dev

Step 3. Install Proj

Trying apt-get just in case it works:

Unfortunately, cartopy requires proj v8.0.0 as a minimum, but if you install proj using apt you can only install proj v6.3.1

Just for reference in case anything changes, this is the command to install proj from apt:

apt-get install proj-bin

I’m fairly sure this is all you need, but in case it’s not, this command will install the remaining proj files:

apt-get install proj-bin libproj-dev proj-data

To remove the above installation, run:

apt-get remove proj-bin

or:

apt-get remove proj-bin libproj-dev proj-data

Building Proj from source

So if the above commands don’t work (it’s not working as of 2022/4/8), then follow the below instructions to install proj from source:

  • Go to your install folder and download proj-9.0.0 (or any version with proj-x.x.x.tar.gz):
wget https://download.osgeo.org/proj/proj-9.0.0.tar.gz 
  • Extract the tar.gz file:
tar -xf proj-9.0.0.tar.gz
  • cd into the folder:
cd proj-9.0.0
  • Make a build folder and cd into it:
mkdir build && cd build
  • Run (this may take a while):
cmake ..
cmake --build .
cmake --build . --target install
  • Run to make sure everything installed correctly:
ctest

The test command failed on one test for me (19 - nkg), but otherwise was fine.

You should find the required files in the ./bin directory

Finally:

  • Move binaries to the /bin directory:
cp ./bin/* /bin
  • As per Justino, you may also need to move the libraries:
cp ./lib/* /lib

Now after all this, you can finally install cartopy with pip:

pip install cartopy

After doing this, my cartopy still wasn’t working. I went home to work on this next week, came back, and all of a sudden it was working so maybe try restarting

Answered By: Recessive

The libraries should be copied manually
sudo cp ./lib/* /lib
This works for me

Answered By: Justino
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.