weixin_39725844
2021-01-11 17:15 阅读 2

Version conflict importing surprise

Description

I'm trying to use surprise in the Google Collaborative notebooks for python 3.

The library is installed with the command: !pip install surprise

And the answer is ok:


Requirement already satisfied: surprise in /usr/local/lib/python3.6/dist-packages (0.1)
Requirement already satisfied: scikit-surprise in /usr/local/lib/python3.6/dist-packages (from surprise) (1.0.6)
Requirement already satisfied: six>=1.10.0 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (1.11.0)
Requirement already satisfied: scipy>=1.0.0 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (1.1.0)
Requirement already satisfied: numpy>=1.11.2 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (1.14.6)
Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.6/dist-packages (from scikit-surprise->surprise) (0.12.5)

But when I try to import the library: import surprise

I have the following error:


---------------------------------------------------------------------------
ContextualVersionConflict                 Traceback (most recent call last)
<ipython-input-38-7ee1a83cf20e> in <module>()
----> 1 import surprise

/usr/local/lib/python3.6/dist-packages/surprise/__init__.py in <module>()
     33            'dump', 'KNNWithZScore', 'get_dataset_dir', 'model_selection']
     34 
---> 35 __version__ = get_distribution('scikit-surprise').version

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in get_distribution(dist)
    474         dist = Requirement.parse(dist)
    475     if isinstance(dist, Requirement):
--> 476         dist = get_provider(dist)
    477     if not isinstance(dist, Distribution):
    478         raise TypeError("Expected string, Requirement, or Distribution", dist)

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in get_provider(moduleOrReq)
    350     """Return an IResourceProvider for the named module or requirement"""
    351     if isinstance(moduleOrReq, Requirement):
--> 352         return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    353     try:
    354         module = sys.modules[moduleOrReq]

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in require(self, *requirements)
    893         included, even if they were already activated in this working set.
    894         """
--> 895         needed = self.resolve(parse_requirements(requirements))
    896 
    897         for dist in needed:

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in resolve(self, requirements, env, installer, replace_conflicting, extras)
    784                 # Oops, the "best" so far conflicts with a dependency
    785                 dependent_req = required_by[req]
--> 786                 raise VersionConflict(dist, req).with_context(dependent_req)
    787 
    788             # push the new requirements onto the stack

ContextualVersionConflict: (scipy 0.19.1 (/usr/local/lib/python3.6/dist-packages), Requirement.parse('scipy>=1.0.0'), {'scikit-surprise'})
</module></module></ipython-input-38-7ee1a83cf20e>

Expected Results

I have tried others import with no problem, even external libraries to collab.

I have installed scipy again.

I have search in stack overflow but I can't find the issue


#### Versions
<!-- Please run the following snippet and paste the output below.
import platform; print(platform.platform())
import sys; print("Python", sys.version)
import surprise; print("surprise", surprise.__version__) --->



Linux-4.14.65+-x86_64-with-Ubuntu-18.04-bionic
Python 3.6.6 (default, Sep 12 2018, 18:26:19) 
[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]
---------------------------------------------------------------------------
ContextualVersionConflict                 Traceback (most recent call last)
<ipython-input-40-2650e1758aa9> in <module>()
      1 import platform; print(platform.platform())
      2 import sys; print("Python", sys.version)
----> 3 import surprise; print("surprise", surprise.__version__)

/usr/local/lib/python3.6/dist-packages/surprise/__init__.py in <module>()
     33            'dump', 'KNNWithZScore', 'get_dataset_dir', 'model_selection']
     34 
---> 35 __version__ = get_distribution('scikit-surprise').version

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in get_distribution(dist)
    474         dist = Requirement.parse(dist)
    475     if isinstance(dist, Requirement):
--> 476         dist = get_provider(dist)
    477     if not isinstance(dist, Distribution):
    478         raise TypeError("Expected string, Requirement, or Distribution", dist)

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in get_provider(moduleOrReq)
    350     """Return an IResourceProvider for the named module or requirement"""
    351     if isinstance(moduleOrReq, Requirement):
--> 352         return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
    353     try:
    354         module = sys.modules[moduleOrReq]

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in require(self, *requirements)
    893         included, even if they were already activated in this working set.
    894         """
--> 895         needed = self.resolve(parse_requirements(requirements))
    896 
    897         for dist in needed:

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in resolve(self, requirements, env, installer, replace_conflicting, extras)
    784                 # Oops, the "best" so far conflicts with a dependency
    785                 dependent_req = required_by[req]
--> 786                 raise VersionConflict(dist, req).with_context(dependent_req)
    787 
    788             # push the new requirements onto the stack

