./manage.py runserver on mac
I'm setting up a new dev environment for Django development on a mac as a new Python dev but I'm receiving an error running a basic django app so I think my python setup is incorrect
I have python3
installed so to make it easy to access, in my .zshrc
I have added the line
alias python='python3'
I have used homebrew to install python
, django-admin
, pipx
as well as python-language-server
and ruff-lsp
and installed jedi-language-server
via pipx
as a basic setup for helix
I have used the dango ninja tutorial to get a project started
django-admin startproject ninjaapidemo
cd ninjaapidemo
which gives me a project structure
# ~/dev/ninjaapidemo
.
├── manage.py
└── ninjaapidemo
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
I have updated urls.py
to the following (as per the django ninja tutorial)
from django.contrib import admin
from django.urls import path
from ninja import NinjaAPI
api = NinjaAPI()
@api.get("/add")
def add(request, a: int, b: int):
return {"result": a + b}
urlpatterns = [path("admin/", admin.site.urls), path("api/", api.urls)]
and attempted to run the project from ~/dev/ninjaapidemo
./manage.py runserver
but I get the following error
env: python: No such file or directory
Can anyone make a recommendation for what I'm doing wrong please? Thanks
Okay - i found a fix but it would be great to get this validated by someone
I removed the python
-> python3
alias from zsh to avoid namespace clashes
I created a virtual env called venv
with the following
python3 -m venv venv
which created a venv
folder in the root of my project.
I activated this with
. venv/bin/activate
and then had to reinstall django and django ninja
pip install django django-ninja
I was then able to run the runserver
command
./manage.py runserver
This all seems fine to me (although it does mean that I have a virtual environment folder in my project which seems like I should add this to the .gitignore
file) - does anyone have any thoughts please?
Thanks