Azure web app with python and pip wheel installations - python

I've been trying to install certain python packages to my Django Web App on Azure. I'm trying to install the packages using the requirements.txt and pips wheel files, as is instructed here https://blogs.msdn.microsoft.com/azureossds/2015/06/29/install-native-python-modules-on-azure-web-apps-api-apps/
The problem is that pip does not seem to locate the wheelhouse folder. The wheelhouse folder is located at the root of my app directory, where I'm also keeping the requirements.txt, manage.py, readme.md and the web.config files.
Here's what my requirements.txt file looks like:
--find-links wheelhouse
django<2
pyodbc==4.0.17
django-pyodbc-azure==1.11.0
Here're the files in wheelhouse folder:
~/myapp/wheelhouse/django_pyodbc_azure-1.11.0.0-py2.py3-none-any.whl
~/myapp/wheelhouse/Django-1.11.4-py2.py3-none-any.whl
~/myapp/wheelhouse/pyodbc-4.0.17-cp27-cp27m-win_amd64.whl
~/myapp/wheelhouse/pyodbc-4.0.17-cp27-cp27m-win32.whl
I've downloaded the pyodbc .whl files from here:http://www.lfd.uci.edu/~gohlke/pythonlibs/
The django_pyodbc_azure-1.11.0.0-py2.py3-none-any.whl file was created by using a windows laptop with the windows c++ compiler for python installed (https://www.microsoft.com/en-us/download/confirmation.aspx?id=44266)
When pushing the commits to the server I still
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (7/7), 730 bytes | 0 bytes/s, done.
Total 7 (delta 3), reused 0 (delta 0)
remote: Updating branch 'master'.
remote: ......................................................................
remote: Updating submodules.
remote: Preparing deployment for commit id '7feb3f4dde'.
remote: Generating deployment script.
remote: Running deployment command...
remote: Handling python deployment.
remote: Detected requirements.txt. You can skip Python specific steps with a .skipPythonDeployment file.
remote: Detecting Python runtime from site configuration
remote: Detected python-2.7
remote: Deleting incompatible virtual environment.
remote: .....................................................................................
remote: Creating python-2.7 virtual environment.
remote: ...
remote: New python executable in env\Scripts\python.exe
remote: ........................................
remote: Installing setuptools, pip...done.
remote: Pip install requirements.
remote: .
remote: Downloading/unpacking django<2 (from -r requirements.txt (line 2))
remote: .........................
remote: Downloading/unpacking pyodbc==4.0.17 (from -r requirements.txt (line 3))
remote: Running setup.py (path:D:\home\site\wwwroot\env\build\pyodbc\setup.py) egg_info for package pyodbc
remote:
remote: Downloading/unpacking django-pyodbc-azure==1.11.0 (from -r requirements.txt (line 4))
remote: Downloading/unpacking pytz (from django<2->-r requirements.txt (line 2))
remote: Installing collected packages: django, pyodbc, django-pyodbc-azure, pytz
remote: .............................................................................................................................
remote: Running setup.py install for pyodbc
remote: building 'pyodbc' extension
remote: error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27
remote: Complete output from command D:\home\site\wwwroot\env\Scripts\python.exe -c "import setuptools, tokenize;__file__='D:\\home\\site\\wwwroot\\env\\build\\pyodbc\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record d:\local\temp\pip-hgg_tz-record\install-record.txt --single-version-externally-managed --compile --install-headers D:\home\site\wwwroot\env\include\site\python2.7:
remote: running install
remote:
remote: running build
remote:
remote: running build_ext
remote:
remote: building 'pyodbc' extension
remote:
remote: error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27
remote:
remote: ----------------------------------------
remote: Cleaning up...
remote: ..................................................................................................................................
remote: Command D:\home\site\wwwroot\env\Scripts\python.exe -c "import setuptools, tokenize;__file__='D:\\home\\site\\wwwroot\\env\\build\\pyodbc\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record d:\local\temp\pip-hgg_tz-record\install-record.txt --single-version-externally-managed --compile --install-headers D:\home\site\wwwroot\env\include\site\python2.7 failed with error code 1 in D:\home\site\wwwroot\env\build\pyodbc
remote: Storing debug log for failure in D:\home\pip\pip.log
remote: An error has occurred during web site deployment.
remote:
remote: Error - Changes committed to remote repository but deployment to website failed.
I'm really confused as to what I'm doing wrong here. Any ideas? One guess would be that the wheelhouse folder should be move to a subdirectory? I tried to move it to the app env folder under scripts, but it didn't work either.
Thanks for your time.
EDIT
So I tried to run the scripts straight from my Kudu console and here's the error I'm getting:
D:\home\site\wwwroot\env\Scripts\pip run on 08/25/17 15:51:48
pyodbc-4.0.17-cp27-cp27m-win32.whl is not a supported wheel on this platform.
Exception information:
Traceback (most recent call last):
File "D:\home\site\wwwroot\env\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "D:\home\site\wwwroot\env\lib\site-packages\pip\commands\install.py", line 257, in run
InstallRequirement.from_line(name, None))
File "D:\home\site\wwwroot\env\lib\site-packages\pip\req.py", line 167, in from_line
raise UnsupportedWheel("%s is not a supported wheel on this platform." % wheel.filename)
UnsupportedWheel: pyodbc-4.0.17-cp27-cp27m-win32.whl is not a supported wheel on this platform.

