4

I am trying to install pyproj. I downloaded the zip folder on this page pyproj.

Then I copied it to C:\Python27\ArcGIS10.3\Lib. However, when I try to import the module, I get the message:

ImportError: No module named pyproj.

I also tried to run the setup.py, but I get the message ImportError: No module named setuptools. I read somewher that it is working when I install Basemap, which is part of Matplotlib, but I cannot find pyproj there.

Any help?

2
  • 1
    Have you tried it in C:\Python27\ArcGIS10.3\Lib\site-packages?
    – countryman
    Commented Jan 26, 2016 at 14:16
  • Yes, I tried that first but without success.
    – Alex
    Commented Jan 27, 2016 at 8:33

2 Answers 2

9

For that, you must know the real Python world and the modern way to install modules.

1) The pyproj module needs the compilation of many C libraries and Windows has no compiler by default as in Linux or Mac OS X so you can't install the module with setuptools , easy_install or pip, the traditional way to install modules or unzipping the folder in C:\Python27\ArcGIS10.x\Lib\site-packages :

2) Christoph Gohlke's Unofficial Windows Binaries for Python Extension Packages has a pyproj compiled version ready for Windows but it is a ,whl file (pyproj-1.9.5-cp27-none-win32.whl)

Therefore, you need to install pip (How do I install pip on Windows?) and after Window: How do I install a Python package with a .whl file?

Then

pip install pyproj-1.9.5-cp27-none-win32.whl

or other whl file (pyproj-1.9.5-cp27-none-win_amd64.whl)

New

To install a Python module (in the site-packages of the Python installation):

a) if it is a simple pure Python module (geojson for example)

1) the classical way
- unzip the zip file (or tgz or)
- open a terminal or a command window in the unzipped folder and

python setup.py install 

You need setuptools if you want to manage all the eventual dependencies automatically (download and installation)

2) the new way (directly from Internet and you need setuptools)
- easy_install geojson
- pip install geojson

They install all the eventual dependencies automatically.

3) you can unzip the file and copy the resulting folder in the site-package folder but there is no management of the eventual dependencies.

b) if it is a complicated module or a module with C libraries (pyproj) or Fortran or...

1) this solution needs a compiler available to compile the C files into .dll or .pyd files (for Windows)
2) same for easy_install or pure pip install
3) you cannot simply copy the resulting folder (no compiled files)
4) the solution of pip and the .whl files

A wheel is a ZIP-format archive with a specially formatted filename and the .whl extension.

It is designed to contain all the necessary files. The contents of pyproj-1.9.5-cp27-none-win32.whl is

enter image description here

You recognize a .pyd file. You can try
- pip install pyproj -> it works if pip can download an adequate .whl file (for Windows) from the Python Package Index
- pip install pyproj-1.9.5-cp27-none-win32.whl -> the file downloaded
- unzipping the whl file in the site-packages folder -> no eventual dependencies management

c) With Anaconda

You can use the solutions 1), 2), 3) and 4) but Anaconda uses another package manager conda easier for the beginners
- conda install pyproj with the management of all the dependencies

If the Python version are the same (Python 2.7.x, 32 or 64 bits) you can try to copy the pyproj folder from the Anaconda distribution to the ArcGIS Python distribution.

5
  • I tried option 1) yesterday and today again. However, I am kind of stuck. I tried the unzipped folder, but there is no init.py. And I tried the pyproj folder which is in the folder lib, which is in the unzipped pyproj folder. The first option doesn't work as there is the missing init.py and the second option doesn't work as the _int.py doesn't manage to import the right scripts. I will try option 2) now, but I would like to manage option 1) aswell. Any suggestions what I am doing wrong?
    – Alex
    Commented Jan 27, 2016 at 8:40
  • Well, option 2) worked, but only as I had installed Anaconda first as the python directory of anaconda was recognized but not of ArcGIS. It still would be nice to go without whl.
    – Alex
    Commented Jan 27, 2016 at 10:24
  • You don't need option 2) with Anaconda, simply use conda install pyproj . With ArcPy, you need to install pip in the Python distribution of ArcGIS and, sorry, but the whl format is becoming a standard in the Python world.
    – gene
    Commented Jan 27, 2016 at 15:54
  • Ok, thanks. So, I guess I can live with whl-files. I just thought as it is an unoffical binary...and I always thought you just need to copy a folder into the python directory to "install" a python module...However could you please give me same more details about option 1?
    – Alex
    Commented Jan 28, 2016 at 8:05
  • look in my answer, please
    – gene
    Commented Jan 28, 2016 at 17:52
1

Looking on PyPi, the last version of pyproj with binary wheels for Python 2.7 Windows is pyproj==1.9.6, released Decembe 30, 2018. Note that if/when ArcMap upgrades their Python version to 3, then newer versions of pyproj can be installed and used.

Install

From a cmd.exe console, you can upgrade pip and install this version of pyproj for ArcMap 10.5:

c:\Python27\ArcGIS10.5\python.exe -m pip install pip --upgrade
c:\Python27\ArcGIS10.5\python.exe -m pip install pyproj==1.9.6

Simple test

Here's a basic check that you can do from ArcMap's Python console:

import pyproj

print(pyproj.__version__)  # 1.9.6
print(pyproj.proj_version_str) # 4.9.3

inProj = pyproj.Proj(init='epsg:3857')
print(inProj(-11705274.6374, 4826473.6922, inverse=True))
# (-105.15027111593008, 39.72785727727918)

Advanced use

And if you need grid shift files to do more advanced transforms (e.g.) NZMG1049 -> NZTM2000 via nzgd2kgrid0005.gsb, which is installed with the version of pyproj described above:

print(pyproj.datadir.pyproj_datadir)
# C:\Python27\ArcGIS10.5\lib\site-packages\pyproj\data

assert 'nzgd2kgrid0005.gsb' in os.listdir(pyproj.datadir.pyproj_datadir)

nzmg = pyproj.Proj('+proj=nzmg +lat_0=-41 +lon_0=173 +x_0=2510000 +y_0=6023150 +datum=nzgd49 +units=m +nadgrids=nzgd2kgrid0005.gsb +no_defs')
nztm = pyproj.Proj('+proj=tmerc +lat_0=0 +lon_0=173 +k=0.9996 +x_0=1600000 +y_0=10000000 +ellps=GRS80 +towgs84=0,0,0 +units=m +no_defs')

pyproj.transform(nzmg, nztm, 2939247.5, 6752871.3)
# (2028008.0242483453, 6191971.575551837)
6
  • The latest pyproj version that supports python 2 is version 2.2.2 pypi.org/project/pyproj/2.2.2.
    – snowman2
    Commented Mar 18, 2020 at 0:32
  • @snowman2 the point of this answer is to install for Python 2.7, as required by current ArcMap (otherwise yes! pyproj >= 2.2 versions are awesome!)
    – Mike T
    Commented Mar 18, 2020 at 0:40
  • I was attempting to say that pyproj<=2.2.2 should work with Python 2 on Windows (Side note: I am not a Windows ArcMap user, so this is purely theoretical). Glad to hear that you like the new version!
    – snowman2
    Commented Mar 18, 2020 at 0:49
  • @snowman2 unfortunately it does not seem that there are any combinations for "win" and "cp27" from the PyPI files for 2.2.2
    – Mike T
    Commented Mar 18, 2020 at 2:13
  • Oh yeah, I remember now. The new version of PROJ doesn't work with VS 2008, and so it doesn't work with python 2 on Windows. So, my suggestion was incorrect.
    – snowman2
    Commented Mar 18, 2020 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.