Monday 22 April 2019

installation - Installing PyProj into ArcPy


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?



Answer



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.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...