title: Python/C API can't import urllib2 library
body: <p>I have to parse a HTML url and return a list of url to use a recursive method of parsing. I'm using BeautifulSoup on Mac OS and I have a problem to import <code>html_parser.py</code></p>
  
  <p>html_parser.py :</p>
  
  <pre><code>#!/usr/local/bin/python2.7
  from bs4 import BeautifulSoup
  import urllib2
  
  
  def link_list(urlString):
      siteFile = urllib2.urlopen(urlString)
      siteHTML = siteFile.read()
      siteFile.close()
      soup = BeautifulSoup(siteHTML, "html.parser")
      liste = []
      for links in soup.find_all('a'):
          print(links.get('href'))
          liste.append(links.get('href'))
      return liste
  </code></pre>
  
  <p>pars.c :</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;Python.h&gt;
  
  int main() {
    Py_Initialize();
  
    /* 1st: Import the module */
      PyRun_SimpleString("from bs4 import BeautifulSoup\n");
      PySys_SetPath(".");
      PyObject* moduleString = PyString_FromString((char*) "html_parser");
      if (!moduleString) {
          PyErr_Print();
          printf("Error formating python script\n");
      }
  
      PyObject* module = PyImport_Import(moduleString);
      if (!module) {
          PyErr_Print();
          printf("Error importing python script\n");
      }
  
      /* 2nd: Getting reference to the function */
      PyObject* function = PyObject_GetAttrString(module, (char*)"link_list");
      if (!function) {
          PyErr_Print();
          printf("Pass valid argument to link_list()\n");
      }
  
      Py_Finalize();
      return 0;
  }
  </code></pre>
  
  <p>I need to use <code>PySys_SetPath(".")</code> to set the Python Path to my working directory. But by doing this it doesn't recognize bs4, so before changing the path I use <code>PyRun_SimpleString("from bs4 import BeautifulSoup\n")</code> but when I'm trying to do the same thing for urllib2 (<code>PyRun_SimpleString("import urllib2\n")</code>) I got this error :</p>
  
  <pre class="lang-none prettyprint-override"><code>  Traceback (most recent call last):
    File "&lt;string&gt;", line 1, in &lt;module&gt;
    File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 94, in &lt;module&gt;
      import httplib
    File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 80, in &lt;module&gt;
      import mimetools
    File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py", line 6, in &lt;module&gt;
      import tempfile
    File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in &lt;module&gt;
      import io as _io
    File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in &lt;module&gt;
      import _io
  ImportError: dlopen(/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
    Referenced from: /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
    Expected in: flat namespace
   in /usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  </code></pre>
  
  <p>Someone helped me, but before the name of my Python program was <code>parser.py</code>and then when we don't use the SetPath c is using an another file int default Python Path. So Python.h doesn't recognize ether bs4 and urllbi2.</p>
  
  <p><strong>EDIT :</strong> </p>
  
  <p>I just checked the version of my system with <code>PyRun_SimpleString("print(sys.version)")</code> and got this :</p>
  
  <pre><code>2.7.10 (default, Jul 30 2016, 19:40:32)
  [GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)]
  </code></pre>
  
  <p>So I'm on Python 2.7.10 and not Python 3, I don't have to use url.request module...</p>