Deploying Django App Using Google Cloud Run - gcloud builds submit error - django

I've followed the tutorial for deploying Django on Cloud Run (https://codelabs.developers.google.com/codelabs/cloud-run-django), and I followed the exact instructions up to "Build your application image" on Step 7: "Configure, build and run migration steps".
When running the command:
gcloud builds submit --pack image=gcr.io/${PROJECT_ID}/myimage
[builder] × python setup.py egg_info did not run successfully.
[builder] │ exit code: 1
[builder] ╰─> [25 lines of output]
[builder] /layers/google.python.runtime/python/lib/python3.11/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
[builder] warnings.warn(msg, warning_class)
[builder] running egg_info
[builder] creating /tmp/pip-pip-egg-info-xoozdk2u/psycopg2_binary.egg-info
[builder] writing /tmp/pip-pip-egg-info-xoozdk2u/psycopg2_binary.egg-info/PKG-INFO
[builder] writing dependency_links to /tmp/pip-pip-egg-info-xoozdk2u/psycopg2_binary.egg-info/dependency_links.txt
[builder] writing top-level names to /tmp/pip-pip-egg-info-xoozdk2u/psycopg2_binary.egg-info/top_level.txt
[builder] writing manifest file '/tmp/pip-pip-egg-info-xoozdk2u/psycopg2_binary.egg-info/SOURCES.txt'
[builder]
[builder] Error: pg_config executable not found.
[builder]
[builder] pg_config is required to build psycopg2 from source. Please add the directory
[builder] containing pg_config to the $PATH or specify the full executable path with the
[builder] option:
[builder]
[builder] python setup.py build_ext --pg-config /path/to/pg_config build ...
[builder]
[builder] or with the pg_config option in 'setup.cfg'.
[builder]
[builder] If you prefer to avoid building psycopg2 from source, please install the PyPI
[builder] 'psycopg2-binary' package instead.
[builder]
[builder] For further information please check the 'doc/src/install.rst' file (also at
[builder] <https://www.psycopg.org/docs/install.html>).
[builder]
[builder] [end of output]
[builder]
[builder] note: This error originates from a subprocess, and is likely not a problem with pip.
[builder] error: metadata-generation-failed
[builder]
[builder] × Encountered error while generating package metadata.
[builder] ╰─> See above for output.
[builder]
[builder] note: This is an issue with the package mentioned above, not pip.
[builder] hint: See above for details.
[builder] --------------------------------------------------------------------------------
[builder] Sorry your project couldn't be built.
[builder] Our documentation explains ways to configure Buildpacks to better recognise your project:
[builder] -> https://github.com/GoogleCloudPlatform/buildpacks/blob/main/README.md
[builder] If you think you've found an issue, please report it:
[builder] -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
[builder] --------------------------------------------------------------------------------
[builder] ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle. This may be the result of using an untrusted builder: failed with status code: 51
ERROR
ERROR: build step 0 "gcr.io/k8s-skaffold/pack" failed: step exited with non-zero status: 1
---------------------------------------------------------------------------------------------------------------------------------------------------------------
BUILD FAILURE: Build step failure: build step 0 "gcr.io/k8s-skaffold/pack" failed: step exited with non-zero status: 1
ERROR: (gcloud.builds.submit) build e6025313-e189-4df7-95e9-6389fbc62b7a completed with status "FAILURE"
This is preventing me from continuing to the next step, and I'm not sure how to troubleshoot this issue.
I've tried pip installing psycopg2-binary as the error suggests, however it made not difference and because it's Google Cloud I wouldn't want to mess around with too many unorthodox installs, perhaps there's something I'm missing here? I've searched everywhere, and I haven't run into this exact issue.

Related

psycopg2-binary installation into a virtual environment fails when trying to compile source code

I am trying to install psycopg2-binary into my Django project. I am using a virtual environment and the command I'm running is
pip install psycopg2-binary
However, I'm getting a massive error message, the gist of it is this:
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory
containing pg_config to the $PATH or specify the full executable path with the
option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
If you prefer to avoid building psycopg2 from source, please install the PyPI
'psycopg2-binary' package instead.
But, hey, I'm installing exactly 'psycopg2-binary'
Why am I getting all this mess?
Pip cannot find you processor+OS at https://pypi.org/project/psycopg2-binary/2.9.2/#files so it tried to install from sources (the last file at the page) and failed.
Compiling from sources is currently the only way. If you can donate some spare processor cycles to the Psycopg2 authors they perhaps could start compiling and publishing wheels for OSX on M1.

AWS lambda - sam build returns error when building dependencies for torch library

Following this tutorial, I am trying to employ a pytorch model. I set the Dockerfile up as intended and when I run sam build, everything works except for the requirements. It returns the following error message:
Collecting torch==1.8.1
Downloading torch-1.8.1-cp38-cp38-manylinux1_x86_64.whl (804.1 MB)
Build Failed
Error: HelloWorldFunction failed to build: The command '/bin/sh -c python3.8 -m pip install -r requirements.txt -t .' returned a non-zero code: 137
Unfortunately, there is no information on what causes the error. Is this related to the size of the torch package? If so, is there any workaround?
I took a look at a template provided by AWS, where they employ a PyTorch model. There, they solve the issue by the following approach in the requirements.txt file:
-f https://download.pytorch.org/whl/torch_stable.html
torch==1.8.0+cpu
I am not sure, if this version is that much more leight-weighted, but it works.

dlib is not installing in pythonanywhere virtualenv

I am trying to recognize faces in an image using "face_recognition" library,to use it we have to install dlib but when installing dlib in pythonanywhere virtualenv console it is throwing some errors
below is the error I got during installation of dlib
(env) 16:09 ~/dlib (master)$ python setup.py install --yes
USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
running install
running bdist_egg
running egg_info
creating dlib.egg-info
writing dlib.egg-info/PKG-INFO
writing top-level names to dlib.egg-info/top_level.txt
writing dependency_links to dlib.egg-info/dependency_links.txt
writing manifest file 'dlib.egg-info/SOURCES.txt'
package init file 'dlib/__init__.py' not found (or not a regular file)
reading manifest file 'dlib.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'dlib.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
error: [Errno 38] Function not implemented
It looks like there's some strange problem with the current version of dlib that's stopping it from installing on PythonAnywhere. Version 19.3.1 seems to work:
pip2.7 install --user dlib==19.3.1
pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f
Try installing from this cmd command, assuming that you have already added pip in path

python_setup.py and egg.info error while installing Django-toolbelt

I tried to install Django-toolbelt, but I keep getting the below. I am using Mac. I've tried googling around for solutions but no luck. Thanks.
(venv)Chans-MacBook-Pro:Django_app2 chantrinh$ pip install django-toolbelt
/Users/chantrinh/Django_app2/venv/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:79: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Collecting django-toolbelt
Using cached django-toolbelt-0.0.1.tar.gz
Collecting django (from django-toolbelt)
Using cached Django-1.8.1-py2.py3-none-any.whl
Collecting psycopg2 (from django-toolbelt)
Using cached psycopg2-2.6.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/4r/bh8wxz5d2678zg90jn1715s80000gn/T/pip-build-eUKfh5/psycopg2
(venv)Chans-MacBook-Pro:Django_app2 chantrinh$ pg_config
-bash: pg_config: command not found
(venv)Chans-MacBook-Pro:Django_app2 chantrinh$ sudo find / -name pg_config
find: /dev/fd/3: Not a directory
find: /dev/fd/4: Not a directory
I had exactly the same error message. However, in my case, I had already installed psycopg2. What was happening was the following:
I had first to install Macports,
Then in the python documentation I got this line:
sudo port install py27-psycopg2
But that line installed the package in
'/opt/local/Library/Frameworks/Python.Framework/....'
instead of
'/Library/Frameworks/Python.Framework/....'
I just created a symbolic link to solve the problem.

Neither Pillow nor PIL could be imported: No module named Image

I am trying to use PIL/Pillow in my django app, running in virtualenv, for eventual deployment to Heroku.
Steps I have done:
started virtualenv (source venv/bin/activate)
pip install pillow
Output:
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard- error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1
otherwise, there were a lot of copied files:
e.g. copying PIL/__init__.py -> build/lib.macosx-10.9-intel-2.7/PIL
However, running python manage.py runserver fails with the error message in the title. Tried pip install pil and does not work. Any inkling on how to fix?
UPDATE: oh found the answer
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future pip install pillow
the unused arguments was preventing further install of pillow. the above tells it to not treat the unused argument as an error.
Found at (To Read more): Can't install mysql gem on OS X
I had the same issue with virtualenv and Django, following command fixed that:
easy_install PIL