在Anaconda Python(Ubuntu)中安装Pyproj



我正在尝试在Ubuntu 16.04上运行Anaconda Python 2.7.15的远程服务器上安装Pyproj。在运行conda install -c conda-forge pyproj(在https://anaconda.org/conda-forge/pyproj上首次列出的选项)后,该软件包将成功安装(Pyproj 2.0.2)。但是,运行程序后,我会得到以下追溯:

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`.

在我的python脚本中,我用 from pyproj import Proj, transform导入,而相关的代码行是:

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

显然,Pyproj无法找到data目录。搜索目录 ~/anaconda2/lib/python2.7/site-packages/pyproj,我确认没有data目录。我有另一台在Anaconda3上安装Pyproj的服务器,该服务器确实包含data目录(带有epsg文件)。我将此目录复制到Anaconda2服务器,并使用Trackback中指示的环境变量声明了路径:

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

我仍然得到相同的错误追溯。

我在pyproj的github存储库上找不到data目录(https://github.com/pyproj4/pyproj/)。

如何解决此错误?

我能够通过安装先验版本的pyproj来解决此问题。我用运行conda install -c conda-forge/label/gcc7 pyprojpyproj-2.0.2安装替换为pyproj-1.9.6。(作为此安装的一部分,proj4也从6.0.0降级到5.2.0)。这是https://anaconda.org/conda-forge/pyproj。

如上所述,我还从另一台服务器上安装的Anaconda3安装了现有的data目录(scp),然后导出PROJ_LIB环境变量,并带有通往data目录的路径。

请注意,在将路径导出到data之前,运行pyproj-1.9.6时,错误追溯却指示RuntimeError: 'no arguments in initialization list'。此问题由其他用户很好地描述:https://github.com/pyproj4/pyproj/issues/134。

pyproj 2.2.0的当前版本对我有用:

(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'

相关内容

  • 没有找到相关文章

最新更新