1

I am trying to fix an error:

import version
ModuleNotFoundError: No module named 'version'

So I tried pip install version which gave me the error below:

from itertools import izip_longest
ImportError: cannot import name 'izip_longest'

So going through different forums, I realized I need to update the file using this import argument import izip_longest and update it to import zip_longest.

But that file version.py seems to be a temporary file and I am unable to access it in Windows 10.

C:\TruCalvin\testsfolder>pip install version

Collecting version
Using cached https://files.pythonhosted.org/packages/fd/b6/fa3b2c859d4d8817a106e4272029d78a2afbca0a27139997a4e5515bbf60/version-0.1.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\Tru~1\AppData\Local\Temp\pip-install-d5jk1cru\version\setup.py", line 4, in <module>
    from version import __version__
  File "C:\Users\Tru~1\AppData\Local\Temp\pip-install-d5jk1cru\version\version.py", line 2, in <module>
    from itertools import izip_longest
ImportError: cannot import name 'izip_longest'

Command "python setup.py egg_info" failed with error code 1 in C:\Users\Tru~1\AppData\Local\Temp\pip-install-d5jk1cru\version\

How do I mitigate this issue and edit the file so that I can run pip install version successfully?

Thanks in advance.

1
  • Updated Setup tools as below >>> pip install -U setuptools but the error remained. from itertools import izip_longest ImportError: cannot import name 'izip_longest' Command "python setup.py egg_info" failed with error code 1 in C:\Users\Tru~1\AppData\Local\Temp\pip-install-rlj_le73\version\
    – Vizag
    Commented Apr 21, 2019 at 13:09

2 Answers 2

0

Overiew

As a rule, pip pulls modules from PyPI. The project you are attempting to install is listed there as version. So rather than using pip, you can simply download the files yourself as a compressed tar.gz archive using the Download files link. In your case, this archive includes version.py.

Installation

To alter and then install version.py in Python 3.x:

  • Fully extract version-0.1.1.tar.gz (you can use 7-zip for this on Windows). Note that you will need to go through the process of decompressing the archive twice (once for the original version-0.1.1.tar.gz file, then once for the remaining version-0.1.1.tar file).

  • Find version.py. Replace import izip_longest with import zip_longest, as noted in your original question, and then save version.py.

  • Open a command window in the same folder as version.py (ex. Shift + Right-ClickOpen command window hereinstructions on enabling this feature in Windows 10).

  • Run e.g. python setup.py install to install your altered copy of version.py.

Caveats

You are likely aware of this, but the reason you are running into the issue with import izip_longest verus import zip_longest is because this module is intended for Python 2.x, not Python 3.x. It is also noted on the module page on PyPi that the module itself is (was) in an "Alpha" stage of development. With that in mind, though not guaranteed, you may still run into issues down the road when actually using the module.

2
  • It worked Got till that final step, but That final step was what I was doing wrong earlier. 'python setup.py install', I was earlier trying to run <python setup.py egg_info> which is obviously not the correct way. Thank you so much. for your detailed response which helped me here. As you have rightly pointed out, now I have a new error which is a good sign :-) will continue on it.
    – Vizag
    Commented Apr 21, 2019 at 20:18
  • Lol well I am glad (???) to hear that. Good luck. =) Commented Apr 21, 2019 at 20:22
0

Bit late for this and there may be things about the version package which are worthwhile.

But, chasing this "cannot import name 'izip_longest'" error, I realised that in fact that the PyPi package I really needed (and had used before) was packaging, not version. packaging has a module version and a class packaging.version.Version.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .