ImportError: No module named googleads - django

I have a django project using python 2.7 and want to deploy it on Google App Engine(GAE).
I followed all this link for the tutorial:
https://cloud.google.com/python/django/appengine
When I finished deploying, and go to my project URL, I got an error and when I look on the Error Reporting in Google Cloud Platform
It says "ImportError: No module named googleads", but I already installed it on my local before I uploaded it.
pip freeze:
asn1crypto==0.24.0
astroid==1.6.1
autopep8==1.3.4
backports.functools-lru-cache==1.5
cffi==1.11.5
colorama==0.3.9
configparser==3.5.0
cryptography==2.1.4
Django==1.11.11
enum34==1.1.6
futures==3.2.0
googleads==10.1.0
httplib2==0.10.3
idna==2.6
ipaddress==1.0.19
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
MySQL-python==1.2.5
mysqlclient==1.3.4
oauth2client==4.1.2
pyasn1==0.4.2
pyasn1-modules==0.2.1
pycodestyle==2.3.1
pycparser==2.18
pylint==1.8.2
PyMySQL==0.8.0
pyOpenSSL==17.5.0
PySocks==1.6.8
pytz==2018.3
PyYAML==3.12
rsa==3.4.2
singledispatch==3.4.0.3
six==1.11.0
suds-jurko==0.6
virtualenv==15.1.0
win-inet-pton==1.0.1
wrapt==1.10.11
xmltodict==0.11.0
Please help!
Thanks!

Note the -t lib difference between the 2 pip invocations in step 2 of the Run the app on your local computer section:
pip install -r requirements-vendor.txt -t lib/
pip install -r requirements.txt
The first one installs the runtime dependencies for your app - inside your app (see Copying a third-party library).
The 2nd one installs dependencies needed for the local development server - in your venv (or local system).
Having app dependencies installed in your venv or local system (which is what your pip freeze shows) doesn't help - that's not where the sandbox is looking at for your app's dependencies.
So check that the googleads package is in your equivalent of the requirements-vendor.txt file and that those packages are installed in your app's lib directory.

Related

App Engine: ImportError: No module named _gdal

How to enable python 2.7 library like GDAL in Google App Engine standard? Currently there are linux python-modules in lib-folder in app engine, but when trying to run the code through endpoints, app engine gives internal server error: ImportError: No module named _gdal. I'm using pygdal version 2.2.3.3. Should the libgdal (demanded for pygdal)be installed also on app engine, and if so, how to do it? I installed GDAL locally into lib folder (using ubuntu bash on windows10) following these instructions using this syntax: sudo pip install --target lib --requirement requirements.txt --ignore-installed as it says here. Please help!
From What compiler can I use to build GDAL/OGR?
GDAL/OGR is written in ANSI C and C++. It can be compiled with all modern C/C++ compilers.
Which means it's incompatible with the (1st generation/python 2.7) standard environment Pure Python sandbox requirement:
All code for the Python runtime environment must be pure Python, and
not include any C extensions or other code that must be compiled.
You may want to look at the flexible environment instead. Probably with a custom runtime, see Up-to-date pip with AppEngine Python flex env?
Google App Engine's standard environment for Python27 only supports a specific set of third-party libraries that use C-extensions, listed here. pygdal is not in the list.
You may want to look into the Python3 standard runtime, though it is in beta. It allows you to install arbitrary third-party libraries.
Modifying this links' answer I managed to get GDAL working in App Engine Flexible.
My dockerfile:
FROM gcr.io/google-appengine/python
RUN apt-get update && apt-get -y install libproj-dev libgdal-dev
RUN export CPLUS_INCLUDE_PATH=/usr/include/gdal
RUN export C_INCLUDE_PATH=/usr/include/gdal
RUN gdal-config --version
# Create a virtualenv for dependencies. This isolates these packages from
# system-level packages.
RUN virtualenv /env -p python2.7
# Setting these environment variables are the same as running
# source /env/bin/activate.
ENV VIRTUAL_ENV /env
ENV PATH /env/bin:$PATH
# Copy the application's requirements.txt and run pip to install all
# dependencies into the virtualenv.
ADD requirements.txt requirements.txt
RUN pip install -r requirements.txt
# Add the application source code.
ADD . /app
CMD gunicorn -t 120 -b :$PORT main:app
My app.yaml-file:
runtime: custom
env: flex
entrypoint: gunicorn -t 120 -b :$PORT main:app
endpoints_api_service:
name: xxxxx.com
rollout_strategy: managed
beta_settings:
cloud_sql_instances: project:europe-north1:dbinstance
runtime_config:
python_version: 2
requirements.text-file:
pygdal==1.11.3.3

No module named PIL in heroku though it is installed

I have been trying to deploy a Django application on Heroku.
Some background - I hadn't used virtual environment while building the application but while deploying it, I had to use it. I'm following this tutorial for deployment. https://medium.com/agatha-codes/9-straightforward-steps-for-deploying-your-django-app-with-heroku-82b952652fb4
Now I'm stuck in step-6. After creating a virtual environment I have freezed the dependencies into requirements.txt.
But when I open the deployed URL it says
ImportError at /
No module named PIL
though Pillow has been installed, it is there in requirements.txt and runs fine when hosted on a local server.
This is my requirements.txt.
certifi==2018.4.16
dj-database-url==0.5.0
Django==1.11.14
django-heroku==0.3.1
gunicorn==19.9.0
packaging==17.1
Pillow==5.2.0
pip-review==1.0
pipenv==2018.7.1
pkg-resources==0.0.0
psycopg2==2.7.5
pyparsing==2.2.0
pytz==2018.5
six==1.11.0
virtualenv==16.0.0
virtualenv-clone==0.3.0
whitenoise==3.3.1
Please help me with this.
Heroku? Access your application and manually run pip install -r requirements.txt, then turn the application off and back on again.
I had this problem before, this step solved my problem.
If you are doing this in your view
import PIL
do this
import Image
In my case I solved this issue by installing 'Pillow'... just try pip/pip3 install Pillow and add it to your requirements.txt file.

Can't find any modules in Django project

I've been following a Django tutorial and initially created virtualenv and a requirements file in it. Project was halfway and in working state. Today I activated virtualenv successfully and tried python manage.py runserver to get error
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
I realized it's not finding Django and just to be sure checked my requirements.txt file (which confirmed right Django version). Tried to reinstall it from the file using pip3 install -r requirements.txt (tried using just pip too) to get another error --
ModuleNotFoundError: No module named 'pip'
It seems the environment is unable to find any of the modules. I tried to reinstall pip also just to be sure, but then it couldn't find apt-get command.
OS: Mac OSX El Capitan 10.11.6
Python: 3.6.2
Django: 1.10.3 (in requirements file)
Try running python -m ensurepip (or python3 -m ensurepip) to see if pip is already installed:
In most cases, end users of Python shouldn’t need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip.

Failed building wheel for python-ldap (windows) *first stackoverflow ask*

I've installed flask, flask_login, and ldap in the virtualenv for my flask package (to authenticate ldap users with the usernames & passwords of the other users at my company).
When I run my flask app, I get "AttributeError: 'module' object has no attribute 'initialize'"
I'm tried "pip install python-ldap"
but I get a red error (sandwiched between other white text) that reads:
"Failed building wheel for python-ldap"
I have thoroughly examined these:
How to install python-ldap on a python 2.7 virtualenv on windows without compiling
Installing python-ldap in a virtualenv on Windows
https://www.python-ldap.org/docs.html
https://www.linuxjournal.com/article/6988?page=0,1
to no avail.
I've had this error for days now...
(also:
pip install openldap
gives:
Collecting openldap
Could not find a version that satisfies the requirement openldap (from versions: )
No matching distribution found for openldap
...(in and outside of my venv) if that information helps)
I had this error last week and after switching work computers, I recreated the virtualenv and installed all of the other packages and dependencies successfully.
my requirements.txt file contains these lines after a line of git stuff:
click==6.7
Flask==0.12.2
Flask-Login==0.4.0
itsdangerous==0.24
Jinja2==2.9.6
ldap==1.0.2
ldap3==2.2.4
MarkupSafe==1.0
pyasn1==0.2.3
Werkzeug==0.12.2
Has anyone successfully installed python-ldap into a flask virtualenv with windows? If so... how?!
Go to:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-ldap
download python_ldap-2.4.38-cp27-cp27m-win_amd64.whl in the same directory that your venv folder is listed under
(ex.)
/myrepo
/myapp
/myapp
/venv
/run.py
/python_ldap-2.4.38-cp27-cp27m-win_amd64.whl
install the .whl file while inside of your venv
venv\Scripts\activate
pip install python_ldap-2.4.38-cp27-cp27m-win_amd64.whl
Voila!
The error
ERROR: Failed building wheel for python-ldap
can occur for several reasons. You actually have to look at what happened above this line. In my case, I just had to install missing dependencies to build python-ldap. You can look them up here. For CentOS 8, I had to install:
sudo dnf install openldap-devel python3-devel gcc
to make
python3 -m pip install --user python-ldap -U
work.

How to install image processing just for a virtualenv project with pip for django

But I'm looking to install freetype, libjpeg, PIL build to add image processing to my django projects I've followed this installation http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard/ which installs it site wide but I can get it inside my virtualenv project.
Do I just cd into the working directory of the virtualenv (project) and install it there and will it just be available for that project or do I use pip? I couldn't find the packages in the pip repository. Can someone enlighten me please.
curl -O http://pypi.python.org/packages/source/d/distribute/distribute-0.6.21.tar.gz
tar -xzvf distribute-0.6.21.tar.gz
cd distribute-0.6.21
python distribute_setup.py
easy_install pip
pip install virtualenv
virtualenv --distribute --no-site-packages [myproject]
cd [myproject]
source bin/activate (this activates the sandbox that virtualenv created)
pip install django mysql-python
Go to the working directory of the virtualenv and then run
$ source bin/activate
This will set that virtual environment as your active one. So now that it's active, you can install what you want, either manually (by following those steps on the site you linked to) or with pip and it will automatically install it into your active virtualenv.
If you then, say, run python manage.py runserver while the same virtualenv is active, django will have access to your newly installed package. Once you want to unset that virtual environment as your active one, simply do deactivate.
I ran into something similar; what I did was install it into the default directory (e.g. Python27/Lib/site-packages) then cut and paste all the new files put there into the created environment's site-packages. Hacky, but works.
After that you can follow EEVIAC's instructions to actually get your server running.