2

I am running a webapp2 sever in Google Cloud SDK and making use of the Naked module to run node.js scripts from python2 in a Vagrant box. While starting the server which has this code snippet

from Naked.toolshed.shell import muterun_js


def get_signed_hash(username):

    response_from_js = muterun_js('./views/api/generateSignedTransaction.js',
                                  nonce)
    signed_hash = response_from_js.stdout
    print('0x' + signed_hash)

I am getting this error message

ImportError: No module named Naked.toolshed.shell

I am making use of the requests library as well and that is not causing any problems. Tried to debug the problem as to maybe the location of the packages, they are both in the same place:

>>> import requests
>>> print(requests.__file__)
/home/vagrant/.local/lib/python2.7/site-packages/requests/__init__.pyc
>>> import Naked
>>> print(Naked.__file__)
/home/vagrant/.local/lib/python2.7/site-packages/Naked/__init__.pyc

Infact I ran the script in the same location as a standalone file calling get_signed_hash('username') and it runs successfully. Is there any other place I need to check?

Sushant Kumar
  • 435
  • 7
  • 24
  • 1
    Are you running this on App Engine Standard? Because you can't use libraries that depend on C headers and extensions, and [Naked](https://github.com/chrissimpkins/naked/tree/master/lib/Naked/toolshed/c) use them. – Mangu Oct 19 '18 at 09:37

1 Answers1

1

For the first generation standard environment apps dependencies need to be installed inside the app (or vendored-in). Having them in the system site-packages (where the regular, standalone apps are loading libraries from) is not enough. Even if you somehow convince the local development server to run the app, it won't work when uploaded to GAE as GAE doesn't have access to your local system.

Typically you'd install your library (and all its dependencies) inside a lib directory inside your app dir, so they could be uploaded to GAE together with your app. See Copying a third-party library.

Alternatively you could try to just symlink the Naked directory into your lib dir, which could work if its all other dependencies are already satisfied in a similar manner. See related How do I access a vendored library from a module in Python Google App Engine?

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
  • I am trying to use `subprocess.check_output` and `subprocess.call` but both are unavailable although they are a part of the official modules, as @Mangu has pointed out in the comments and also in the link shared by you its not possible to include modules with C dependancies. Do i need to use the process given by you for shipped modules as well? – Sushant Kumar Oct 19 '18 at 14:46
  • I don't think you can use `subprocess` either, due to another sandbox restriction - making not allowed system calls - can't launch processes. – Dan Cornilescu Oct 19 '18 at 16:48