4

I am getting below error when trying to import the urllib2:

>>> import urllib2

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/urllib2.py", line 94, in <module>
import httplib
File "/usr/lib64/python2.7/httplib.py", line 69, in <module>
from array import array

ImportError: cannot import name array`

Any thoughts on it?

TerryA
  • 58,805
  • 11
  • 114
  • 143
S R
  • 657
  • 3
  • 10
  • 21
  • Could you be shadowing the stdlib's `array.py` with one of your own? Try `import array` and then `print array.__file__` to rule this out. – DSM Apr 02 '13 at 12:28
  • `array.__file__ == '/usr/lib64/python2.7/lib-dynload/arraymodule.so'` – User Apr 02 '13 at 12:42
  • Well, if you did that in the same state that you did `import urllib2`, that rules out the single most common source of this kind of `ImportError`. Hmmm. I'd still be tempted to edit `httplib.py` and add `import array; print array.__file__; print dir(array)` right before the `from array import array` line, to see what it thinks it has available to import. – DSM Apr 02 '13 at 13:02
  • @DSM- Didn't worked.. – S R Apr 02 '13 at 14:20
  • What do you mean "didn't work"? `print` statements aren't there to fix it, they're trying to help us figure out what the problem is. – DSM Apr 02 '13 at 14:58
  • @DSM- I treid that too which din't worked! Thanks anyways..@Ramesh's solution worked :) – S R Apr 02 '13 at 17:27
  • Possible duplicate of [How to access a standard-library module in Python when there is a local module with the same name?](https://stackoverflow.com/questions/1900189/how-to-access-a-standard-library-module-in-python-when-there-is-a-local-module-w) – Isaiah Norton Nov 19 '19 at 16:28

1 Answers1

8

It seems you have a python program named "array.py" in you present working directory. If yes rename that python program or move it to some other directory.

Ramesh Raithatha
  • 544
  • 1
  • 7
  • 18