title: Error trying to import pysftp in Lambda: cannot import name '_bcrypt' from partially initialized module 'bcrypt' (most likely due to circular import)
body: <p>I'm trying to import pysftp in my AWS lambda function, but I'm getting this error:
  &quot;Unable to import module 'app': cannot import name '_bcrypt' from partially initialized module 'bcrypt' (most likely due to a circular import)&quot;</p>
  <p>The only code I have written in my function is the basic default code plus my pysftp import:</p>
  <pre><code>import json
  import pysftp
  def lambda_handler(event, context):
      return {
          &quot;statusCode&quot;: 200,
          &quot;body&quot;: json.dumps({
              &quot;message&quot;: &quot;hello world&quot;,
              # &quot;location&quot;: ip.text.replace(&quot;\n&quot;, &quot;&quot;)
          }),
      }
  </code></pre>
  <p>bycrpt is a package that automatically gets installed when pysftp is installed, so when I try to import pysftp, it is connected to bycrpt. The way I connected all my libraries/packages to my lambda was by zipping together all the site-packages in my virtual environment into one folder and uploading that into a lambda layer. I then connected that layer to my function. It seems that the layer connection is working, because before I tried that method, I was getting the error &quot;Unable to import module 'app': No module named 'pysftp'&quot;. So at least I'm not getting that error anymore.</p>
  <p>I also tried zipping all my packages and my lambda function together in one folder and then uploading that zipped folder directly into my lambda function (as shown in this video: <a href="https://www.youtube.com/watch?v=yyBSeGkuPqk" rel="nofollow noreferrer">https://www.youtube.com/watch?v=yyBSeGkuPqk</a>), but I'm getting the same error. Using the layer method is much simpler so I'd rather stick with that.</p>
  <p>When I tried researching my specific error, all I could really find were people that had listed their imports in incorrect orders, or were importing packages multiple times. But I'm not doing either of those. I'm just trying to get the simple default code to work.</p>
  <p>Any help is much appreciated! Thank you!</p>