why my pip gives same error when i run Django server? - python

I updated the version of my pip but when I run every time any command with pip on terminal, it gives me the same error. Before I tried to create a django project and after some time when I run project it gives error. I don't know where I am going wrong.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/bin/pip", line 8, in <module>
sys.exit(main())
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 73, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/__init__.py", line 104, in create_command
module = importlib.import_module(module_path)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 17, in <module>
from pip._internal.cli.req_command import RequirementCommand, with_cleanup
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 22, in <module>
from pip._internal.req.constructors import (
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/req/__init__.py", line 10, in <module>
from .req_install import InstallRequirement
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pip/_internal/req/req_install.py", line 10, in <module>
import uuid
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/uuid.py", line 57, in <module>
_AIX = platform.system() == 'AIX'
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/platform.py", line 891, in system
return uname().system
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/platform.py", line 857, in uname
processor = _syscmd_uname('-p', '')
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/platform.py", line 613, in _syscmd_uname
output = subprocess.check_output(('uname', option),
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/subprocess.py", line 411, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/run/__init__.py", line 145, in __new__
process = cls.create_process(command, stdin, cwd=cwd, env=env, shell=shell)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/run/__init__.py", line 121, in create_process
shlex.split(command),
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 311, in split
return list(lex)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 300, in __next__
token = self.get_token()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 109, in get_token
raw = self.read_token()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/shlex.py", line 140, in read_token
nextchar = self.instream.read(1)
AttributeError: 'tuple' object has no attribute 'read'
Every time it is the same error with pip. Please help me with this problem.

Related

I have a problem importing openai in Django for web application purposes

My python version is able to run open ai on its own, but when I tried to integrate it with Django I ran into the following issue:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1031, in _bootstrap_inner
self.run()
^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 968, in run
self._target(*self._args, **self._kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 134, in inner_run
self.check(display_num_errors=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/management/base.py", line 475, in check
all_issues = checks.run_checks(
^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/checks/registry.py", line 88, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/core/checks/urls.py", line 24, in check_resolver
return check_method()
^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/resolvers.py", line 494, in check
for pattern in self.url_patterns:
^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/resolvers.py", line 715, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__
res = instance.__dict__[self.name] = self.func(instance)
^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/resolvers.py", line 708, in urlconf_module
return import_module(self.urlconf_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 902, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/matthewsetiawan/Desktop/Final Year Project/OpenCare/Main Project/OpenCare/loanhub/urls.py", line 21, in <module>
path('',include('authentication.urls')),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/django/urls/conf.py", line 38, in include
urlconf_module = import_module(urlconf_module)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 902, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Users/matthewsetiawan/Desktop/Final Year Project/OpenCare/Main Project/OpenCare/authentication/urls.py", line 3, in <module>
from . import views
^^^^^^^^^^^^^^^^^^^
File "/Users/matthewsetiawan/Desktop/Final Year Project/OpenCare/Main Project/OpenCare/authentication/views.py", line 13, in <module>
import openai
^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/__init__.py", line 9, in <module>
from openai.api_resources import (
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/__init__.py", line 1, in <module>
from openai.api_resources.completion import Completion # noqa: F401
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/completion.py", line 4, in <module>
from openai.api_resources.abstract import DeletableAPIResource, ListableAPIResource
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/__init__.py", line 3, in <module>
from openai.api_resources.abstract.api_resource import APIResource
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_resources/abstract/api_resource.py", line 4, in <module>
from openai import api_requestor, error, util
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/openai/api_requestor.py", line 21, in <module>
import aiohttp
^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/__init__.py", line 6, in <module>
from .client import (
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/aiohttp/client.py", line 34, in <module>
from yarl import URL
^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yarl/__init__.py", line 1, in <module>
from ._url import URL, cache_clear, cache_configure, cache_info
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yarl/_url.py", line 11, in <module>
from ._quoting import _Quoter, _Unquoter
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/yarl/_quoting.py", line 14, in <module>
from ._quoting_c import _Quoter, _Unquoter # type: ignore[misc]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "yarl/_quoting_c.pyx", line 1, in init yarl._quoting_c
ValueError: builtins.type size changed, may indicate binary incompatibility. Expected 904 from C header, got 896 from PyObject
I have not been able to find my issue anywhere else on the web as this module is relatively new, however could anyone give some insights on this issue. Perhaps it has something to do with setting.py file?

How to fix: "HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory 10:49:33 Traceback"?

I have a project in which I use a rq worker in conjuction with tensorflow to predict the genre of songs recorded on a microphone (Raspberry pi4).
The problem is: when i use the function to predict the genre i get an error on the rq worker that says:
2021-09-13 10:49:30.246680: E tensorflow/core/platform/hadoop/hadoop_file_system.cc:132] HadoopFileSystem load error: libhdfs.so: cannot open shared object file: No such file or directory
10:49:33 Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/rq/worker.py", line 1031, in perform_job
rv = job.perform()
File "/home/pi/.local/lib/python3.7/site-packages/rq/job.py", line 749, in perform
self._result = self._execute()
File "/home/pi/.local/lib/python3.7/site-packages/rq/job.py", line 772, in _execute
result = self.func(*self.args, **self.kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/rq/job.py", line 225, in func
return import_attribute(self.func_name)
File "/home/pi/.local/lib/python3.7/site-packages/rq/utils.py", line 142, in import_attribute
module = importlib.import_module(module_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./recognition.py", line 1, in <module>
from tensorflow.keras import layers
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py", line 98, in <module>
from tensorflow_core import *
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "<frozen importlib._bootstrap>", line 1019, in _handle_fromlist
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
module = self._load()
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/__init__.py", line 88, in <module>
from tensorflow.python import keras
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/__init__.py", line 26, in <module>
from tensorflow.python.keras import activations
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/__init__.py", line 26, in <module>
from tensorflow.python.keras import activations
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/activations.py", line 23, in <module>
from tensorflow.python.keras.utils.generic_utils import deserialize_keras_object
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/__init__.py", line 34, in <module>
from tensorflow.python.keras.utils.io_utils import HDF5Matrix
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/io_utils.py", line 30, in <module>
import h5py
File "/home/pi/.local/lib/python3.7/site-packages/h5py/__init__.py", line 25, in <module>
from . import _errors
File "h5py/_errors.pyx", line 1, in init h5py._errors
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/rq/worker.py", line 1031, in perform_job
rv = job.perform()
File "/home/pi/.local/lib/python3.7/site-packages/rq/job.py", line 749, in perform
self._result = self._execute()
File "/home/pi/.local/lib/python3.7/site-packages/rq/job.py", line 772, in _execute
result = self.func(*self.args, **self.kwargs)
File "/home/pi/.local/lib/python3.7/site-packages/rq/job.py", line 225, in func
return import_attribute(self.func_name)
File "/home/pi/.local/lib/python3.7/site-packages/rq/utils.py", line 142, in import_attribute
module = importlib.import_module(module_name)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./recognition.py", line 1, in <module>
from tensorflow.keras import layers
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py", line 98, in <module>
from tensorflow_core import *
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/__init__.py", line 28, in <module>
from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "<frozen importlib._bootstrap>", line 1019, in _handle_fromlist
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py", line 50, in __getattr__
module = self._load()
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow/__init__.py", line 44, in _load
module = _importlib.import_module(self.__name__)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/__init__.py", line 88, in <module>
from tensorflow.python import keras
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/__init__.py", line 26, in <module>
from tensorflow.python.keras import activations
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/__init__.py", line 26, in <module>
from tensorflow.python.keras import activations
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/activations.py", line 23, in <module>
from tensorflow.python.keras.utils.generic_utils import deserialize_keras_object
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/__init__.py", line 34, in <module>
from tensorflow.python.keras.utils.io_utils import HDF5Matrix
File "/home/pi/.local/lib/python3.7/site-packages/tensorflow_core/python/keras/utils/io_utils.py", line 30, in <module>
import h5py
File "/home/pi/.local/lib/python3.7/site-packages/h5py/__init__.py", line 25, in <module>
from . import _errors
File "h5py/_errors.pyx", line 1, in init h5py._errors
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 44 from C header, got 40 from PyObject
I know it's a lot of text but i have no clue on how to fix the error.
Also I want to specify that the rq worker works fine with other functions that does not require the Tensorflow library.

Unable to use mixins from drf-extensions

I have installed drf-extensions and imported it to my views. After that, I started getting below exception and I was not able to identify the root cause of this. Can someone explain me, what went wrong here pls?
> python .\manage.py runserver
Watching for file changes with StatReloader
Performing system checks...
Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 177, in import_from_string
return import_string(val)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\utils.py", line 6, in <module>
from rest_framework_extensions.key_constructor.constructors import (
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\key_constructor\constructors.py", line 4, in <module>
from rest_framework_extensions.key_constructor import bits
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\key_constructor\bits.py", line 3, in <module>
from django.db.models.sql.datastructures import EmptyResultSet
ImportError: cannot import name 'EmptyResultSet' from 'django.db.models.sql.datastructures'
(C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\db\models\sql\datastructures.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\autoreload.py", line 53, in wrapper
fn(*args, **kwargs)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\management\commands\runserver.py", line 118, in inner_run
self.check(display_num_errors=True)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\management\base.py", line 392, in check
all_issues = checks.run_checks(
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\checks\registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
return check_method()
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\urls\resolvers.py", line 408, in check
for pattern in self.url_patterns:
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\urls\resolvers.py", line 589, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\utils\functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\urls\resolvers.py", line 582, in urlconf_module
return import_module(self.urlconf_name)
File "C:\Users\gknath\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\gknath\Desktop\python-django\testing_new_backend_model_modp\projects\urls.py", line 5, in <module>
from .api import router
File "C:\Users\gknath\Desktop\python-django\testing_new_backend_model_modp\projects\api.py", line 2, in <module>
from api.views import FactorViewSet, ProjectViewSet, FactorViewSet
File "C:\Users\gknath\Desktop\python-django\testing_new_backend_model_modp\api\views.py", line 3, in <module>
from rest_framework_extensions.mixins import NestedViewSetMixin
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\mixins.py", line 1, in <module>
from rest_framework_extensions.cache.mixins import CacheResponseMixin
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\cache\mixins.py", line 5, in <module>
class BaseCacheResponseMixin:
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework_extensions\cache\mixins.py", line 8, in BaseCacheResponseMixin
object_cache_key_func = extensions_api_settings.DEFAULT_OBJECT_CACHE_KEY_FUNC
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 225, in __getattr__
val = perform_import(val, attr)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 166, in perform_import
return import_from_string(val, setting_name)
File "C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\rest_framework\settings.py", line 180, in import_from_string
raise ImportError(msg)
ImportError: Could not import 'rest_framework_extensions.utils.default_object_cache_key_func' for API setting 'DEFAULT_OBJECT_CACHE_KEY_FUNC'. ImportError: cannot import name 'EmptyResultSet' from 'django.db.models.sql.datastructures' (C:\Users\gknath\Desktop\python-django\django-models-rest\venv\lib\site-packages\django\db\models\sql\datastructures.py).
If I disable the extension import then I can run fine. I am using three models and have written serializers and trying to make an nested API using drf_extensions.
I guess the problem is related to this issue: https://github.com/chibisov/drf-extensions/issues/294
Temporary fix for me was to uninstall and install with:
pip install -U git+git://github.com/chibisov/drf-extensions.git#8001a440c7322be26bbe2d16f3a334a8b0b5860b

RQ job times out

I am trying to accomplish a task by using rq and redis. However the job is sometimes getting stuck importing a module.
JobTimeoutException: Task exceeded maximum timeout value (100 seconds)
File "rq/worker.py", line 812, in perform_job
rv = job.perform()
File "rq/job.py", line 588, in perform
self._result = self._execute()
File "rq/job.py", line 594, in _execute
return self.func(*self.args, **self.kwargs)
File "rq/job.py", line 199, in func
return import_attribute(self.func_name)
File "rq/utils.py", line 155, in import_attribute
module = importlib.import_module(module_name)
File "__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "my_task.py", line 13, in <module>
import my_sockets
File "my_sockets.py", line 1, in <module>
from flask_socketio import SocketIO
File "__init__.py", line 8, in <module>
from socketio import socketio_manage
File "__init__.py", line 3, in <module>
from .client import Client
File "/usr/local/lib/python3.6/dist-packages/socketio/client.py", line 5, in <module>
import engineio
File "__init__.py", line 3, in <module>
from .client import Client
File "/usr/local/lib/python3.6/dist-packages/engineio/client.py", line 13, in <module>
import requests
File "__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "urllib3/contrib/pyopenssl.py", line 48, in <module>
from cryptography.hazmat.backends.openssl import backend as openssl_backend
File "cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
from cryptography.hazmat.backends.openssl.backend import backend
File "cryptography/hazmat/backends/openssl/backend.py", line 2419, in <module>
backend = Backend()
File "cryptography/hazmat/backends/openssl/backend.py", line 119, in __init__
self.activate_osrandom_engine()
File "cryptography/hazmat/backends/openssl/backend.py", line 163, in activate_osrandom_engine
with self._get_osurandom_engine() as e:
File "contextlib.py", line 81, in __enter__
return next(self.gen)
File "cryptography/hazmat/backends/openssl/backend.py", line 146, in _get_osurandom_engine
res = self._lib.ENGINE_init(e)
File "rq/timeouts.py", line 64, in handle_death_penalty
'({0} seconds)'.format(self._timeout))
It happens only 1 out of 10 times, which makes it hard to reproduce. Does anyone know what is causing this?

ModuleNotFoundError: No module named 'social.models' when running celery worker

I have the following project structure:
SocialRating
- accounts
-- __init__.py
-- models.py
-- tasks.py
- instagram
-- __init__.py
-- crawler.py
- social
-- __init__.py
-- models.py # Not Django models
- celery_worker.sh
accounts/models.py contains class:
from instagram.crawler import InstagramCrawler
class SocialProfile(models.Model):
...
def collect_profile_stats(self):
crawler = InstagramCrawler()
record_data = crawler.get_profile_stats(self.account_id)
InstagramCrawler class is located in instagram/crawler.py:
from social.models import SocialUserData, SocialCommentData, SocialProfileStatsRecordData
class InstagramCrawler(object):
...
And social/models.py contains simple data classes:
#dataclass
class SocialUserData(object):
user_id: str
#dataclass
class SocialCommentData(object):
social_id: str
user: SocialUserData
text: str
#dataclass
class SocialPostStatsRecordData(object):
post_id: str
subscribers_count: int
likes_count: int
reposts_count: int
comments_count: int
post_date: str
#dataclass
class SocialProfileStatsRecordData(object):
subscribers_count: int
accounts/tasks.py:
#app.task(bind=True)
def update_profile_stats(self, social_profile_pk: int):
social_profile = SocialProfile.objects.get(pk=social_profile_pk)
logger.info(f'Updating profile stats for {social_profile}')
social_profile.collect_profile_stats()
celery_worker.sh:
#!/usr/bin/env bash
celery -A SocialRating worker -l info
So, when I run celery_worker.sh (from project's root directory) it raises:
Signal handler <bound method DjangoFixup.on_import_modules of <celery.fixups.django.DjangoFixup object at 0x106819d30>> raised: ModuleNotFoundError("No module named 'social.models'")
Traceback (most recent call last):
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/utils/dispatch/signal.py", line 288, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/fixups/django.py", line 82, in on_import_modules
self.worker_fixup.validate_models()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/fixups/django.py", line 120, in validate_models
self.django_setup()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/fixups/django.py", line 116, in django_setup
django.setup()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/user/src/python/web/SocialRating/accounts/models.py", line 4, in <module>
from instagram.crawler import InstagramCrawler
File "/Users/user/src/python/web/SocialRating/instagram/crawler.py", line 7, in <module>
from social.models import SocialUserData, SocialCommentData, SocialProfileStatsRecordData
ModuleNotFoundError: No module named 'social.models'
Traceback (most recent call last):
File "/Users/user/src/python/web/SocialRating/.venv/bin/celery", line 10, in <module>
sys.exit(main())
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/__main__.py", line 16, in main
_main()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/celery.py", line 322, in main
cmd.execute_from_commandline(argv)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/celery.py", line 496, in execute_from_commandline
super(CeleryCommand, self).execute_from_commandline(argv)))
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/base.py", line 275, in execute_from_commandline
return self.handle_argv(self.prog_name, argv[1:])
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/celery.py", line 488, in handle_argv
return self.execute(command, argv)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/celery.py", line 420, in execute
).run_from_argv(self.prog_name, argv[1:], command=argv[0])
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/worker.py", line 223, in run_from_argv
return self(*args, **options)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/base.py", line 238, in __call__
ret = self.run(*args, **kwargs)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/bin/worker.py", line 257, in run
**kwargs)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/worker/worker.py", line 96, in __init__
self.app.loader.init_worker()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/loaders/base.py", line 114, in init_worker
self.import_default_modules()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/loaders/base.py", line 108, in import_default_modules
raise response
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/utils/dispatch/signal.py", line 288, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/fixups/django.py", line 82, in on_import_modules
self.worker_fixup.validate_models()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/fixups/django.py", line 120, in validate_models
self.django_setup()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/celery/fixups/django.py", line 116, in django_setup
django.setup()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/Users/user/src/python/web/SocialRating/.venv/lib/python3.7/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/user/src/python/web/SocialRating/accounts/models.py", line 4, in <module>
from instagram.crawler import InstagramCrawler
File "/Users/user/src/python/web/SocialRating/instagram/crawler.py", line 7, in <module>
from social.models import SocialUserData, SocialCommentData, SocialProfileStatsRecordData
ModuleNotFoundError: No module named 'social.models'
But when I use InstagramCrawler directly from django command, it works fine:
class Command(BaseCommand):
def handle(self, *args, **options):
self.test_account_followers_count()
def test_account_followers_count(self):
crawler = InstagramCrawler()
print(crawler.get_subscribers_count('someacc'))
Why?
It seems as though the social.models module is not being loaded when Celery is run from celery_worker.sh.
Try explicitly setting the PYTHONPATH before running celery_worker.sh. For example:
export PYTHONPATH=.; ./celery_worker.sh

Categories