Why can I import module bs4 or requests from python IDLE shell but not from the python interpreter?
Question: I can import module BeautifulSoup or requests without any problem when I run
it from my script or do it directly in the python IDLE shell:

    
    
    Python 2.7.9 (default, Mar  8 2015, 00:52:26) 
    [GCC 4.9.2] on linux2
    Type "copyright", "credits" or "license()" for more information.
    >>> import bs4
    >>> bs4
    <module 'bs4' from '/usr/local/lib/python2.7/dist-packages/bs4/__init__.pyc'>
    >>> import requests
    >>> requests
    <module 'requests' from '/usr/lib/python2.7/dist-packages/requests/__init__.pyc'>
    

However, when I do it from the command prompt using the python interpreter I
run into the following errors:

    
    
    pi@raspberrypi:~/Desktop/A/C $ python
    Python 2.7.9 (default, Mar  8 2015, 00:52:26) 
    [GCC 4.9.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import bs4
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python2.7/dist-packages/bs4/__init__.py", line 30,     in <module>
        from .builder import builder_registry, ParserRejectedMarkup
      File "/usr/local/lib/python2.7/dist-packages/bs4/builder/__init__.py",         line 4, in <module>
        from bs4.element import (
      File "/usr/local/lib/python2.7/dist-packages/bs4/element.py", line 3, in <module>
        from pdb import set_trace
      File "/usr/lib/python2.7/pdb.py", line 9, in <module>
        import cmd
      File "/usr/lib/python2.7/cmd.py", line 53, in <module>
        IDENTCHARS = string.ascii_letters + string.digits + '_'
    AttributeError: 'module' object has no attribute 'ascii_letters'
    >>> import requests
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/dist-packages/requests/__init__.py", line 55, in <module>
        import urllib3
      File "/usr/lib/python2.7/dist-packages/urllib3/__init__.py", line 10, in <module>
        from .connectionpool import (
      File "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 29, in <module>
        from .packages.ssl_match_hostname import CertificateError
      File "/usr/lib/python2.7/dist-packages/urllib3/packages/__init__.py", line 5, in <module>
        from ssl import CertificateError
      File "/usr/lib/python2.7/ssl.py", line 90, in <module>
        import textwrap
      File "/usr/lib/python2.7/textwrap.py", line 40, in <module>
        class TextWrapper:
      File "/usr/lib/python2.7/textwrap.py", line 82, in TextWrapper
        whitespace_trans = string.maketrans(_whitespace, ' ' * len(_whitespace))
    AttributeError: 'module' object has no attribute 'maketrans'
    

I read a lot of forums, but didn't really understood what could be causing
this, and most importantly, how to solve it.

Many thanks for your help, Best, Mathieu


Answer: It is not really IDLE vs. Python shell on console but where the current
working directory for the process is. Because in the directory from wich you
start the console Python shell there is a `string.py` which ”shadows” the
`string` module from the standard library. Delete that `string.py` (and the
`string.pyc` if it exists) from that folder and other modules will find the
standard `string` module again.

