New to Python - Django, Need To Read Log - python

I have been handed over an application which is built in Python - Django. I need to support it. There was no handover or anything like that. Pitty Me!
I am new to this language and framework. When I try to run the server with python manage.py runserver I get following errors:
Unhandled exception in thread started by .wrapper at 0x108f48e18>
Traceback (most recent call last):
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
autoreload.raise_last_exception()
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/init.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/contrib/admin/init.py", line 4, in
from django.contrib.admin.filters import (
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/contrib/admin/filters.py", line 10, in
from django.contrib.admin.options import IncorrectLookupParameters
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/contrib/admin/options.py", line 12, in
from django.contrib.admin import helpers, widgets
File "/Users/atariq/Sites/Python_Stuff/123/venv/lib/python3.7/site-packages/django/contrib/admin/widgets.py", line 152
'%s=%s' % (k, v) for k, v in params.items(),
^
I am unable to understand what it says. Can someone guide me over it?
I have installed all the required packages for the project with pip.
I am on Python 3.7 and using virtualenv.
UPDATE
I came to know that project works with Python 3.6, so I installed it and still getting same type of error log.
Pip Freeze gave me this:
asgiref==1.1.2
attrs==18.2.0
autobahn==18.11.2
Automat==0.7.0
certifi==2018.11.29
channels==1.1.6
chardet==3.0.4
constantly==15.1.0
coreapi==2.3.3
coreschema==0.0.4
daphne==1.3.0
defusedxml==0.5.0
dj-database-url==0.5.0
Django==1.11.12
django-allauth==0.32.0
django-cors-headers==2.4.0
django-debug-toolbar==1.9.1
django-filter==2.0.0
django-jsonview==1.2.0
django-prometheus==1.0.13
django-pyodbc-azure==1.11.12.1
django-watchman==0.15.0
djangorestframework==3.7.7
djangorestframework-camel-case==0.2.0
djangorestframework-jwt==1.11.0
djangorestframework-xml==1.3.0
docutils==0.13.1
drf-yasg==1.6.2
future==0.17.1
gevent==1.2.2
greenlet==0.4.15
hyperlink==18.0.0
idna==2.7
incremental==17.5.0
inflection==0.3.1
itypes==1.1.0
Jinja2==2.10
ldap3==2.3
MarkupSafe==1.1.0
oauthlib==2.1.0
openapi-codec==1.3.2
Pillow==5.3.0
prometheus-client==0.5.0
pyasn1==0.4.4
Pygments==2.3.0
PyHamcrest==1.9.0
PyJWT==1.7.1
pyodbc==4.0.23
python-dateutil==2.6.1
python3-openid==3.1.0
pytz==2018.7
raven==6.7.0
requests==2.20.1
requests-oauthlib==1.0.0
ruamel.yaml==0.15.81
six==1.11.0
sqlparse==0.2.4
Twisted==18.9.0
txaio==18.8.1
ua-parser==0.8.0
uritemplate==3.0.0
urllib3==1.24.1
user-agents==1.1.0
uWSGI==2.0.17
zope.interface==4.6.0
Manage.py
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ProjectName.settings.development")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise 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?"
)
raise
execute_from_command_line(sys.argv)
Regards

It seems to be incompatibility of Python 3.7 and your current version of Django. You can find more details in similar question
What I can suggest is to upgrade your Django 2 or use Python 3.6.
Here you can see that Python 3.7 is compatible with Django 1.11.17 version.

Can we see the code u a=have written in manage.py
Who ever tries python for the first tym they does a very basic mistake of inidnantion. Though it ll be inditnation error for sometime it will throw some other prioritized error. !CHECK FOR INDINANATION

Thanks guys for the help.
After a lot of headbang, I came to know that there were a lot of modules missing from req.txt file which were required to build the project. They were mentioned in some other file.
After installing all the required modules, and running the migrations, I was able to run the project.

Related

Azure DevOps AzureFunctionApp#1 not installing python dependencies

