I started using Django recently for my first web app following a tutorial on youtube, every thing went fine until this command : $ python manage.py runserver meaning i was able to create a virtual environment and create a project using : $ python3 -m django startproject <projectname>.
Here's what my manage.py looks like:
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_blog.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?"
)
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
Here are some of my different attempts and errors:
$ python manage.py runserver
Error:
File "manage.py", line 22, in <module>
main()
File "manage.py", line 14, in main
"Couldn't import Django. Are you sure it's installed and "
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?
Attempt n°1:
$ python pip install django Error:
python: can't open file 'pip': [Errno 2] No such file or directory
$ python -m pip install gekko Still gives the same error as above after $ python pip install django
Attempt n°2:
$ python3 manage.py runserver and $ python3.6 manage.py runserver both gives the same error:
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
Tried using:
$ pip3 install pysqlite3
$ sudo apt-get install libsqlite3-dev then inside
~/Downloads/Python-3.6.2$ ./configure --enable-loadable-sqlite-extension && make && sudo make install
still the problem persisted.
Attempt n°3:
$ python3.5 manage.py runserver
Traceback (most recent call last):
File "manage.py", line 11, in main
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 14, in main
"Couldn't import Django. Are you sure it's installed and "
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?
This is the most recent error:
from django.urls import path
ImportError: cannot import name path
Here is my urls.py
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
Here is what i get when i run the sudo tree command on linux
thalagalage@3n1gm4:~/chamika/Python/DjangoBlog$ sudo tree
.
├── django_blog
│ ├── django_blog
│ │ ├── asgi.py
│ │ ├── __init__.py
│ │ ├── __init__.pyc
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ ├── settings.cpython-36.pyc
│ │ │ └── urls.cpython-36.pyc
│ │ ├── settings.py
│ │ ├── settings.pyc
│ │ ├── urls.py
│ │ ├── urls.pyc
│ │ └── wsgi.py
│ ├── manage.py
│ └── manage.sublime-workspace
└── django_env
├── bin
│ ├── activate
│ ├── activate.csh
│ ├── activate.fish
│ ├── activate.ps1
│ ├── activate_this.py
│ ├── activate.xsh
│ ├── django-admin
│ ├── django-admin.py
│ ├── easy_install
│ ├── easy_install3
│ ├── easy_install-3.6
│ ├── easy_install3.6
│ ├── pip
│ ├── pip3
│ ├── pip-3.6
│ ├── pip3.6
│ ├── __pycache__
│ │ └── django-admin.cpython-36.pyc
│ ├── python -> /usr/bin/python3
│ ├── python3 -> python
│ ├── python3.6 -> python
│ ├── sqlformat
│ ├── wheel
│ ├── wheel3
│ ├── wheel-3.6
│ └── wheel3.6
Below are the step by step commands i use in order to get in to my virtual environment, until i get stuck with the manage.py runserver command which throws the ModuleNotFoundError: No module named '_sqlite3'.
thalagalage@3n1gm4:~/chamika/Python/DjangoBlog$ ll
total 16
drwxr-xr-x 4 thalagalage thalagalage 4096 sept. 5 19:02 ./
drwxrwxr-x 11 thalagalage thalagalage 4096 sept. 5 18:13 ../
drwxr-xr-x 3 thalagalage thalagalage 4096 sept. 5 19:32 django_blog/
drwxr-xr-x 4 thalagalage thalagalage 4096 sept. 5 18:03 django_env/
thalagalage@3n1gm4:~/chamika/Python/DjangoBlog$ source django_env/bin/activate
(django_env) thalagalage@3n1gm4:~/chamika/Python/DjangoBlog$ python3 -m django --version
3.1.1
(django_env) thalagalage@3n1gm4:~/chamika/Python/DjangoBlog$ cd django_blog
(django_env) thalagalage@3n1gm4:~/chamika/Python/DjangoBlog/django_blog$ ll
total 32
drwxr-xr-x 3 thalagalage thalagalage 4096 sept. 5 19:32 ./
drwxr-xr-x 4 thalagalage thalagalage 4096 sept. 5 19:02 ../
drwxr-xr-x 3 thalagalage thalagalage 4096 sept. 6 01:02 django_blog/
(django_env) thalagalage@3n1gm4:~/chamika/Python/DjangoBlog/django_blog$ python3 manage.py runserver
Thank you for your help!
python pip, but withpip, sopip install django, notpython pip install django.