I am using RPiCam_Webinterface for testing my camera. While Rpicam_Webinterface is working I can't use my camera to do anything else from commandline(like raspivid or raspistill). So to use raspistill I stop the RPiCam_Webinterface using ./RPi_Cam_Web_Interface_Installer.sh stop
It stops. Now I do raspistill -o 0.jpg works fine.
But when I go in python shell and do >>> import picamera

Traceback (most recent call last):   File "<stdin>", line 1, in <module>   File "/usr/lib/python2.7/dist-packages/picamera/__init__.py", line 82, in <module>
    from picamera.camera import PiCamera   File "/usr/lib/python2.7/dist-packages/picamera/camera.py", line 81, in <module>
    import mimetypes   File "/usr/lib/python2.7/mimetypes.py", line 29, in <module>
    import urllib   File "/usr/lib/python2.7/urllib.py", line 26, in <module>
    import socket   File "socket.py", line 6, in <module>
    server_socket = socket.socket() TypeError: 'module' object is not callable

Why is this happening? Is my socket being occupied (not sure the technical term to use) by RPiCam_Webinterface? Basically is RPiCam_Webinterface not allowing import of socket module ? But on stoppage it does allow raspistill & raspivid

  • I don't think that socket has anything to do with the camera itself; more likely it is for streaming output or something (I've never used python's picamera so I don't know all of what it does). Are you saying this error doesn't happen if you try it before starting RPiCam_Webinterface? – goldilocks May 18 '15 at 14:08
  • Removed RPI_Cam_Webinterface still picamera not working. Something else is creating the problem. – Coderaemon May 18 '15 at 14:17
  • I'm not really a python user so I'm not of much help beyond that, but could this be because you are using the python 3.x shell? I know that it is not completely backward compatible with 2.x code. – goldilocks May 18 '15 at 14:24
  • So I copied the python file to an outer directory (which doesn't have RPI cam interface folder) and now its working . So there is some compatibility issue between RPi interface and picamera ? – Coderaemon May 18 '15 at 16:10
  • Sounds like it could be some kind of namespace collision -- but again I've used python so little I don't know anything about how it resolves these kinds of things. – goldilocks May 18 '15 at 18:39

I suspect the issue here is that the script was being run in a directory where another socket.py file existed. When importing modules, Python by default looks in the current directory first. Only if the module is not found there does Python move on to search other directories (like /usr/lib/python2.7, etc). The module search path can be inspected as follows:

>>> import sys
>>> sys.path
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.7', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client', '/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode']

Note that the first entry is blank (which means search the current directory). So, the chain of events that occurred above was as follows:

  1. User runs import picamera in the interpreter
  2. The interpreter imports picamera
  3. picamera imports mimetypes
  4. mimetypes imports urllib
  5. urllib attempts to import socket
  6. At this point the interpreter finds socket.py in the current directory and imports it instead of the "official" socket.py in the Python distribution
  7. Something in socket.py attempts to execute socket.socket() to create a new socket, but the socket.py that got imported doesn't have a callable named "socket" and the script crashes

The morale of the story is "don't named your files after top level modules in the standard library (at least when you want to use those same modules). Admittedly this may be tricky, given the extensive nature of Python's standard library!

| improve this answer | |

Have you installed the module itself?

sudo apt-get install python-picamera


sudo pip install picamera

The second only works if you have installed pip with sudo apt-get install python-pip

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.