Using the Azure Devops task with current setup :
task: AzureFunctionApp#1
displayName: Deploy Lab
inputs:
azureSubscription: 'serviceConnection'
appType: 'functionAppLinux'
appName: 'myAwesomeApp'
package: '.'
runtimeStack: 'PYTHON|3.8'
Also, in the root directory (ie . in the ado task), I have a requirements.txt file that contains numpy
The deployment runs successfully but when I test the app, I have the following error:
Failure Exception: ModuleNotFoundError: No module named 'numpy'
Which simply means that the requirements.txt file is not considered or pip install -r requirements.txt didn't run successfully in the remote compute, what am I doing wrong ?
EDIT: Added a step to install the packages locally did work, but as numpy is a C built library it's dependent on the host machine and that doesn't work in the remote function app :lol:
The step that I added is this one:
- bash: pip install -r requirements.txt --target="./.python_packages/lib/site-packages"
displayName: 'Install dependencies'
And the error:
Result: Failure Exception: ImportError: IMPORTANT: PLEASE READ THIS
FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy
C-extensions failed. This error can happen for many reasons, often due
to issues with your setup or how NumPy was installed. We have compiled
some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html Please
note and check the following: * The Python version is: Python3.9 from
"/usr/local/bin/python" * The NumPy version is: "1.22.3" and make sure
that they are the versions you expect. Please carefully study the
documentation linked above for further help. Original error was: No
module named 'numpy.core._multiarray_umath' . Troubleshooting Guide:
https://aka.ms/functions-modulenotfound Stack: File
"/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/dispatcher.py",
line 305, in _handle__function_load_request func =
loader.load_function( File
"/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py",
line 42, in call raise extend_exception_message(e, message) File
"/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/utils/wrappers.py",
line 40, in call return func(*args, **kwargs) File
"/azure-functions-host/workers/python/3.9/LINUX/X64/azure_functions_worker/loader.py",
line 85, in load_function mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.9/importlib/init.py", line 127, in
import_module return _bootstrap._gcd_import(name[level:], package,
level) File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in
_find_and_load_unlocked File "", line 680, in _load_unlocked File "",
line 850, in exec_module File "", line
228, in _call_with_frames_removed File
"/home/site/wwwroot/bilans/main.py", line 24, in from .
import bilan File "/home/site/wwwroot/bilans/bilan.py", line 16, in
import numpy as np File
"/home/site/wwwroot/.python_packages/lib/site-packages/numpy/init.py",
line 144, in from . import core File
"/home/site/wwwroot/.python_packages/lib/site-packages/numpy/core/init.py",
line 49, in raise ImportError(msg)
Maybe you will have to use python 3.9 and the latest ubuntu agent in the pipeline
https://github.com/Azure/azure-functions-python-worker/issues/904

Trying to run Scrapy

I am trying to run Scrapy and encountering the following error.
It seems that Scrapy can't find TheTwisted 10.0.0 - I've downloaded it but don't know where to place the folder. Thanks!
Traceback (most recent call last):
File "/usr/local/bin/scrapy", line 5, in
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 3095, in
#_call_aside
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 3081, in _call_aside
f(*args, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 3108, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 658, in _build_master
ws.require(requires)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 959, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/init.py", line 846, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'Twisted>=10.0.0' distribution was not found and is required by Scrapy
If using Linux, install Twisted by running pip install Twisted in terminal.
If Windows, the Twisted docs recommend pip install Twisted[windows_platform].
In both cases if you're using a virtual environment (recommended) make sure to install it inside the venv.

Pyinstaller / Django - pkg_resources.DistributionNotFound: The 'django-omnibus' distribution was not found

I am trying to create an installer for a django website that uses the django-omnibus module.
My Pyinstaller command:
pyinstaller --name djangosite manage.py
The Pyinstaller command runs to completion.
Trying to run the web server using
djangosite.exe runserver localhost:8000
I get the following error:
Traceback (most recent call last):
File "<string>", line 10, in <module>
File "django\core\management\__init__.py", line 338, in execute_from_command_line
File "django\core\management\__init__.py", line 312, in execute
File "django\__init__.py", line 18, in setup
File "django\apps\registry.py", line 85, in populate
File "django\apps\config.py", line 86, in create
File "importlib\__init__.py", line 37, in import_module
File "c:\users\USERNAME\appdata\local\temp\pip-build-vxcefe\pyinstaller\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
File "omnibus\__init__.py", line 3, in <module>
File "pkg_resources\__init__.py", line 561, in get_distribution
File "pkg_resources\__init__.py", line 441, in get_provider
File "pkg_resources\__init__.py", line 962, in require
File "pkg_resources\__init__.py", line 849, in resolve
pkg_resources.DistributionNotFound: The 'django-omnibus' distribution was not found and is required by the application manage returned -1
If I remove all django-omnibus code, the site works fine (except for the my websocket functionality obviously). Any ideas? Thanks.
I needed to add a hook.py file for django-omnibus and add the --additional-hooks-dir=. flag to the pyinstaller command.
hook-omnibus.py
from PyInstaller.utils.hooks import copy_metadata, collect_data_files
datas = copy_metadata('django-omnibus')
datas += collect_data_files('omnibus')
Similar answer here:
https://github.com/pyinstaller/pyinstaller/issues/1713
I know this is a late reply, but I had a similar issue with django-user-accounts - pkg_resources.DistributionNotFound: The 'django-user-accounts' distribution was not found
I was directed here when searching for a fix. I solved the issue with the following addition to settings.py - hopefully helps someone else.
INSTALLED_APPS = [
...
'django.contrib.sites',
...
]

setuptools seems to find incorrect match

I'm new to python and hitting issues trying to use setuptools (which seems to be the recommended way to get dependencies for CI).
Following (amongst other guides) these:
http://flask.pocoo.org/docs/0.10/patterns/distribute/
https://pytest.org/latest/goodpractises.html#integration-with-setuptools-test-commands
my setup.py says:
install_requires=['Flask','Flask-SQLAlchemy'],
However when I run "setup.py test" Flask-SQLAlchemy is installed and fails:
(.venv)root#apb:/projectmanager# ./setup.py test
running test
Searching for Flask-SQLAlchemy
Reading https://pypi.python.org/simple/Flask-SQLAlchemy/
Best match: Flask-SQLAlchemy 2.0
Downloading https://pypi.python.org/packages/source/F/Flask-SQLAlchemy/Flask-SQLAlchemy-2.0.tar.gz#md5=06ae73194cca73b72e178f870d1dac7c
Processing Flask-SQLAlchemy-2.0.tar.gz
...
Installed /projectmanager/Flask_SQLAlchemy-2.0-py2.7.egg
Searching for Flask
Best match: Flask SQLAlchemy-2.0
Downloading https://pypi.python.org/packages/source/F/Flask-SQLAlchemy/Flask-SQLAlchemy-2.0.tar.gz#md5=06ae73194cca73b72e178f870d1dac7c
Processing Flask-SQLAlchemy-2.0.tar.gz
...
Installed /projectmanager/Flask_SQLAlchemy-2.0-py2.7.egg
Traceback (most recent call last):
File "./setup.py", line 135, in <module>
cmdclass = {'test': PyTest},
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/projectmanager/.venv/local/lib/python2.7/site-packages/setuptools/command/test.py", line 132, in run
self.distribution.install_requires)
File "/projectmanager/.venv/local/lib/python2.7/site-packages/setuptools/dist.py", line 287, in fetch_build_eggs
replace_conflicting=True,
File "/projectmanager/.venv/local/lib/python2.7/site-packages/pkg_resources.py", line 639, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Flask
I don't understand why it's:
a) processing the dependencies out of order
b) not finding Flask
As this is really an app rather than a library, using pip and requirements.txt is an option, however I like the standardisation setuptools brings.
Update: specifying 'Flask>=0.10.1' cures the problem - but why? There is no version of flask anywhere on the system.
Many thanks

