jaraco / wolframalpha

MIT License
148 stars 25 forks source link

ImportError: No module named 'jaraco.itertools' #18

Closed yccmoe closed 5 years ago

yccmoe commented 5 years ago

I installed it through the pip, but the following error occurs: How do we deal with this?

15:07 ~ $ pip3.7 install --user wolframalpha
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: wolframalpha in ./.local/lib/python3.7/site-packages (3.0.1)
Requirement already satisfied: xmltodict in ./.local/lib/python3.7/site-packages (from wolframalpha) (0.12.0)
Requirement already satisfied: jaraco.itertools>=2.0 in ./.local/lib/python3.7/site-packages (from wolframalpha) (4.4.2)
Requirement already satisfied: six in /usr/lib/python3.7/site-packages (from wolframalpha) (1.11.0)
Requirement already satisfied: more-itertools>=4.0.0 in /usr/lib/python3.7/site-packages (from jaraco.itertools>=2.0->wolframalpha) (4.3.0)
Requirement already satisfied: inflect in ./.local/lib/python3.7/site-packages (from jaraco.itertools>=2.0->wolframalpha) (2.1.0)

15:08 ~ $ python3.7
Python 3.7.0 (default, Aug 22 2018, 20:50:05) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wolframalpha
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yamcc/.local/lib/python3.7/site-packages/wolframalpha/__init__.py",
 line 7, in <module>
    from jaraco.itertools import always_iterable
ModuleNotFoundError: No module named 'jaraco.itertools'
jaraco commented 5 years ago

tl;dr - skip to Investigation below.

Background

The issue is that the jaraco namespace switched from pkg_resources-style namespaces to pkgutil-style namespaces (see jaraco/jaraco.functools#9)... and you probably had an older jaraco.* package installed in that environment (or in the system environment).

Your best bet is to install the latest jaraco.* packages. To figure out which packages you might have installed using the pkg_resources style namespacing is to import jaraco, then look at jaraco.__file__ to see where the jaraco namespace package is coming from... and then inspect that environment (site-packages, etc.) to see what jaraco packages are installed in what version. You may be able to use pip list | grep jaraco to achieve something similar.

Then, I would look at the history for each of those packages and see which ones may need to be upgraded. You may want to use a tool like pipdeptree to determine which packages caused those jaraco packages to be installed.

Alternatively, you could just start from scratch in a clean virtualenv or environment... new environments will get the latest jaraco.* packages and should work without problems.

A third option, which I wouldn't recommend, could be to downgrade jaraco.wolframalpha to a version prior to the switch.

Investigation

When I started looking into which version of jaraco.wolframalpha got the update, I noticed there was no such update. I need to do more investigation.

yccmoe commented 5 years ago
$ pip3.7 list | grep wolframalpha
wolframalpha                     3.0.1  

$ pip3.7 list | grep jaraco
jaraco.functools                 1.20       
jaraco.itertools                 4.4.2  

In fact, I set up the environment 12 hours ago. I installed Wolframalpha today, and jarco is also..

I have lib files that used to work well in Python 3.5. Is it OK to simply copy and paste?

jaraco commented 5 years ago

Okay. I was confused. There's no such thing as jaraco.wolframalpha, so there's nothing that this package (wolframalpha) can do to about this issue. As a result, I'll close this ticket... but my original two suggestions stand - either track down and correct the incompatible jaraco.* packages or create a new environment with compatible versions. Feel free to follow up here or in jaraco/jaraco.functools#9 if you have more specific information with which I may help.

jaraco commented 5 years ago

So - jaraco.functools got the pkgutil treatment in version 2.0 and jaraco.itertools got it in 4.0. So that's the root of your issue. I suggest to simply pip install -U jaraco.functools (possibly with pip3.7 and --user to match your previous usage). That should get you 2.0 and correct the issue.

yccmoe commented 5 years ago
$ pip3.7 install --upgrade --user jaraco.functools
Looking in links: /usr/share/pip-wheels
Collecting jaraco.functools
  Downloading https://files.pythonhosted.org/packages/12/a4/3e7366d0f5e75dcad7be88524c8cbd0f3a9fb1db243269550981740c57fe/jaraco.functools-2.0-py2.py3-none-any.whl
Requirement already satisfied, skipping upgrade: more-itertools in /usr/lib/python3.7/site-packages (from jaraco.functools) (4.3.0)
Requirement already satisfied, skipping upgrade: six<2.0.0,>=1.0.0 in /usr/lib/python3.7/site-packages (from more-itertools->jaraco.functools) (1.11.0)
Installing collected packages: jaraco.functools
Successfully installed jaraco.functools-2.0

$ pip3.7 list | grep jaraco
jaraco.functools                 2.0        
jaraco.itertools                 4.4.2  

and...

$ python3.7
Python 3.7.0 (default, Aug 22 2018, 20:50:05) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wolframalpha
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yamcc/.local/lib/python3.7/site-packages/wolframalpha/__init__.py", 
line 7, in <module>
    from jaraco.itertools import always_iterable
ModuleNotFoundError: No module named 'jaraco.itertools'

>>> import jaraco.itertools
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'jaraco.itertools'

I've updated it, but there's still a problem.

I don't know the Github rules well. Is it OK to write on a "closed" issue?
Should it be written following jaraco/jaraco.functools#9 ?

jaraco commented 5 years ago

You're welcome to continue the conversation here.

I suspect that the issue is that there's still an older jaraco.* package installed somewhere, probably in your system site-packages.

What happens when you

>>> import jaraco
>>> jaraco.__path__
...
>>> jaraco.__file__
...
yccmoe commented 5 years ago

I'm ashamed, but I solved it. I didn't learn Python anywhere, so I solved it with my own crutches.

Crutches way

jaraco commented 5 years ago

With that reference, I now can see the issue, and I too encountered this issue with Python Anywhere. I encountered the same issue. I can't remember if I wrote to the Python Anywhere team about it or not (I can't find anything in my e-mail nor the forums), but I believe the issue stems from the fact that Python Anywhere comes with some packages pre-installed that depend on some (older) versions of packages in the jaraco.* namespace... and since you don't have control over those packages, and because pkg_resources-style packages use .pth files to install the namespace and .pth files are processed early in the interpreter startup, you have little recourse to prevent those older packages from influencing your environment. I'm glad you found a workaround.