No module named Crypto.Cipher on local mac AppEngine - google-app-engine

No module named Crypto.Cipher
when I try to import
from Crypto.Cipher import AES
My folder structure looks like this:
test/
test/main.py
test/pycrypto-2.3
I ran the build and install inside of the pycrypto folder but I keep getting the error, any ideas?

It does not work with the usual easy_install, or running setup.py, depending on your Mac OS X version. This is due to how Google App Engine only allows for libraries loaded from certain directories. See here for more discussion: http://code.google.com/p/googleappengine/issues/detail?id=1627

You don't need to include pycrypto in your app; you need to install it the standard way for a Python library. If you've done that, the most likely reason it's not working is because you installed it (Eg, using easy_install) for a different version or installation of Python than the one that you're running the dev_appserver with. Macs are particularly notorious for this. Make sure you installed it in the same version of Python as the one the dev_appserver is running.

Please set PYTHONHOME if you have installed pycrypto in a user-defined directory. Also
/home/user# python -v
>>> from Crypto.Cipher import AES
will give you some idea what's the exact error.

Related

ModuleNotFoundError: no module named 'transformers'

this is my first post and I am very new to coding so please let me know if you need more information. I have been running some AI to generate artwork and it has been working but when I reloaded it the script won't work and it is now saying "No module named 'transformers'". Can anyone help me out? It was when I upgraded to google colab pro that I started to encounter issues although I am not sure why that would make a difference
ModuleNotFoundError
Probably it is because you have not installed in your (new, since you've upgraded to colabs pro) session the library transformers. Try to run as first cell the following: !pip install transformers (the "!" at the beginning of the instruction is needed to go into "terminal mode" ). This will download the transformers package into the session's environment.
assuming you are referring to the module here: https://pypi.org/project/transformers/
you need to install transformers with pip
after you install transformers, make sure to import it , and import the Module youre gonna use

`cannot find package "appengine" error` when using VS code

By following this tutorial I created a go lang project and opened it by Visual Studio Code.
The code itself works fine I can run the server, but somehow VS Code shows
cannot find package "appengine" in any of:
/usr/local/Cellar/go/1.8.3/libexec/src/appengine (from $GOROOT)
/Users/ironsand/go/src/appengine (from $GOPATH)
I thought I must set GOROOT for the Google App Engine, but according to this stackoverflow question I shouldn't.
How to make VS Code recognize google app engine library properly?
More info
The appengine package exists in ~/dev/google-cloud-sdk/platform/google_appengine/goroot-1.8/‌​src/appengine
I'm using macOS Sierra 10.12.6.
I did use that tutorial and it's working on my Mac via terminal and via VS Code.
You may follow this tutorial to be able use VS code to deploy GAE app with python:
Deploy GAE app with VS code
• Dont forget to update path of dev_appserver.py in tasks.json.
If that didn't work out, you would need to re-install/init google-cloud-sdk.
Note that it's necessary to provide root privileges during installing/initializing in order to allow installer script to add paths properly.
Last thing: avoid tilde expansion ~ in path. Use absolute path in config.( in general absolute path must be used always unless there is a reason to use relative address with tilde )
Good luck,'.

Running GAE GCS on PyCharm under OS X, runtime error "No module named cloudstorage"

I am trying to add Google Cloud Storage functionality to a Python GAE app that is already running with significant functionality. I work entirely within PyCharm on my development computer, which is a Mac running OS X 10.9.5.
I have created a new Python module that contains this statement:
import cloudstorage as gcs
as shown in the sample code at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/getstarted
When I first added that line, PyCharm said "No module named cloudstorage" in the editor.
I then followed both the "pip" and the "svn" instructions at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/download
to download the GCS Client Library.
In trying to follow those instructions, taking into account my prior experience with this programming environment, I actually tried using "pip" three times:
Once without the "-t" option, since I've never needed that option with "pip" before
Once using the "-t" option to specify my application directory's "lib" subdirectory
Once using:
pip install GoogleAppEngineCloudStorageClient -t /Applications/GoogleAppEngineLauncher.app//Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib, since I wasn't sure what the instructions meant by "<your_app_directory/lib>"
As mentioned, I also executed the "svn" command. Then, as mentioned in install python google cloud storage client on Ubuntu 14.04, I ran "cd gcs-client/src" and "sudo python setup.py install". I ran these commands in my user root directory.
After each of those successful but different installations of the GCS Client Library, I looked at the PyCharm editor window for my module, and it always had the same "No module named cloudstorage" error. But as an experiment, I would also try restarting PyCharm, and also try running my app.
At some point, the editor window stopped showing the error. It was not immediately after one of those steps above, but after I would go away to read various webpages and then come back to look at the error again. I don't know which of the installations was the one that got rid of the error message in the PyCharm editor.
In any case, whenever I try to run the app (again, inside PyCharm), I always get the runtime error "ImportError: No module named cloudstorage" on the same import statement.
The Run/Debug Configuration page for this app has both "Add content roots to PYTHONPATH" and "Add source roots to PYTHONPATH" checked.
Of course the main help I want is how to get past the "No module named cloudstorage" runtime error, even though the import statement no longer shows an error.
I think I also have as many as three spurious versions of the GCS Client Library. I'm much more concerned with getting past "Module not found", since it's a show-stopper, but if you have any idea how I can delete the spurious versions so that they're not just lying around, I'd be most grateful for that help as well.
If the "cloudstorage" directory is at <app>/lib/cloudstorage, then the import statement has to specify "lib":
import lib.cloudstorage
In my case, it's:
import lib.cloudstorage as gcs
By the way, the <app>/lib/GoogleAppEngineCloudStorageClient-1.9.5.0-py2.7.egg-info directory does not seem to be needed and can be deleted.
Actually, you also need to
touch __init__.py
in the lib directory. This will make the cloudstorage module visible to the "import lib.cloudstorage" command.
Dear Google: The distributions should include this file (or the procedure should account for it), and the demo script should be changed to reflect the expected usage. But more importantly why are you distributing/PROLIFERATING library code like this??!!! Why is this not distributed via gcloud? How am I ever going to pick up a patch for this library?
The accepted answer's solution
import lib.module_name
definitely can solve the problem. But I don't like add lib in front of every single module and happened to see how Google suggest import third party libs like this.
appengine will automatically run a file called appengine_config.py. So you can create such a file and put
from google.appengine.ext import vendor
vendor.add('lib')
inside that file. This will help you tell appengine to find dependencies in that folder, so you can simply write
import cloudstorage as gcs
I solve the missing module issue by adding the following to my main application file (main.py):
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
I think this is the way Guido intended. Now my code simply says import cloudstorage as gcs. None of the lib.cloudstorage or lib/__init__.py business.
From
https://stackoverflow.com/a/37645984/1740008

New App Engine SDK unable to utilize / find locally installed Python Imaging Library

Yesterday I updated my google cloud SDK along with the python runtime. Now an app I was able to run locally in the SDK complains about the PIL / Python Imaging Library not being available:
bash-3.2$ dev_appserver.py . --host=0.0.0.0
INFO 2014-05-31 17:07:52,313 devappserver2.py:706] Skipping SDK update check.
WARNING 2014-05-31 17:07:52,319 api_server.py:378] Could not initialize images API; you are likely missing the Python "PIL" module.
Not true, however. I DO have PIL installed and it works swimmingly with jpegs, which is what I expect:
bash-3.2$ ipython
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
In [1]: from PIL import Image
In [2]: my_image = Image.open('motorcycle.jpg')
In [3]: my_image.show()
Works just fine. FWIW, I declare my app.yaml use of PIL as such:
libraries:
...
- name: webapp2
version: latest
- name: PIL
version: latest
I've tested it, so it's not a false negative. When I try to use the GAE images module, it's blows up with the same problem. It works just fine in production. Clearly Python has what it needs to work. Why is App Engine unable to make use of it?
The problem I was having had to do with having a clash between a brew version of python installed versus the system version. Fixing my shell's path to point to the correct python installation sorted this problem, too. For GAE users: I also had to make sure my app engine SDK path was correct as well.
If you're having problems installing or getting PIL to work, understand that there are many dependencies involved with PIL, including what file format codecs you will want to support (there is a PNG library, a TIFF library and a JPEG library), and whether you want to draw text in your images and need truetype font support via the freetype library. Know that you may have PIL installed and no codec support libraries and effectively PIL won't be usable.
A good starting place for this issue might be this other question:
How to deal with Linux/Python dependencies?

How to import java.nio.file package

Im trying to listen to a directory for changes, then discovered java.nio.* was developed to handle efficiently such tasks and more. Then downloaded jdk1.7.0_02 from oracle and started eclipse with it. Then created new java project, tryed to implement some class from java.nio.file and Oh my eyes! "The import java.nio.file cannot be resolved".
Do i have to find some .jar in the whole jdk1.7.0_02 directory that contains such package? or is something wrong with my classpath?
Thank you in advance!!
You've different version of JDKs. You just need to set JDK7/JRE7 version eclipse project. You may also select the Execution environment JRE to JavaSE 7 while creating a new project.
The JDK your projects use to compile, the version of the resulting class files, the JRE they used to execute and the JDK eclipse runs with are widely independent settings.
The New I/0 is named as the NIO in javaSE 7.0 ("Dolphin").
The below link described as in details.
wiki - NIO

Resources