NoneType error in pbr when running setup.py script

When running 'python setup.py develop' or 'python setup.py install' I receive the following traceback.
Traceback (most recent call last):
File "setup.py", line 38, in <module>
test_suite='nose.collector',
File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
dist.run_commands()
File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
self.run_command(cmd)
File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
cmd_obj.run()
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 27, in run
self.install_for_development()
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 129, in install_for_development
self.process_distribution(None, self.dist, not self.no_deps)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 682, in process_distribution
[requirement], self.local_index, self.easy_install
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pkg_resources.py", line 631, in resolve
dist = best[req.key] = env.best_match(req, ws, installer)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pkg_resources.py", line 871, in best_match
return self.obtain(req, installer)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pkg_resources.py", line 883, in obtain
return installer(requirement)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 595, in easy_install
return self.install_item(spec, dist.location, tmpdir, deps)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 627, in install_item
self.process_distribution(spec, dist, deps)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 659, in process_distribution
self.install_egg_scripts(dist)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/develop.py", line 152, in install_egg_scripts
return easy_install.install_egg_scripts(self,dist)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 532, in install_egg_scripts
self.install_wrapper_scripts(dist)
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/setuptools/command/easy_install.py", line 734, in install_wrapper_scripts
for args in get_script_args(dist):
File "/local/home/kassan1/venvs/some_env/local/lib/python2.7/site-packages/pbr/packaging.py", line 512, in override_get_script_args
header = easy_install.get_script_header("", executable, is_wininst)
AttributeError: 'NoneType' object has no attribute 'get_script_header'
Interestingly, if I rerun the same command as above, the installation is successful.
Just for kicks, I tried adding debugging statements to the pbr/packaging.py file both when easy_install was imported and used. It looked just fine when it was imported however, was None when accessed at line 512 as per the traceback.
Below is my requirements file that I am using:
pyyaml
requests
termcolor
mock
nose
cached_property
argparse
unittest2
tox
stevedore
kombu
and setup.py script:
import ez_setup
ez_setup.use_setuptools('3.6')
import os
from setuptools import setup, find_packages
try:
# workaround for http://bugs.python.org/issue15881
import multiprocessing # noqa
except ImportError:
pass
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
def requirements():
return read('requirements.txt').splitlines()
setup(
name='MY_PROJECT',
version='0.0.1',
author="Noorez Kassam",
long_description=read('README.rst'),
install_requires=requirements(),
entry_points={
'console_scripts': [
'myproj = myproj.myproj:main',
],
'myproj.urloperations.download': [
'file = myproj.filedownload:download'
],
},
packages=find_packages(),
test_suite='nose.collector',
)
Quick searches on Google indicate that others have encountered variations of what I am seeing however, I couldn't locate a solution to the problem.
I had a very similar problem and found a workaround.
I also got AttributeError: 'NoneType' object has no attribute 'get_script_header'
Workaround that fixed it for me: In the list install_requires I had "tornado" before "luigi". By switching the order to "luigi" and then "tornado" this bug went away. I see that you do not use tornado or luigi, but I guess the ordering is still the cause of this problem since you can fix the problem by running your install command twice.
Additional note: Before finding this workaround I tried to upgrade to newest setuptools (v 5.8). It did not solve the bug.
I had the same problem and it was fixed by updating setuptools version, i.e.:
pip install --upgrade setuptools

Categories

Resources