0

Whenever possible I avoid installing Python libraries other than those installed with ArcPy by the ArcGIS Desktop 10.x and ArcGIS Pro installs but occasionally I have for ReportLab, gdal, pyodbc and I usually find several ways are suggested and I only get them working after some experimentation.

I would like to be able to copy a worksheet from one Excel (*.xls) spreadsheet, created using TableToExcel in ArcPy, to another Excel (*.xls) spreadsheet (also created by ArcPy), and the only technique that I found that looks promising for doing this is in this answer to Writing to existing workbook using xlwt

That technique commences by importing xlrd, xlwt and xlutils using the re-ordered lines below:

from xlrd import open_workbook
from xlwt import easyxf
from xlutils.copy import copy

When I run them using IDLE from Python 2.7.10 that was installed with ArcGIS 10.4.1 for Desktop I get this error which indicates that xlrd and xlwt are available but xutils is not.

Traceback (most recent call last): File "C:\Fyfe\xutilsTest.py", line 3, in from xlutils.copy import copy ImportError: No module named xlutils.copy

This matches what I see when I look in C:\Python27\ArcGIS10.4\Lib\site-packages where xlrd and xlwt folders can be seen but no xlutils.

enter image description here

Is there a simple process that will let me download a folder of Python code for xlutils and copy it into the same folder to make import xlutils just work?

Installing third party python libraries in ArcGIS location gives me some hints about what may need to be done but that Q&A seems to be more understandable by someone who develops using a higher Python:ArcPy ratio than I do.

  • A little hesitant to add this as a full answer because I don't have arc on my home machine, but this Q&A seems to suggest that you could just download a distribution of xlutils and drop it in the directory as you suggested. – Bryce Frank Dec 18 '16 at 6:21
  • @Luke I notice that there is a pip folder in the same location as xlrd and xlwt but the ArcGIS install does not provide a path that makes pip recognizable as a command. To save me wading through stackoverflow.com/questions/4750806/… is there something that just has to be added onto PYTHONPATH to make pip available to a DOS prompt? – PolyGeo Dec 18 '16 at 7:01
  • Use the full path to to pip.exe or replace pip with python -m pip – user2856 Dec 18 '16 at 8:12
  • Optionally, you could utilize the shipped setup.py script shipped with the module at the DOS prompt by changing to the directory you stored the module folder (cd) then use the command: python setup.py install – T. Wayne Whitley Dec 18 '16 at 8:54
  • Thanks @BryceFrank and T.WayneWhitley - I got this working with Luke's help but appreciate your input. – PolyGeo Dec 18 '16 at 8:57
1

You can install from pypi using pip:

pip install --user xlutils

http://pythonhosted.org/xlutils/installation.html

If pip.exe is not in your PATH use the full path to to pip.exe or replace pip with python -m pip

0

@Luke's answer filled the key steps to a solution.

A few extra things that I had to do to my vanilla ArcGIS install of ArcPy were:

  1. Added ;C:\Python27\ArcGIS10.4 to my Path so that python was recognized as a command
  2. Used python -m pip install --user xlutils which I ran in C:\users\PolyGeo
  3. When the xlutils site-package still did not import I went to C:\Users\PolyGeo\AppData\Roaming\Python\Python27\site-packages and cut two folders xlutils and xlutils-2.0.0.dist-info
  4. I then pasted those two folders into C:\Python27\ArcGIS10.4\Lib\site-packages

I was then able to import xlutils.

As commented by @Luke the steps above may not have been necessary:

You should never need to cut and paste pip installed packages/modules. I use the --user flag as I don't have admin rights to install directly to the python installation directory, but you can leave that out to install directly to C:\Python27\ArcGIS10.4. Also, the user site packages directory C:\users\username\python27 only gets added to your python path if it exists when python starts. So you would need to restart IDLE to get python to register the newly installed module. You would only need to do this once, i.e the first time you ever install using the --user flag.

  • This is one annoying outcome of having ArcGIS install Python for you; you have to manually set the path. After dealing with multiple ArcGIS re-installs, I created a script to do this for me. There are built-in logical checks for various version of ArcGIS as well as installing the pip package. – Sethdd Dec 18 '16 at 14:39
  • You should never need to cut and paste pip installed packages/modules. I use the --user flag as I don't have admin rights to install directly to the python installation directory, but you can leave that out to install directly to C:\Python27\ArcGIS10.4. Also, the user site packages directory C:\users\username\python27 only gets added to your python path if it exists when python starts. So you would need to restart IDLE to get python to register the newly installed module. You would only need to do this once, i.e the first time you ever install using the --user flag. – user2856 Dec 18 '16 at 19:44
  • @Luke I suspect that I overlooked restarting IDLE when I first retested. – PolyGeo Dec 18 '16 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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