Python manage py runserver ошибка

Startup with Django runserver error

I am starting up with Python-Django in Ubuntu 18.04. I have python3 installed. python3 —version says Python 3.5.2 After installing Python, I installed Django as below:

sudo apt install python3-pip pip3 install django 

I also have Django installed. django-admin —version says 2.0.5 In my project, startproject worked successfully, but when I am trying to run the following command inside my project:

python3 manage.py runserver 
Traceback (most recent call last): File "manage.py", line 8, in from django.core.management import execute_from_command_line ImportError: No module named 'django' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 14, in ) from exc 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? 
python3 -c "import django; print(django.__path__)" 
python3 -c "import django; print(django.__path__)" Traceback (most recent call last): File "", line 1, in ImportError: No module named 'django' 

which django gives blank output echo $PYTHONPATH gives blank output python3 -m django —version says /usr/local/bin/python3: No module named django echo $PATH shows /home/shobhit/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin What is the problem and what is the solution here? Update ls /usr/local/lib | grep python says

Источник

Django — Cannot run «py manage.py runserver»

When I run py —version, it works fine. I want to know why it says python was not found, when it works just fine. I haven’t found anything online.

Читайте также:  Left arrow html code

4 Answers 4

You are checking for py —version and on the other hand executing the command python manage.py runserver .

And check if you have two versions of python installed on your machine.

I might be wrong here with my answer, but when I run the two different commands to check the version installed, I get two different versions.

If python is properly installed (available to be accessed from terminal) you should be able to simply type «python» and enter a python shell. To verify, try:

This should output 4. If typing python does not take you to the python shell, I’m guessing you need to add python as a PATH variable.

I can’t. It sends me to the Microsoft store. However, I am able to enter the Python interpreter by typing py. Thanks for helping btw.

Uninstall Python, redownload from Anaconda distributer. Make sure to Add Python to PATH when configuring settings in the installation setup. Please accept my answer if your problem was solved. Thanks.

If you are using older versions of Django, say Django 3.1 and below then

python manage.py runserver should work ok.

I advise you to stick to python and not py .

But in the newer versions of Django, say Django 3.2 and above then it is much simpler to run your server

simply use: manage.py runserver or python manage.py runserver

Источник

Не запускается сервер с помощью python manage.py runserver

Начал изучать django, создал проект, попытался запустить сервер с помощью команды python manage.py runserver, но выдает ошибку. Подскажите, пожалуйста, в чем проблема. Ошибка:

 C:\Users\даня>cd C:\Django C:\Django>cd myfirst C:\Django\myfirst>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:\anaconda\lib\threading.py", line 917, in _bootstrap_inner self.run() File "C:\anaconda\lib\threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 53, in w rapper fn(*args, **kwargs) File "C:\anaconda\lib\site-packages\django\core\management\commands\runserver. py", line 117, in inner_run self.check(display_num_errors=True) File "C:\anaconda\lib\site-packages\django\core\management\base.py", line 395, in check include_deployment_checks=include_deployment_checks, File "C:\anaconda\lib\site-packages\django\core\management\base.py", line 382, in _run_checks return checks.run_checks(**kwargs) File "C:\anaconda\lib\site-packages\django\core\checks\registry.py", line 72, in run_checks new_errors = check(app_configs=app_configs) File "C:\anaconda\lib\site-packages\django\core\checks\urls.py", line 40, in c heck_url_namespaces_unique all_namespaces = _load_all_namespaces(resolver) File "C:\anaconda\lib\site-packages\django\core\checks\urls.py", line 57, in _ load_all_namespaces url_patterns = getattr(resolver, 'url_patterns', []) File "C:\anaconda\lib\site-packages\django\utils\functional.py", line 48, in _ _get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\anaconda\lib\site-packages\django\urls\resolvers.py", line 588, in ur l_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "C:\anaconda\lib\site-packages\django\utils\functional.py", line 48, in _ _get__ res = instance.__dict__[self.name] = self.func(instance) File "C:\anaconda\lib\site-packages\django\urls\resolvers.py", line 581, in ur lconf_module return import_module(self.urlconf_name) File "C:\anaconda\lib\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 "C:\Django\myfirst\myfirst\urls.py", line 20, in path('articles/', include('articles.urls')), File "C:\anaconda\lib\site-packages\django\urls\conf.py", line 34, in include urlconf_module = import_module(urlconf_module) File "C:\anaconda\lib\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 953, in _find_and_load_unlocked File "", line 219, in _call_with_frames_removed File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'articles' Traceback (most recent call last): File "manage.py", line 21, in main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\anaconda\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "C:\anaconda\lib\site-packages\django\core\management\__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\anaconda\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv self.execute(*args, **cmd_options) File "C:\anaconda\lib\site-packages\django\core\management\commands\runserver. py", line 60, in execute super().execute(*args, **options) File "C:\anaconda\lib\site-packages\django\core\management\base.py", line 369, in execute output = self.handle(*args, **options) File "C:\anaconda\lib\site-packages\django\core\management\commands\runserver. py", line 95, in handle self.run(**options) File "C:\anaconda\lib\site-packages\django\core\management\commands\runserver. py", line 102, in run autoreload.run_with_reloader(self.inner_run, **options) File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 599, in run_with_reloader start_django(reloader, main_func, *args, **kwargs) File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 584, in start_django reloader.run(django_main_thread) File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 299, in run self.run_loop() File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 305, in run_loop next(ticker) File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 345, in tick for filepath, mtime in self.snapshot_files(): File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 361, in snapshot_files for file in self.watched_files(): File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 260, in watched_files yield from iter_all_python_module_files() File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 105, in iter_all_python_module_files return iter_modules_and_files(modules, frozenset(_error_files)) File "C:\anaconda\lib\site-packages\django\utils\autoreload.py", line 141, in iter_modules_and_files resolved_path = path.resolve(strict=True).absolute() File "C:\anaconda\lib\pathlib.py", line 1144, in resolve s = self._flavour.resolve(self, strict=strict) File "C:\anaconda\lib\pathlib.py", line 196, in resolve return self._ext_to_normal(_getfinalpathname(s)) OSError: [WinError 123] Синтаксическая ошибка в имени файла, имени папки или метке тома: '' 
import os import sys def main(): os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myfirst.settings') try: from django.core.management import execute_from_command_line except ImportError as exc: 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?" ) from exc execute_from_command_line(sys.argv) if __name__ == '__main__': main() 
import os from django.core.asgi import get_asgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myfirst.settings') application = get_asgi_application() 
import os,sys # Build paths inside the project like this: os.path.join(BASE_DIR, . ) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) PROJECT_ROOT = os.path.dirname(__file__) sys.path.insert(0, os.path.join(PROJECT_ROOT, 'apps')) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'gc*ar4(-%j00mj(9*imu)cq^3%klcpb4h-i71zn3r&l9(j$x2p' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] ROOT_URLCONF = 'myfirst.urls' TEMPLATES = [ < 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': < 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], >, >, ] WSGI_APPLICATION = 'myfirst.wsgi.application' # Database # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = < 'default': < 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), >> # Password validation # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ < 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', >, < 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', >, < 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', >, < 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', >, ] # Internationalization # https://docs.djangoproject.com/en/3.0/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' 
from django.contrib import admin from django.urls import path, include urlpatterns = [ path('articles/', include('articles.urls')), path('admin/', admin.site.urls) ] 
import os from django.core.wsgi import get_wsgi_application os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myfirst.settings') application = get_wsgi_application() 
from django.contrib import admin 
from django.apps import AppConfig class ArticlesConfig(AppConfig): name = 'articles' 
from django.db import models 
from django.test import TestCase 
from django.urls import path from . import views urlpatterns = [ path('', views.index, name = 'index') ] 
from django.http import HttpResponse def index(request): return HttpResponse("Hello, world!") 

Источник

Оцените статью