The recommended approach is to update Python on your WebApp using an extension:
https://learn.microsoft.com/visualstudio/python/managing-python-on-azure-app-service
Since actually, the default version of Python on WebApp are terribly old (and unsecure). You will get a newer version of pip, able to deal with all wheel files (currently it's not as you saw...).
Note that the Python extension are compiled by Microsoft, they are official.

Related

Error Pushing To Heroku with 2captcha library - ModuleNotFoundError: No module named 'requests'

I'm getting this error - ModuleNotFoundError: No module named 'requests' when I run git push heroku master. It's saying I don't have the requests in my requirements.txt but it's clearly in there. I believe something weird is happening because of 2captcha-python. Any ideas on how I can resolve this error? Included my requirements.txt file and error log below.
Requirements.txt file:
requests==2.25.1
2captcha-python==1.1.0
beautifulsoup4==4.9.3
bs4==0.0.1
cachetools==4.2.2
certifi==2021.5.30
chardet==4.0.0
df2gspread==1.0.4
google-api-python-client==1.6.7
google-auth==1.31.0
google-auth-oauthlib==0.4.4
gspread==3.7.0
httplib2==0.19.1
idna==2.10
lxml==4.6.3
numpy==1.20.3
oauth2client==4.1.3
oauthlib==3.1.1
pandas==1.2.4
pyasn1==0.4.8
pyasn1-modules==0.2.8
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2021.1
requests-oauthlib==1.3.0
rsa==4.7.2
selenium==3.141.0
six==1.16.0
soupsieve==2.2.1
uritemplate==3.0.1
urllib3==1.26.5
Error log:
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote: 1. heroku/python
remote: 2. https://github.com/heroku/heroku-buildpack-google-chrome
remote: 3. https://github.com/heroku/heroku-buildpack-chromedriver
remote: -----> Python app detected
remote: -----> No Python version was specified. Using the buildpack default: python-3.9.5
remote: To use a different version, see: https://devcenter.heroku.com/articles/python-runtimes
remote: -----> Installing python-3.9.5
remote: -----> Installing pip 20.2.4, setuptools 47.1.1 and wheel 0.36.2
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: Collecting requests==2.25.1
remote: Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
remote: Collecting 2captcha-python==1.1.0
remote: Downloading 2captcha-python-1.1.0.tar.gz (8.8 kB)
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-y8s7an11
remote: cwd: /tmp/pip-install-qcbdr2fk/2captcha-python/
remote: Complete output (9 lines):
remote: Traceback (most recent call last):
remote: File "<string>", line 1, in <module>
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/setup.py", line 4, in <module>
remote: from twocaptcha import __version__
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/twocaptcha/__init__.py", line 1, in <module>
remote: from .api import ApiClient
remote: File "/tmp/pip-install-qcbdr2fk/2captcha-python/twocaptcha/api.py", line 3, in <module>
remote: import requests
remote: ModuleNotFoundError: No module named 'requests'
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to python-selenium-southcarolina.
remote:
To https://git.heroku.com/python-selenium-southcarolina.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/python-selenium-southcarolina.git'
pip first downloads all modules and later install them. So when pip downloads 2captcha then requests is already downloaded but not installed. And this makes problem.
You have to first install all modules except 2captcha and later install only 2captcha. OR first install only requests and later other modules.
EDIT:
I can't test it but in documentation you can see that it can use also setup.py to install modules. But I don't know if it will run both setup.py and requirements or only one of them.
On local computer in venv I installed both using setup.py
from setuptools import setup
setup(
install_requires=['requests', 'wheel'],
)
import subprocess
subprocess.run('python -m pip install 2captcha-python', shell=True)
and running python setup.py install (but Heroku should run it automatically)
Later I will test it on Heroku when I refresh my account.

deploying bot to heroku, can't push bot to heroku

I'm having issues deploying my bot i made using discord.py into discord using heroku. I've followed many guides and looked into mane other sources as well to why it is happening and nothing seems to be working. This is what i get....
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.10
remote: -----> Installing pip
remote: -----> Installing SQLite3
remote: -----> Installing requirements with pip
remote: Collecting git+https://github.com/tony1bally/education-helper (from -r /tmp/build_e8b937d57bb9efdeafd512bb63149ee1/requirements.txt (line 1))
remote: Cloning https://github.com/tony1bally/education-helper to /tmp/pip-req-build-7hfbm1vc
remote: Running command git clone -q https://github.com/tony1bally/education-helper /tmp/pip-req-build-7hfbm1vc
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-req-build-7hfbm1vc/setup.py'"'"'; __file__='"'"'/tmp/pip-req-build-7hfbm1vc/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-req-build-7hfbm1vc/pip-egg-info
remote: cwd: /tmp/pip-req-build-7hfbm1vc/
remote: Complete output (5 lines):
remote: Traceback (most recent call last):
remote: File "<string>", line 1, in <module>
remote: File "/app/.heroku/python/lib/python3.6/tokenize.py", line 452, in open
remote: buffer = _builtin_open(filename, 'rb')
remote: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-req-build-7hfbm1vc/setup.py'
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to education-helper.
remote:
To https://git.heroku.com/education-helper.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/education-helper.git'
Does anyone know why this is happening?
This is through the command prompt btw!
You've declared https://github.com/tony1bally/education-helper as a dependency in requirements.txt but the repository is empty and cannot be installed with pip as a Python module.
Remove it from requirements.txt, add, commit and push again.

Heroku build fail with error "PyObjC requires MacOS to build" - how to fix?

I'm trying to use the playsound module in a very simple Django app with the below code which plays an mp3 file:
from playsound import playsound
playsound(filename)
However, my push to Heroku fails at PyOBjC (which is apparently also needed). I've pip installed playsound and PyObjC (without PyObjC, my play fails for needing AppKit). With both modules installed, the application works great on my local server.
It all works great until the Heroku build. Snippet of the error below. Does anyone have any ideas for what I need to do to get this build to work?
...
remote: Collecting pyobjc-core==6.1
remote: Downloading pyobjc-core-6.1.tar.gz (791 kB)
remote: ERROR: Command errored out with exit status 1:
remote: command: /app/.heroku/python/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-l_hzqzmw/pyobjc-core/setup.py'"'"'; __file__='"'"'/tmp/pip-install-l_hzqzmw/pyobjc-core/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-l_hzqzmw/pyobjc-core/pip-egg-info
remote: cwd: /tmp/pip-install-l_hzqzmw/pyobjc-core/
remote: Complete output (4 lines):
remote: /app/.heroku/python/lib/python3.8/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
remote: warnings.warn(msg)
remote: running egg_info
remote: error: PyObjC requires macOS to build
remote: ----------------------------------------
remote: ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to db-devsite.
remote:
To https://git.heroku.com/db-devsite.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/db-devsite.git'
The playsound module only has a dependency on PyObjC when used on macOS, for Linux machines (such as Heroku) the library has a dependency on "PyGObject" and the GStreamer library.
Note that playsound plays the sound on the machine that's running the code, which is probably not what you want when you use Heroku (it will try to play the sound a machine at Heroku).

No package found error while pushing to heroku a flask app

I am trying to deploy a Flask app on Heroku which responds to JSON post requests after doing some data analysis on a big JSON dataset. I referred to this question: No package 'gobject-introspection-1.0' found while deploying to Heroku but it's still not working.
requirements.txt:
flask
pandas
gunicorn
flask_cors
gdown
Package gobject-introspection-1.0 was not found in the pkg-config search path.
remote: Perhaps you should add the directory containing `gobject-introspection-1.0.pc'
remote: to the PKG_CONFIG_PATH environment variable
remote: No package 'gobject-introspection-1.0' found
remote: Command '('pkg-config', '--print-errors', '--exists', 'gobject-introspection-1.0 >= 1.46.0')' returned non-zero exit status 1.
remote:
remote: Try installing it with: 'sudo apt install libgirepository1.0-dev'
remote:
remote: ----------------------------------------
remote: Command "/app/.heroku/python/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-3ejh6vw4/PyGObject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-lgaouqha-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-3ejh6vw4/PyGObject/
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to stormy-castle-60587.
You can try to reach your slug with heroku run bash --app appname and then try to install libgirepository1.0-dev. In case of failure, use heroku-community/apt, more info at heroku-buildpack-apt

No package 'gobject-introspection-1.0' found while deploying to Heroku

Attempted to deploy python web app to heroku but encountered the following errors:
remote: running build_ext
remote: Package gobject-introspection-1.0 was not found in the pkg-config search path.
remote: Perhaps you should add the directory containing `gobject-introspection-1.0.pc'
remote: to the PKG_CONFIG_PATH environment variable
remote: No package 'gobject-introspection-1.0' found
remote: Command '('pkg-config', '--print-errors', '--exists', 'gobject-introspection-1.0 >= 1.46.0')' returned non-zero exit status 1.
remote:
remote: Try installing it with: 'sudo apt install libgirepository1.0-dev'
remote:
remote: ----------------------------------------
remote: Command "/app/.heroku/python/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-l6sq2i_i/PyGObject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-k7lo0r2b-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-l6sq2i_i/PyGObject/
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to ggoh-trailer.
remote:
To https://git.heroku.com/ggoh-trailer.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/ggoh-trailer.git'
OS = Ubuntu 18.04(Bionic)
Python 3.7.1
In requirements.txt:
pycairo==1.18.0
PyGObject==3.30.2
I've installed libgirepository1.0-dev as below;
$ whereis gobject-introspection-1.0
gobject-introspection-1: /usr/include/gobject-introspection-1.0 /usr/share/gobject-introspection-1.
But I still see the same error above. Are there any other applications that I need to install on Ubuntu to fulfill the dependency?
After manually editing requirement.txt files with content below;
Flask
gunicorn
Heroku was able to accept my git push. I've learned to only use the required dependencies in requirement.txt. Thanks Chris for point me to the right direction.

Categories

Resources