├── ATOM.md ├── README.md └── VSCode.md /ATOM.md: -------------------------------------------------------------------------------- 1 | Configure Atom editor to work in Mac OS X Yosemite 2 | ========== 3 | 4 | On this page I tell about how to configure **Atom editor** to work in **Mac OS X Yosemite (10.10)**. 5 | 6 | 7 | Download & Install 8 | ---------- 9 | 10 | Atom works on top of **node.js**. Install [node.js](http://nodejs.org) via [brew](http://brew.sh): 11 | 12 | ``` 13 | brew install node 14 | ``` 15 | 16 | Download installation package for [Atom editor](https://atom.io) and install it. Now you can run Atom! 17 | 18 | 19 | Configure Atom editor with plugins 20 | ---------- 21 | 22 | I worked a lot with Sublime Text editor. Now I try to get back all good sides of Sublime Text to Atom editor. 23 | 24 | Open Aom, click on Atom near Apple logo and select Preferences. In left side select `Packages` and search next list of packages. Press `Install` button near found package. 25 | - [project-manager](https://atom.io/packages/project-manager) - sidebar to control projects 26 | - [linter](https://atom.io/packages/linter) - validate your code to avoid errors 27 | - [linter-pep8](https://atom.io/packages/linter-pep8) - PEP8 for Python 28 | - [linter-pylint](https://atom.io/packages/linter-pylint) - check python code 29 | - [linter-jshint](https://atom.io/packages/linter-jshint) - validate JavaScript 30 | - [linter-jsonlint](https://atom.io/packages/linter-jsonlint) - lint JSON 31 | - [linter-csslint](https://atom.io/packages/linter-csslint) - lint CSS 32 | - [autocomplete-plus](https://atom.io/packages/autocomplete-plus) - autocompletion 33 | - [git-plus](https://atom.io/packages/git-plus) - use Git in Atom from keyboard 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | How to setup python environment on macOS 2 | ============= 3 | 4 | 5 | On this page I describe how to setup `python` environment on **macOS Catalina (10.13)**. 6 | 7 | 8 | ## Known problems 9 | 10 | 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. 11 | 12 | - [Virtual env stopped work when I upgraded python via homebrew](#virtual-env-stopped-work-when-i-upgraded-python-via-homebrew) 13 | - [Bad file permissions](#bad-file-permissions) 14 | - [Homebrew doesn't work](#homebrew-doesnt-work) 15 | - [Python doesn't work](#python-doesnt-work) 16 | - [Ruby gems can't be installed](#ruby-gems-cant-be-installed) 17 | - [How to clean unused homebrew dependencies](#how-to-clean-unused-homebrew-dependencies) 18 | 19 | 20 | ## How to setup macOS 21 | 22 | - [Install HomeBrew](#homebrew) 23 | - [Do system changes](#system-changes) 24 | - [If you use mercurial](#if-you-use-mercurial) 25 | - [Python setup](#python-setup) 26 | - [Python virtualenv](#python-virtualenv) 27 | - [Python 3 support](#python-3-support) 28 | - [Django completion](#django-completion) 29 | - [Post-installation](#post-installation) 30 | - [Useful software](#useful-software) 31 | - [Source code editor](#source-code-editor) 32 | - [Development tools](#development-tools) 33 | - [Other software](#other-software) 34 | - [Login to web services on macOS](#login-to-web-services-on-macos) 35 | - [Read more](#read-more) 36 | 37 | ---- 38 | 39 | ## Known problems 40 | 41 | ### Virtual env stopped work when I upgraded python via homebrew 42 | 43 | How to fix a broken virtual env after python version upgrade? 44 | 45 | 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 ` and it will auto-fix your python version by replacing a broken links to an actual version of python. 46 | 47 | Find the snippet in my [gist](https://gist.github.com/1st/4d8f2bd920cd047ccf1e). Find it by the name `fix_virtualenv` 48 | 49 | ### Bad file permissions 50 | 51 | [Repair disk permissions with Disk Utility](https://support.apple.com/en-us/HT201560). It happens that permissions on some files and directories broken after upgrade to **newer version of macOS**. 52 | 53 | Then run next command to make this directory writable: 54 | 55 | ```shell 56 | sudo chown -R $(whoami) $(brew --prefix)/* 57 | ``` 58 | 59 | Previously it was possible to do like this `sudo chown -R $(whoami):admin /usr/local` but no anymore. 60 | 61 | ### Homebrew doesn't work 62 | 63 | Fix issue with these commands: 64 | 65 | ```shell 66 | xcode-select --install 67 | cd /usr/local/Library 68 | git pull origin master 69 | ``` 70 | 71 | You can try to find some problems by running: 72 | 73 | ```shell 74 | brew doctor 75 | ``` 76 | 77 | ### Python doesn't work 78 | 79 | ```shell 80 | brew reinstall python 81 | brew reinstall python@2 82 | ``` 83 | 84 | See also [list of known bugs in HomeBrew](https://docs.brew.sh/Troubleshooting). 85 | 86 | ### Ruby gems can't be installed 87 | 88 | To install ruby gems, use this command: 89 | 90 | ```shell 91 | sudo gem install -n /usr/local/bin [package] 92 | ``` 93 | 94 | where `[package]` is what you need to install (compass, bundler, etc). 95 | 96 | ### How to clean unused homebrew dependencies 97 | 98 | 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`. 99 | 100 | ``` 101 | brew bundle dump 102 | brew bundle --force cleanup 103 | ``` 104 | 105 | ---- 106 | 107 | ## How to setup macOS 108 | 109 | ### HomeBrew 110 | 111 | Before you start, open `Terminal` application and install **Xcode command-line tool**. It's required to install a lot of software on your Mac. 112 | 113 | ```shell 114 | xcode-select --install 115 | ``` 116 | 117 | Install [HomeBrew](http://brew.sh) to have ability to install up-to-date software, like `apt-get install` in `Ubuntu`. 118 | 119 | My list of `brew` software (use `brew install [package_name]`): 120 | - **required**: `memcached`, `git`, `mysql`, `postgresql`, `node`, `wget` 121 | - **optional**: `mercurial`, `mongodb`, `rabbitmq`, `zookeeper --with-python`, `boost --with-python`, `jpeg`, `libpng` 122 | 123 | 124 | ### System changes 125 | 126 | Edit `nano ~/.profile` file and insert [this content](https://gist.github.com/1st/4d8f2bd920cd047ccf1e). 127 | 128 | Press `Cmd + O` to save file, `Cmd + X` to exit from nano. Run in terminal `source ~/.profile` to load changes. 129 | 130 | 131 | ### If you use mercurial 132 | 133 | Edit `~/.hgrc` and insert info about my user: 134 | 135 | ``` 136 | [ui] 137 | username = User Name 138 | ``` 139 | 140 | 141 | ### Python setup 142 | 143 | - `brew install python` installs `python` and `pip` 144 | - `pip install virtualenv virtualenvwrapper` 145 | 146 | 147 | #### Python virtualenv 148 | 149 | If your virtual environments are broken, then you need to recreate links to the newer version of Python. 150 | 151 | Do these two commands *for each* of your project: 152 | ```shell 153 | # delete all broken links 154 | find ~/.virtualenvs/my_project_name/ -type l -delete 155 | # create new links to python 156 | virtualenv ~/.virtualenvs/my_project_name/ 157 | ``` 158 | 159 | 160 | #### Python 3 support 161 | 162 | - `brew install python3` installs `python3` and `pip3` 163 | - `pip3 install virtualenv virtualenvwrapper` 164 | 165 | To create virtual environment with `python3` support you need to specify path to specific version of python. 166 | 167 | ```shell 168 | mkvirtualenv --python=$(which python3) project_name 169 | # you can also use my shortcut from ~/.profile (see link to file above) 170 | mkvirtualenv3 project_name 171 | ``` 172 | 173 | 174 | #### Django completion 175 | 176 | Add autocompletion in terminal when we type `manage.py` or `django-admin.py` and press `` button two times. 177 | 178 | - `cd /usr/local/etc/bash_completion.d/` 179 | - `wget https://raw.github.com/django/django/master/extras/django_bash_completion` 180 | - `source ~/.profile` to affect changes 181 | 182 | 183 | ## Post-installation 184 | 185 | - create virtual environments for projects `mkvirtualenv [env_name]` and run `pip install -r requirements.txt` 186 | - restore MySQL/Postgres/MongoDB databases 187 | - mongodb: `mongodump --out backup/` -> `mongorestore backup/` 188 | 189 | 190 | ## Useful software 191 | 192 | This is my list of sofrware that I use: 193 | 194 | ### Source code editor 195 | 196 | I use **Visual Studio Code** and you can read [how to configure VS Code on macOS for Python dev](VSCode.md). 197 | 198 | In the past I've used [Sublime Text 3](http://www.sublimetext.com/3) and tried [Atom](ATOM.md). 199 | 200 | ### Development tools 201 | 202 | - [GitHub Desktop](https://desktop.github.com) - GUI for git repos. In the past I also used [SourceTree](http://www.sourcetreeapp.com) 203 | - [MySQL Workbench](http://dev.mysql.com/downloads/workbench/). Also I use [Postico](https://eggerapps.at/postico/) for Postgres 204 | - [Docker](https://docs.docker.com/docker-for-mac/docker-toolbox/) 205 | 206 | ### Other software 207 | 208 | - From **App Store**: Pages, Numbers, Keynote, Pixelmator, Graphic, 1Password, The Unarchiver, Pocket 209 | - [DropBox](https://www.dropbox.com) 210 | - [Skype](http://www.skype.com) 211 | - [Google Chrome](http://www.google.com/chrome) 212 | - [VirtualBox](https://www.virtualbox.org) 213 | - [TunnelBlick](https://code.google.com/p/tunnelblick/) - graphical OpenVPN for Mac 214 | - [Team Viewer](http://www.teamviewer.com/en/index.aspx) - share your screen 215 | - [XMind](http://www.xmind.net) - save your minds in graphical representation 216 | - [VLC Video Player](http://www.videolan.org/vlc/download-macosx.html) 217 | 218 | 219 | ## Login to web services on macOS 220 | 221 | - Login to [google.com](http://google.com) and auto-setup macOS to work with: mail, calendar, etc 222 | - Login to [facebook](http://facebook.com), [twitter](http://twitter.com) and [linkedin](http://linkedin.com) and allow auto-setup on macOS 223 | 224 | 225 | ## Read more 226 | 227 | - [How To Setup Ubuntu Web Server](https://github.com/1st/setup-web-server) 228 | -------------------------------------------------------------------------------- /VSCode.md: -------------------------------------------------------------------------------- 1 | # VS Code for Python on macOS 2 | 3 | Here I will describe how do I use **VS Code** in my daily work for **Python web development on macOS**. 4 | 5 | ## Install VS Code 6 | 7 | Download and install VS Code from [code.visualstudio.com](https://code.visualstudio.com) and then follow 8 | instructions below about how to configure it to be really useful for you. 9 | 10 | ## Install extensions 11 | 12 | - [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) - adds features such as IntelliSense, linting, debugging, code navigation, code formatting, Jupyter notebook support, refactoring, variable explorer, test explorer, snippets, and more! 13 | - [Project Manager](https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager) - must have extension to have fully functional projects. When you open a project - all opened files are restored too, like you want 14 | - [GitHub Pull Requests and Issues](https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github) allows you to work with PRs within the VS Code. No need to open web browser anymore! 15 | - [Prettify JSON](https://marketplace.visualstudio.com/items?itemName=mohsen1.prettify-json) - make a one-line unreadable JSON to be formatted for human. Just open command palette and select `Prettify JSON` command - it will do the magic for the currently open file 16 | - [Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker) - checks your Python and Markdown files on typos. Nice to have 17 | - [Docker](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) - makes it easy to build, manage and deploy containerized applications from Visual Studio Code 18 | - [DotENV](https://marketplace.visualstudio.com/items?itemName=mikestead.dotenv) - VSCode `.env` file syntax highlighting 19 | 20 | ## How to use Visual Studio Code 21 | 22 | The main feature that you need to use again and again is the **Command Palette** that is open with `⇧ ⌘ P` combination. 23 | In the *Command Palette* you can do almost anything: open a project, transform selection to upper-case, prettify JSON, etc. 24 | 25 | Before the first use, I recommend to read [Visual Studio Code: User Interface](https://code.visualstudio.com/docs/getstarted/userinterface). 26 | 27 | ## Configure VS Code for Python 28 | 29 | ### Basic setup of the editor 30 | 31 | Here we will do next adjustments: 32 | - [x] set text size to be more comfortable for your eyes 33 | - [x] add ruler to show `80` and `100` characters border 34 | - [x] wrap long lines of text to be limited by `99` characters. It especially useful in Markdown files 35 | - [x] set python linter rules to notify you about long lines of code 36 | 37 | Click on Cog Wheel and then click on the Settings option. Then click on the `Open Settings (JSON)` icon 38 | on the top right side of the window. 39 | 40 | Change `User` settings to: 41 | ```js 42 | { 43 | "workbench.startupEditor": "newUntitledFile", 44 | "editor.fontSize": 14, 45 | "editor.wordWrap": "wordWrapColumn", 46 | "editor.wordWrapColumn": 80, 47 | "editor.rulers": [ 48 | 80, 49 | 100 50 | ], 51 | "git.confirmSync": false, 52 | "git.autofetch": true, 53 | "files.trimTrailingWhitespace": true, 54 | "explorer.confirmDragAndDrop": false, 55 | "python.venvPath": "~/.virtualenvs", 56 | "python.venvFolders": [ 57 | "~/.virtualenvs" 58 | ], 59 | "python.linting.pycodestyleEnabled": true, 60 | "python.linting.pycodestyleArgs": [ 61 | "--max-line-length=99" 62 | ], 63 | "terminal.integrated.fontSize": 14, 64 | "window.zoomLevel": 0, 65 | "[markdown]": { 66 | "editor.wordWrap": "wordWrapColumn", 67 | "editor.quickSuggestions": false 68 | }, 69 | // Sort imports on each file save. Do `pip install isort` to make it working 70 | "[python]": { 71 | "editor.codeActionsOnSave": { 72 | "source.organizeImports": true 73 | } 74 | }, 75 | // Settings to be passed to the isort. All options are: https://pycqa.github.io/isort/docs/configuration/options.html 76 | "python.sortImports.args": [ 77 | // In case if you use one import per line 78 | "--force-single-line-imports", 79 | "--atomic", 80 | "--line-length", "100", 81 | // In case if you have some folder that needs to be recognized as "local" one, but it's a symlink for example 82 | "--project", "common", 83 | ] 84 | } 85 | ``` 86 | 87 | Change `Workspace` settings to *(but replace `project-name` to your virtual env name)*: 88 | ```js 89 | { 90 | "python.pythonPath": "~/.virtualenvs/project-name/bin/python", 91 | "python.testing.unittestArgs": [ 92 | "-v", 93 | "-s", 94 | "./src", 95 | "-p", 96 | "test_*.py" 97 | ], 98 | "python.testing.pytestEnabled": false, 99 | "python.testing.nosetestsEnabled": false, 100 | "python.testing.unittestEnabled": true 101 | } 102 | ``` 103 | 104 | ### Debug code 105 | 106 | You can debug code of the running web app, your celery task worker or even you can run unit tests with debug enabled. 107 | 108 | Create a file in your project's folder `.vscode/launch.json` and change it's content to: 109 | ```js 110 | { 111 | // Use IntelliSense to learn about possible attributes. 112 | // Hover to view descriptions of existing attributes. 113 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 114 | "version": "0.2.0", 115 | "configurations": [ 116 | { 117 | "name": "Django", 118 | "type": "python", 119 | "request": "launch", 120 | "program": "${workspaceFolder}/src/manage.py", 121 | "args": [ 122 | "runserver", 123 | "8077", 124 | "--noreload" 125 | ], 126 | "django": true, 127 | "env": { 128 | "ENV_NAME": "development", 129 | }, 130 | // To debug external libs (e.g. django) - set to "false" 131 | "justMyCode": false, 132 | "cwd": "${workspaceFolder}/src" 133 | }, 134 | { 135 | "name": "Celery", 136 | "type": "python", 137 | "request": "launch", 138 | "module": "celery", 139 | "args": [ 140 | "-A", 141 | "project-name", 142 | "worker", 143 | "-l", 144 | "info", 145 | "-P", 146 | "solo" 147 | ], 148 | "django": true, 149 | "env": { 150 | "ENV_NAME": "development", 151 | }, 152 | "cwd": "${workspaceFolder}/src" 153 | }, 154 | { 155 | "name": "Tests", 156 | "type": "python", 157 | "request": "launch", 158 | "program": "${workspaceFolder}/src/manage.py", 159 | "args": [ 160 | "test", 161 | 162 | // To test only one app - specify it's name below: 163 | // "app-name", 164 | 165 | // We can keep DB between runs 166 | // "--keepdb", 167 | 168 | // And can stop when we find the first failing test, instead of waiting for all tests to be finished 169 | // "--failfast", 170 | 171 | // Use it always, it will answer "yes" to all prompts, like to destroy DB before each test run 172 | "--noinput" 173 | ], 174 | "django": true, 175 | "env": { 176 | "ENV_NAME": "testing", 177 | }, 178 | "cwd": "${workspaceFolder}/src" 179 | } 180 | ] 181 | } 182 | ``` 183 | 184 | Now click on the `Run` (Debug) icon on the left side of the VS Code window. And now you can run Django web server, Celery worker or unit tests in debug mode. 185 | 186 | ## Problems and solutions 187 | 188 | ### `Cmd + T` shows nothing 189 | 190 | When you try to `Go To Symbol in workspace` command, or just press `Cmd + T` - the empty list appear *(with just a message `No symbols matching`)*. 191 | 192 | To fix this problem, you could open the `Settings` menu and find `Jedi` there *(using the search bar on the top)*. Then uncheck option for `Python: Jedi Enabled` and restart the VS Code. Next time when you will press `Cmd + T` it will index all your files *(it will take a while)* and the list of all symbols across the workspace will appear in the list. 193 | --------------------------------------------------------------------------------