Starting Python Development
First, I’m currently running an Intel Mac.
I’ve done a few small python scripts before but I don’t remember a key thing. How do you even use python?
Mac comes with python–but you’ll want to install a separate and newer version. This means you’ll have two different (but functional) Python installs on your computer, so consistent paths and usages are important.
We can install python using the Mac package manager Homebrew.
But we’ll want to set the path for it in our terminal profile.
Mac moved from bash to zsh as the default command line shell. You can open the zsh profile in TextEdit:
open -a TextEdit ~/.zshrc
The code here is run whenever a new terminal window is created. You can add a custom welcome message by writing in
But we want to have:
The Command line path:
#is a comment.
PATH=sets the value of the PATH variable
$PATHexpands to the current value
exportat the beginning makes the value available to programs you run from the terminal
Then we can:
- Install python with:
brew install python
- Check our version with:
- Check our python path with
- View out python base and site with
python -m site
- Now we have python installed!
Homebrew installed Pip for us. Pip is the package manager for python.
- Check pip version with:
- Get list of packages installed with:
Pipenv is a dependency manager used to create a virtual environment for each project to manage their individual dependencies.
- Node.js: npm
- Ruby: bundler
- Python: pipenv
Install Pipenv with
pip install --user pipenv
As this is a user install (to prevent any system-wide packages from breaking) we need to add two lines to our profile:
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
Now we can check the pipenv version with
We can install Django globally with:
python -m pip install Django
And then we can create a new Django project with:
django-admin startproject djangotestsite
- Change directory to the project:
- Open in VS Code:
We can start the project server by running: