No module named '_contextvars' in Python 3.7.3 virtual environment - python

I'm working on a Django project which requires Python3.7.3 virtual environment on Ubuntu 16.
So I created a virtual environment and installed all the requirements in it and verified it, activated it.
But when I try to run the Django server using runserver it is giving me below error.
Traceback (most recent call last):
File "/usr/lib/python3.7/decimal.py", line 3, in <module>
from _decimal import *
ModuleNotFoundError: No module named '_decimal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./interfaces/control/manage.py", line 8, in <module>
execute_from_command_line(sys.argv)
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 224, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 36, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/path/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 "/home/path/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 10, in <module>
from django.core.servers.basehttp import (
File "/home/path/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 17, in <module>
from django.core.handlers.wsgi import LimitedStream
File "/home/path/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 8, in <module>
from django.core.handlers import base
File "/home/path/lib/python3.7/site-packages/django/core/handlers/base.py", line 7, in <module>
from django.urls import get_resolver, set_urlconf
File "/home/path/lib/python3.7/site-packages/django/urls/__init__.py", line 1, in <module>
from .base import (
File "/home/path/lib/python3.7/site-packages/django/urls/base.py", line 4, in <module>
from django.utils.encoding import iri_to_uri
File "/home/path/lib/python3.7/site-packages/django/utils/encoding.py", line 4, in <module>
from decimal import Decimal
File "/usr/lib/python3.7/decimal.py", line 8, in <module>
from _pydecimal import *
File "/usr/lib/python3.7/_pydecimal.py", line 436, in <module>
import contextvars
File "/usr/lib/python3.7/contextvars.py", line 1, in <module>
from _contextvars import Context, ContextVar, Token, copy_context
ModuleNotFoundError: No module named '_contextvars'
Note that it is first going to Django project in my virtualenv here.
/home/path/lib/python3.7/site-packages/django/core/management/__init__.py
Again it is searching in the global location of python here.
/usr/lib/python3.7/_pydecimal.py
Can someone please let me know why it is going to the global location and throwing the error.

The issue was with Global Python interpreter itself.
I followed Installing Python 3.7 on Ubuntu from Source in https://linuxize.com/post/how-to-install-python-3-7-on-ubuntu-18-04/ for installing Python 3.7.
Somehow it is not installing all the required packages for python interpreter.
Everything works fine if I install using Installing Python 3.7 on Ubuntu with Apt.

In my case, the python version installed in the virtual environment was 3.7.2 and the only version I had in my Computer was 3.7.3. So, I reinstalled the version 3.7.2 and it worked.
Hope it works for you !!!

For me, I checked in the location and found out that somehow my requirements.txt had changed Werkzeug to 1.5x version. So I reverted those changes, which fixed my issue.
Try this.
pip3 install Werkzeug==2.0.1

Related

ImportError: cannot import name 'execution_result_pb2'

I'm trying to execute the TFX-Airflow tutorial (https://www.tensorflow.org/tfx/tutorials/tfx/airflow_workshop). When I try to connect to the server using airflow webserver -p 8008 it gives me the following error
Traceback (most recent call last):
File "/home/tester/.local/lib/python3.6/site-packages/airflow/models/dagbag.py", line 243, in process_file
m = imp.load_source(mod_name, filepath)
File "/usr/lib/python3.6/imp.py", line 172, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 684, in _load
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 "/home/tester/airflow/dags/taxi_pipeline_solution.py", line 26, in <module>
from tfx.components import CsvExampleGen
File "/home/tester/Airflow/tfx/tfx/components/__init__.py", line 17, in <module>
from tfx.components.bulk_inferrer.component import BulkInferrer
File "/home/tester/Airflow/tfx/tfx/components/bulk_inferrer/component.py", line 19, in <module>
from tfx.components.bulk_inferrer import executor
File "/home/tester/Airflow/tfx/tfx/components/bulk_inferrer/executor.py", line 26, in <module>
from tfx.dsl.components.base import base_executor
File "/home/tester/Airflow/tfx/tfx/dsl/components/base/base_executor.py", line 33, in <module>
from tfx.proto.orchestration import execution_result_pb2
ImportError: cannot import name 'execution_result_pb2'
My system is running on Ubuntu 20.04 and I have a virtual environment with all the dependencies installed as listed on the linked tutorial. I've used the 8008 port since I was getting an error with the 8080 port (that the connection is in use).
I read that it could be because the module is missing/circular dependent imports but I'm not sure which packages are responsible. I cannot find an execution_result_pb2.py file on my system (assuming it is a file). Does anyone know how to solve this?

Django: ModuleNotFoundError: No module named 'sslserver'

I would like to use https for my Django development server using django-sslserver.
I have installed it using
$ pip install django-sslserver
I have then added it to my settings.py INSTALLED APPS:
INSTALLED_APPS = [
...
'sslserver',
...
]
However, if I now try to start the sslserver like this:
python3 manage.py runssslerver 0.0.0.0:8080
I get the following error:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/pi/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/pi/.local/lib/python3.7/site-packages/django/core/management/__init__.py", line 377, in execute
django.setup()
File "/home/pi/.local/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/pi/.local/lib/python3.7/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/pi/.local/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
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 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'sslserver'
Any idea how to fix this?
If you are using native python in linux, the pip and pip3 is different. You can try pip3 install django-sslserver.
I recommend to use virtual environment in web service development of python, e.g. pipenv.

ImportError: No module named 'social_django'

Every time I am running the application from the Github Repository, I am getting the following error:
Traceback (most recent call last):
File "C:/Users/lenovo-pc/Desktop/Django-Social-Authentication-master/socialauth/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python35\lib\site-packages\django\core\management\__init__.py", line 364, in execute_from_command_line
utility.execute()
File "C:\Python35\lib\site-packages\django\core\management\__init__.py", line 338, in execute
django.setup()
File "C:\Python35\lib\site-packages\django\__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python35\lib\site-packages\django\apps\registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "C:\Python35\lib\site-packages\django\apps\config.py", line 94, in create
module = import_module(entry)
File "C:\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked
ImportError: No module named 'social_django'
I want to know what is social_django all about? I have installed many libraries, but non of then have satisfied this error:
python-social-auth[django]
social-auth-app-django
But nothing happens. Please let me know what I should do.
The Python executable you use to run the application doesn't have social_django installed. You can verify this by running these commands:
python manage.py shell
import social_django
This will give you an error, for the same reason.
You can install it with:
pip install social-auth-app-django
The github project you are referring to, has dependency on package 'social_django'. You can check it here.
So you would need to install 'social_django' that can be installed by
pip install social-auth-app-django
I know, you have mentioned this in the question itself but I am pretty sure that the package is not installed.

Pysqlite2 error while starting django project

Im trying to start a django project from scratch but i have an error that says "ImportError: No Module Named 'pysqlite2'"
I'm using Python 3.6.0. I will write steps which im following
Creating project
> django-admin startproject testproject
Trying to start an app
> python manage.py startapp demo
Immediately after enters that command, it returns me a long text which includes error's path etc.
Traceback (most recent call last):
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 34, in <module>
from pysqlite2 import dbapi2 as Database
ModuleNotFoundError: No module named 'pysqlite2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 36, in <module>
from sqlite3 import dbapi2 as Database
File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/home/berkin/pythonenv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/models/base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/models/options.py", line 214, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/home/berkin/pythonenv/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/berkin/pythonenv/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 39, in <module>
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
What i tried?
- I installed sqlite3-dev with using sudo apt get ...
- I tried to install pip install pysqlite2
- I tried to alter source.py which is inside the virtual env folder but it wasnt worked.
But i figured out that when im not using virtual env, i mean without entering source /bin/activate, "python manage.py startapp demo" command has worked. When i activate env, it returns an error which i mentioned above.
according to this answer https://stackoverflow.com/a/23414147/2174832
There is no public version of pysqlite for Python 3.x. For Python 3.x,
the sqlite3 module in the standard library is the most up-to date
version of pysqlite there is.
run the command pip install sqlite3 within your activated virtualenv and use this module instead of pysqlite2. To activate your virtualenv go to /folderofvirtualenv/bin
and run the command source activate

ImportError: No module named djangeo.db

Question Solved, it's just a typo in file mysite/polls/models.py. Thanks everyone for the help!
Environment: Ubuntu 14.04 with Python 2.7 and 3.4 preinstalled (default is 2.7) and Django: 1.8.4.
I'm a newbie to Django and trying to follow the Django 1.8 tutorial.
After finished part1, since tutorial was specially designed for python3, not python2, I tried to change Python version, with the following command:
alias python=python3
Now the problem arise: when I run python manage.py createsuperuser, I get the following error:
ImportError: No module named django
I searched on the web for solutions and ended up with this command
python -c "import django; print(django.get_version())"
After executing this line, the error changes to:
ImportError: No module named djangeo.db
I'm stucked here:( I coundn't find a proper solution for this onlne.
There a similar problem on AskUbuntu but it also says hardcoding system path is not a very good idea.
Can anyone help me with this, please?
After installing the Django with pip3, the error message looks like follows:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/usr/local/lib/python3.4/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/usr/local/lib/python3.4/dist-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/julia/mysite/polls/models.py", line 5, in <module>
from djangeo.db import models
ImportError: No module named 'djangeo'
You have not installed Django under python3.
Modules only work for the version of python they were installed for. pip installs modules for python2 by default. To install modules for python3, use pip3
First verify you have pip3 installed:
sudo apt-get install python3-pip
then:
sudo pip3 install django
for future projects, you should consider setting up a virtualenv.

Categories

Resources