benjaminp / six

Python 2 and 3 compatibility library
https://six.readthedocs.io/
MIT License
978 stars 274 forks source link

Fail to imoprt cPickle by other module(Theano) #132

Open benjaminp opened 8 years ago

benjaminp commented 8 years ago

Originally reported by: Yiqun Liu (Bitbucket: yiqun_liu, GitHub: Unknown)


Yesterday, I updated all the packages via pip and theano couldn't be imported due to following error:

#!Terminal

>>> import theano
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/theano/__init__.py", line 52, in <module>
    from theano.gof import (
  File "/Library/Python/2.7/site-packages/theano/gof/__init__.py", line 38, in <module>
    from theano.gof.cc import \
  File "/Library/Python/2.7/site-packages/theano/gof/cc.py", line 30, in <module>
    from theano.gof import link
  File "/Library/Python/2.7/site-packages/theano/gof/link.py", line 18, in <module>
    from theano.gof.type import Type
  File "/Library/Python/2.7/site-packages/theano/gof/type.py", line 17, in <module>
    from theano.gof.op import CLinkerObject
  File "/Library/Python/2.7/site-packages/theano/gof/op.py", line 25, in <module>
    from theano.gof.cmodule import GCC_compiler
  File "/Library/Python/2.7/site-packages/theano/gof/cmodule.py", line 8, in <module>
    import six.moves.cPickle as pickle
ImportError: No module named cPickle

It seems that the problem comes from six - Yet I've tried importing cPickle itself in python and it didn't fail. Moreover, the issue still existed even after I updated Theano to the bleeding edge version. And my terminal returned these words when I typed 'pip show six':

#!Terminal

---
Metadata-Version: 2.0
Name: six
Version: 1.9.0
Summary: Python 2 and 3 compatibility utilities
Home-page: http://pypi.python.org/pypi/six/
Author: Benjamin Peterson
Author-email: benjamin@python.org
License: MIT
Location: /Library/Python/2.7/site-packages
Requires: 

Evidently, I've six installed on my computer. Therefore, I can make sure that the problem is due to a bug of six. Please fix the issue, thanks.


benjaminp commented 8 years ago

Original comment by Andrew Arrasmith (Bitbucket: aarrasmi, GitHub: aarrasmi):


Hi Matthias,

I tried it with both the latest release of Theano and the "bleeding edge" version on the git repo. By up to date I mean the version that I get with pip with the upgrade flag. My copy of Theano (I reverted to the latest release) has version 1.9.0 of six installed with it, and and my machine has six 1.10.0 installed.

I think that in just now confirming I had the latest versions (which I did last night as well) I may have found the problem. It seems that for some reason my pip upgrade calls last night didn't remove a copy of 1.5.2 (and I must have missed it in the output of the find command you recommend above) while just now redoing

#!BASH
sudo pip install -U six

found and removed the old version.

I must have been doing something stupid last night and somehow missing this.

Sorry to bother you over what was probably just an old version that was hiding from me, and thank you for your response.

Andrew

benjaminp commented 8 years ago

Original comment by Matthias Liebig (Bitbucket: mliebig, GitHub: Unknown):


Hello Andrew,

which version of six do you use ("up to date" with what)? And when you are patching Theano, you might want to try the following:

#!python

import six
print(six.__file__)

in order to find out which module is actually used.

Note: The Theano's git repo contains a copy of six, which is new enough to support "import six.moves.cPickle".

benjaminp commented 8 years ago

Original comment by Andrew Arrasmith (Bitbucket: aarrasmi, GitHub: aarrasmi):


Hi,

I have had what seems to be the same issue. After a little experimentation I have found that while

#!python

import six.moves.cPickle

doesn't work

#!python

from six.moves import cPickle

does. I am fairly confused by this, but I got Theano working by replacing the instances of

#!python

import six.moves.(name)

with

#!python

from six.moves import (name)

This behaviour seems odd to me, but I thought it might be relevant to the discussion here (which I found while trying to solve my issue) so I am contributing it.

If it is relevant, I am running Linux Mint 17.1 and have made sure that Theano and six are fully up to date and removed all old copies.

benjaminp commented 8 years ago

Original comment by Matthias Liebig (Bitbucket: mliebig, GitHub: Unknown):


In issue #134 the following issue with pip is mentioned: https://github.com/pypa/pip/issues/3165 The dev there wrote, that "OS X El Capitan ships with six 1.4.1".

Maybe this is also the cause for your problem with Theano? The old version of six might be in your sys.path ahead of the one installed with pip. So you might want to try

#!bash

find / -type f -name 'six.py*'

after all in order to verify this.

benjaminp commented 8 years ago

Original comment by Yiqun Liu (Bitbucket: yiqun_liu, GitHub: Unknown):


@mliebig Unfortunately, the first line doesn't work. But

#!Terminal

import cPickle

works well. I assume that cPickle is placed incorrectly.

benjaminp commented 8 years ago

Original comment by Matthias Liebig (Bitbucket: mliebig, GitHub: Unknown):


Could you please try invoking the failing import manually:

#!python

import six.moves.cPickle

If it works, it might be that another, older copy of six is shadowing the one you pasted. Try finding it, e.g. with

#!bash

find /Library -type f -iname 'six.py*'

or

#!bash

find / -type f -iname 'six.py*'