简体   繁体   中英

Installing openpyxl with python2.7 results in "ImportError : no module named util"

I have Python 2.7.14. I know that Python 2 is deprecated but I don't have choice for the moment.

I tried to install openpyxl library.

I downloaded and extracted the .tar.gz. The version downloaded is 3.0.3.

When I run python setup.py install , I'm facing the following error:

Traceback (most recent call last):
    File "setup.py", line 28, in <module>
        from importlib.util import module_from_spec, spec_from_file_location
ImportError: No module named util

How can I solve this issue for Python 2.7.14?

From the openpyxl release history , the last version compatible with Python2.7 is 2.6.4:

https://openpyxl.readthedocs.io/en/stable/changes.html#id16

2.6.4 (2019-09-25)

Final release for Python 2.7 ––––––––––––––––––––––––––––

Starting openpyxl 3.0.0 , it is Python-3 only.
So, you need to install a specific older version.

Using pip :

$ python -V
Python 2.7.17

$ python -m pip install openpyxl==2.6.4

Using the downloadable tar.gz from PyPi :

$ wget https://files.pythonhosted.org/packages/d6/26/eb28e975b7a37aad38d7ec4f7a0f652bdee6ecf36e6bd06f473c5af9b87b/openpyxl-2.6.4.tar.gz
$ mkdir openpyxl-2.6.4
$ tar -xvzf openpyxl-2.6.4.tar.gz -C openpyxl-2.6.4
$ cd openpyxl-2.6.4
$ python setup.py install

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM