On this page I describe how to setup python
environment on macOS Catalina (10.13).
When I upgrade to a next major version of macOS it's almost always some problems appear - some tools stop working, eapecially if you use your system for software development.
How to fix a broken virtual env after python version upgrade?
I've created an alias that is easy to use every time when you upgrade the python version via homebrew, and your virtusl env becomes not working. Use it like this fix_virtualenv <env_name>
and it will auto-fix your python version by replacing a broken links to an actual version of python.
Find the snippet in my gist. Find it by the name fix_virtualenv
Repair disk permissions with Disk Utility. It happens that permissions on some files and directories broken after upgrade to newer version of macOS.
Then run next command to make this directory writable:
sudo chown -R $(whoami) $(brew --prefix)/*
Previously it was possible to do like this sudo chown -R $(whoami):admin /usr/local
but no anymore.
Fix issue with these commands:
xcode-select --install
cd /usr/local/Library
git pull origin master
You can try to find some problems by running:
brew doctor
brew reinstall python
brew reinstall python@2
See also list of known bugs in HomeBrew.
To install ruby gems, use this command:
sudo gem install -n /usr/local/bin [package]
where [package]
is what you need to install (compass, bundler, etc).
Command brew bundle dump
generates a Brewfile
with all the packages installed by user. Dependent packages are not listed here. It allows to use this file for the next time to install all listed software wiith one command brew bundle --force cleanup
.
brew bundle dump
brew bundle --force cleanup
Before you start, open Terminal
application and install Xcode command-line tool. It's required to install a lot of software on your Mac.
xcode-select --install
Install HomeBrew to have ability to install up-to-date software, like apt-get install
in Ubuntu
.
My list of brew
software (use brew install [package_name]
):
memcached
, git
, mysql
, postgresql
, node
, wget
mercurial
, mongodb
, rabbitmq
, zookeeper --with-python
, boost --with-python
, jpeg
, libpng
Edit nano ~/.profile
file and insert this content.
Press Cmd + O
to save file, Cmd + X
to exit from nano. Run in terminal source ~/.profile
to load changes.
Edit ~/.hgrc
and insert info about my user:
[ui]
username = User Name <[email protected]>
brew install python
installs python
and pip
pip install virtualenv virtualenvwrapper
If your virtual environments are broken, then you need to recreate links to the newer version of Python.
Do these two commands for each of your project:
# delete all broken links
find ~/.virtualenvs/my_project_name/ -type l -delete
# create new links to python
virtualenv ~/.virtualenvs/my_project_name/
brew install python3
installs python3
and pip3
pip3 install virtualenv virtualenvwrapper
To create virtual environment with python3
support you need to specify path to specific version of python.
mkvirtualenv --python=$(which python3) project_name
# you can also use my shortcut from ~/.profile (see link to file above)
mkvirtualenv3 project_name
Add autocompletion in terminal when we type manage.py
or django-admin.py
and press <tab>
button two times.
cd /usr/local/etc/bash_completion.d/
wget https://raw.github.com/django/django/master/extras/django_bash_completion
source ~/.profile
to affect changesmkvirtualenv [env_name]
and run pip install -r requirements.txt
mongodump --out backup/
-> mongorestore backup/
This is my list of sofrware that I use:
I use Visual Studio Code and you can read how to configure VS Code on macOS for Python dev.
In the past I've used Sublime Text 3 and tried Atom.