0

I am getting an error message that says "no module named xlutils.copy". When I got to do the pip install of xlutils.copy I get an error message "could not find a version that satifies the requirement". I downloaded xlutils 2.0.0 which contains xlutils.copy but I am not sure if it needs to be put in a certain directory?

from xlrd import open_workbook
from xlutils.copy import copy
rb = open_workbook('Excel FDT Master_01_update.xlsx')
wb = copy(rb)
s = rb.sheet_by_name('INPUT')
r = 5
for test in col_test:
    s.cell(rowx = r, colx = 1).value = test
    r += 1
wb.save('comeonenow.xls')
boulderj
  • 11
  • 1
  • 5

1 Answers1

1

Perhaps you have multiple installations of Python, and the pip installed the xlutils in a different installation. If you try just:

import xlutils

I expect you'll get the same results as before. I feel this may be getting overlooked by some of the other posters. Your error message says it can't find the xlutils module, not some submodule or variable. Is this still the case?

When you have multiple installations of Python, only one is the "default", so to speak, and any module installations will install into that default Python installation. I am careful to only run two installations: Python 2.7 and 3.6. And I go into each installation and make sure that I have a pip2 and a python2, and a pip3 and python3, so that I can just reference directly to the Py version I want to use, either to run or to install new packages. Otherwise, if I just run pip, I'm not 1000% sure where it will go. (Okay, I'm exaggerating. I know Python 2 is my default. Just trying to make a point.) :)

Also, just because you think you only have one Python installation, that may not be the case. On Windows, yes. But on Mac, there is a preloaded Python installation, and updating the Python and getting new packages into the new version instead of the preloaded version can be tricky, depending on what you've done. Also, when you install an IDE like PyCharm, it wants to install a Python version, as well.

Last comment -- Sometimes (not usually but sometimes), an installed package will have a different name than you would think. That is not the case with xlutils. But, with fonttools, you install fonttools but you must import fontTools (note the capital 'T') into your Py script. Again, not the case with xlutils, but just be aware of this for the future.

GaryMBloom
  • 5,350
  • 1
  • 24
  • 32
  • What is the best way to determine how many installations I have and where the modules are being installed? Thank you. – boulderj Dec 07 '17 at 19:20
  • @boulderj - Not always simple, but it depends on your platform. Are you on Windows or Mac, or something else? – GaryMBloom Dec 07 '17 at 19:22
  • I am on a Windows – boulderj Dec 07 '17 at 19:23
  • @boulderj Brute force, you can just do a global search for python.exe (on Windows) or python (on OSX/UNIX), and see where they are. – GaryMBloom Dec 07 '17 at 19:24
  • @boulderj - Usually Python 2 installs in the root directory of C:, so look for C:\Python27\, etc. Python 3 can be trickier. That can be installed in your home dir, or in the C:\Program Files\... dir, etc. Do the global search and see where you find python.exe – GaryMBloom Dec 07 '17 at 19:25
  • 1
    If you run `pip --version`, it should tell you what version of Python it's linked with. – John Gordon Dec 07 '17 at 19:28
  • @boulderj - what version of Python are you running? Did you install any IDEs, like PyCharm or anything else? – GaryMBloom Dec 07 '17 at 19:28
  • @JohnGordon - Excellent comment, John! – GaryMBloom Dec 07 '17 at 19:28
  • @boulderj - what is the full path to the python and pythonw that you found? And what's the version from pip? (as per John's comment) – GaryMBloom Dec 07 '17 at 19:30
  • @boulderj - It's also possible that you did something wrong installing **xlutils**. You can always try reinstalling it. You can type 'pip install --upgrade xlutils' and see what happens. – GaryMBloom Dec 07 '17 at 19:31
  • I am running Spyder from the Anaconda install. My pip is using Python 2.7 and the pip is 9.0.1 full path to python27 is c:\python27\lib\site-packages – boulderj Dec 07 '17 at 19:33
  • @Gary when I did the xlutils upgrade it says it is already up to date. Could it be the IDE that I am using? – boulderj Dec 07 '17 at 19:35
  • @boulderj - when you type pip --version, it should tell you more. Mine says `pip 9.0.1 from c:\python27\lib\site-packages (python 2.7)`. What path does yours say? – GaryMBloom Dec 07 '17 at 19:35
  • @Gary mine says the exact same thing. – boulderj Dec 07 '17 at 19:35
  • @boulderj Spyder probably came with its own Python installation. I use PyCharm, and it asks me which Python installation I want to use. I expect Spyder does something similar. Unless Spyder has a mechanism for installing packages, you need to figure out how to config Spyder to point to YOUR c:\python27\ python installation. – GaryMBloom Dec 07 '17 at 19:38
  • Ok. Thank you. It seems weird, though because I have installed other modules like openpyxl and that seems to work just fine. – boulderj Dec 07 '17 at 19:45
  • 1
    well, if you're on anaconda, then you should not use pip, but rather conda install... anaconda uses a virtual env, so did you use the conda prompt or a regular windows prompt when installing? Note: pip works on anaconda installs I use it regularly, however the conda folks don't recommend it. – ahed87 Dec 07 '17 at 19:46
  • also why are you hooked on this, there are other roads that lead to rome..., you have the anaconda install, meaning that you can read/write excel out of the box, so why not try to use what comes out of the box if you have issues with installing something new? – ahed87 Dec 07 '17 at 19:48
  • @Gary02127 I do have more than one xlutils versions in the site-packages folder. Do you think that could be the issue? – boulderj Dec 07 '17 at 19:49
  • @ahed87 I do notice that the Spyder installation directory is set up much like a Python installation, with .\Lib and .\Lib\site-packages directories, so what ahed is saying makes sense. I never used a virtual environment, so I can't contribute much more. The simple answer is that somehow, for some reason, the xlutils is getting put in a place where you can't see it. Seems buggy! – GaryMBloom Dec 07 '17 at 19:51
  • @ahed87 do you have reccomendation of code to use by just using conda to write like I am attempting to? – boulderj Dec 07 '17 at 19:51
  • to begin with, use the anaconda promt (in the start menu), that one is set up properly. Then just write conda install xlutils, but in your case I would uninstall xlutils first (with pip since you used that). it will tell you if it has the package or not, if not you can try with conda-forge or pip. However I think you are chasing your own tail, if you properly describe (= example data) the input data, and also what you expect as final outcome (=example data), someone will help you to code it with a pure anaconda install (probably based on dataframes). – ahed87 Dec 07 '17 at 19:59
  • @ahed87 I updated an old question of mine to ask. https://stackoverflow.com/questions/47700554/writing-a-list-to-new-excel-xlsx-with-dataframes – boulderj Dec 07 '17 at 20:12
  • @boulderj - No, I don't think multiple versions should be causing the problem, but, again, I've never used a VE... – GaryMBloom Dec 08 '17 at 01:55