0

I have a small python (2.7) script that works with several threads. One of the threads will read a global list and post an https post request for each one of the entries of this list.

For doing that I saw that the best way is to use python requests module. I have installed it with pip (no problem with that, it is placed in ...Python/2.7/site-packages/requests/...), but, when I import this module in my script, I get an error.

I have created another script with just one line (import requests) to reproduce the error, and I get this:

Traceback (most recent call last):
  File "req.py", line 1, in <module>
    import requests
  File "/Library/Python/2.7/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Library/Python/2.7/site-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/Library/Python/2.7/site-packages/urllib3/connectionpool.py", line 11, in <module>
    from .exceptions import (
  File "/Library/Python/2.7/site-packages/urllib3/exceptions.py", line 2, in <module>
    from .packages.six.moves.http_client import (
  File "/Library/Python/2.7/site-packages/urllib3/packages/six.py", line 203, in load_module
    mod = mod._resolve()
  File "/Library/Python/2.7/site-packages/urllib3/packages/six.py", line 115, in _resolve
    return _import_module(self.mod)
  File "/Library/Python/2.7/site-packages/urllib3/packages/six.py", line 82, in _import_module
    __import__(name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 69, in <module>
    from array import array
  File "/Users/carlestalenssebastia/Documents/mychip/raspberry pi/array.py", line 3, in <module>
IndexError: list index out of range

Python 2.7.10 MacBook Pro with macOS Sierra (v 10.12)

Am I doing something wrong? Didn't I installed the module in the proper way?

  • 2
    you need to rename the file called `array.py` in your folder raspberry pi, its creating a conflict – PRMoureu Aug 21 '17 at 20:30
  • Welcome to SO: In general, you should not name your modules the same name as python supplied modules....it creates conflicts. Try, if you must, something like `my_array` or better yet something more descriptive. – Shawn Mehan Aug 21 '17 at 20:32
  • Holy ****. I didn't even created that file, maybe it was an error while installing something. Moreover, it was a .pyc file, that obviously I didn't created (not intentionally, at least). Thank you guys. – animaldesequia Aug 21 '17 at 20:48

1 Answers1

1

it seems that you're having two modules with the same name array.py rename your local array.py module to something more unique to resolve this.

take a look at this answer for more info on how to handle this issue and here to learn more on how python import system works.

ShmulikA
  • 3,468
  • 3
  • 25
  • 40
  • Yes, I had a array.pyc (I don't know how it was created), and in the file editing program I was using it was hidden. Once I checked it in the terminal, I deleted it and proceed successfully. – animaldesequia Aug 21 '17 at 20:50
  • 1
    PS: +1 for the link to the little explanation about python module importing system – animaldesequia Aug 21 '17 at 20:51