ContextualVersionConflict: (scipy 0.19.1 (/usr/local/lib/python3.6/dist-packages), Requirement.parse('scipy>=1.0.0'), {'scikit-surprise'})
-->
</module></module></ipython-input-40-2650e1758aa9>

Thanks very much for your support I need it a lot for a business challenge that I need to deliver next week.

Regards Javi

该提问来源于开源项目:NicolasHug/Surprise

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

12条回答 默认 最新

  • weixin_39966163 weixin_39966163 2021-01-11 17:15

    The command is pip install scikit-surprise

    But the problem comes from the fact that you have scipy 0.19 while surprise requires scipy 1.0 at least.

    try

    pip install "scipy>=1.0" and then pip install scikit-surprise

    点赞 评论 复制链接分享
  • weixin_39966163 weixin_39966163 2021-01-11 17:15

    looking at your logs again it seems that you have the 2 versions of scipy but I think it finds 0.19 before 1.0 so you get the error. You should probably use a virtual environment, or conda. Or if you're bold, delete the 0.19 version.

    This is not a problem with surprise though, this is a problem with your python environment, so please refer to other resources. Thanks!

    点赞 评论 复制链接分享
  • weixin_39725844 weixin_39725844 2021-01-11 17:15

    Thanks for your answer Nicolas.

    The google collab is on cloud they provide the linux environment.

    Listing the external libraries, I only find the updated version of the scipy

    image

    When I uninstall scipy I have the same error even when I haven't it.

    image

    Can you check it? pelase Google collaborative notebooks are free and your library is really great

    Thanks in advance for your support Javi

    点赞 评论 复制链接分享
  • weixin_39725844 weixin_39725844 2021-01-11 17:15

    This is the link to google collaboratoy notebooks

    https://research.google.com/colaboratory/faq.html

    Javi

    点赞 评论 复制链接分享
  • weixin_39966163 weixin_39966163 2021-01-11 17:15

    Try !pip install scipy numpy and only then !pip install scikit-surprise

    If it still doesn't work, try opening a new notebook. It works for me, though I have no idea what's going on

    点赞 评论 复制链接分享
  • weixin_39725844 weixin_39725844 2021-01-11 17:15

    Hi Nicolas,

    It's happening me the same but if is not happening to you is another issue probably my chrome browser I will follow investigating the issue and come back when I found a solution.

    I have done the following: !pip uninstall scipy nuympy

    !pip install scipy numpy

    !pip install scikit-surprise

    import surprise

    And finally I have the same error

    Regards Javi

    点赞 评论 复制链接分享
  • weixin_39725844 weixin_39725844 2021-01-11 17:15

    Just to update you, I have tested with different browsers, with different google users and different computers (this shouldn't be importan for cloud processing but just in case). I have the same fail in all of the attempts, I only can understand that is something in the europe google cloud is different..

    These are all the information that I have could obtain form the cloud

    image

    image

    I hope it helps

    Regards

    点赞 评论 复制链接分享
  • weixin_39966163 weixin_39966163 2021-01-11 17:15

    Unfortunately there's not much I can do regarding this. I don't know what's going on with google notebooks but the problem seems to be on their side (if the surprise installation was broken I would have had tons of issues already).

    Sounds like magic but I had the same issue as yours, then opened a new notebook and it worked. I don't even want to know why TBH...

    The best I can suggest is to install surprise locally? If you really want to use notebooks it works fine with jupyter.

    点赞 评论 复制链接分享
  • weixin_39725844 weixin_39725844 2021-01-11 17:15

    I really appreciate the effort and dedication that you have done to this issue. I have used in my computer and enjoyed a lot learning about recommendations with the different models of the library, i will use in the future a lot. Congrats for the excellent work done in the area.

    Regards Javi

    点赞 评论 复制链接分享
  • weixin_39966163 weixin_39966163 2021-01-11 17:15

    Thanks a lot! :)

    点赞 评论 复制链接分享
  • weixin_39610353 weixin_39610353 2021-01-11 17:15

    This is an annoying issue, but there's a weird fix. If you run this code, you reproduce the error:

    !pip install scikit-surprise import surprise

    After running the script (installing surprise), restart the colab runtime:

    fix_surprise

    Once you do this, rerun the script. It should import surprise without raising an exception. I hope somebody finds this helpful!

    点赞 评论 复制链接分享
  • weixin_39580041 weixin_39580041 2021-01-11 17:15

    This was helpful, although for a different package : symfit, which was giving the same error about the Conflicted Import. Thanks a lot.

    点赞 评论 复制链接分享

相关推荐