0

I am trying to install pyproj on a remote server running anaconda python 2.7.15 on Ubuntu 16.04. After running conda install -c conda-forge pyproj (first listed option at https://anaconda.org/conda-forge/pyproj), the package installs successfully (pyproj 2.0.2). However, upon running my program I get the following traceback:

Traceback (most recent call last):
  File "run_qc_worker.py", line 1288, in <module>
    GC.make_metadata_caches() # For percentiles check
  File "/home/ubuntu/qc-mem/qc/lib/global_class.py", line 384, in make_metadata_caches
    mercator_arr = self.proj_arr(lat_lon_arr) # project to x/y
  File "/home/ubuntu/qc-mem/qc/lib/global_class.py", line 421, in proj_arr
    inproj = Proj(init='epsg:4326') # WGS 84
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/__init__.py", line 322, in __init__
    self.crs = CRS.from_user_input(projparams if projparams is not None else kwargs)
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/crs.py", line 224, in from_user_input
    return cls(**value)
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/crs.py", line 146, in __init__
    super(CRS, self).__init__(projstring)
  File "pyproj/_crs.pyx", line 307, in pyproj._crs._CRS.__init__
  File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/pyproj/datadir.py", line 62, in get_data_dir
    "Valid PROJ.4 data directory not found."
pyproj.exceptions.DataDirError: Valid PROJ.4 data directory not found.Either set the path using the environmental variable PROJ_LIB or with `pyproj.datadir.set_data_dir`.

In my python script, I import with from pyproj import Proj, transform, and the relevant lines of code are:

inproj = Proj(init='epsg:4326') # WGS 84
outproj = Proj(init='epsg:3857') # WGS 84 / Pseudo-Mercator

Apparently, pyproj is unable to find a data directory. Searching the directory at ~/anaconda2/lib/python2.7/site-packages/pyproj, I confirmed there is no data directory. I have another server with an installation of pyproj on anaconda3 that does contain a data directory (with an epsg file). I copied this directory to the anaconda2 server, and declared the path using the environment variable as instructed in the traceback:

export PROJ_LIB=~/anaconda2/lib/python2.7/site-packages/pyproj/data

I still get the same error traceback.

I cannot find a data directory on the github repo for pyproj (https://github.com/pyproj4/pyproj/).

How can I resolve this error?

pjw
  • 2,133
  • 3
  • 27
  • 44

2 Answers2

0

I was able to resolve this by installing a prior version of pyproj. I replaced the pyproj-2.0.2 installation with pyproj-1.9.6, by running conda install -c conda-forge/label/gcc7 pyproj. (proj4 was also downgraded from 6.0.0 to 5.2.0 as part of this install). This is the second available conda install option listed at https://anaconda.org/conda-forge/pyproj.

As described above, I also manually copied (scp) an existing data directory from an anaconda3 install on another server, and then exported the PROJ_LIB environment variable with the path to the data directory.

Note that when running pyproj-1.9.6 before exporting the path to data, the error traceback instead indicates RuntimeError: 'no arguments in initialization list'. This issue is well-described by other users here: https://github.com/pyproj4/pyproj/issues/134.

pjw
  • 2,133
  • 3
  • 27
  • 44
  • It appears that manually copying the `data` directory is not necessary. Simply installing the pyproj 1.9.6 version will work. – pjw Apr 12 '19 at 23:49
0

The current version of pyproj 2.2.0 works for me:

(base) $ conda create -c conda-forge -n proj27 python=2.7 pyproj
...
  proj4              conda-forge/linux-64::proj4-6.1.0-he751ad9_2
  pyproj             conda-forge/linux-64::pyproj-2.2.0-py27hc44880f_0
...
(base) snowal@snowal-lx2:~$ conda activate proj27
(proj27) snowal@snowal-lx2:~$ python
Python 2.7.15 | packaged by conda-forge | (default, Feb 28 2019, 04:00:11) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyproj import Proj, transform
>>> inproj = Proj(init='epsg:4326') # WGS 84
>>> outproj = Proj(init='epsg:3857') # WGS 84 / Pseudo-Mercator
>>> import pyproj
>>> pyproj.__version__
'2.2.0'

snowman2
  • 646
  • 4
  • 11