frankjonen

My Python Setup (macOS Mojave and up)

Jun 3rd, 2020
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.77 KB | None | 0 0
  1. # My setup to make learning Python easier
  2.  
  3. #   First we get the most recent Python version.
  4. #   As of this writing, that's 3.8
  5.  
  6. #   If you don't use Homebrew yet, now's a good time to fix that.
  7. #   Open Terminal and go like this:
  8.  
  9. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  10.  
  11.  
  12. #   Done?
  13. #   Now do:
  14.  
  15. brew install python@3.8
  16.  
  17.  
  18. #    Let's get us a decent Vim for the Desktop
  19.  
  20. brew install macvim
  21. #   brew installed apps cannot be seen by Spotlight, so you can't use
  22. #   that to launch these apps. Here's a workaround:
  23. #   Create an Automator app that runs this shell script
  24. #   open /usr/local/opt/macvim/MacVim.app $@
  25.  
  26. #   Or just get it readymade with Spotlight launchability from here
  27. #   https://macvim-dev.github.io/macvim/
  28. #   Difference? The brew version only has Python3 built-in (:py3 commands).
  29.  
  30.  
  31. #   Cleanup and set it up
  32.  
  33. brew cleanup
  34.  
  35.  
  36. #   Brewage is done, now we set our system up to have BOTH,
  37. #   the legacy Python many macOS apps need to function and the
  38. #   current one that we want to learn. Without screwing up either.
  39.  
  40. #   Put this in your .bash_profile
  41.  
  42. export PYTHONPATH=/usr/local/opt/python@3.8/bin
  43. export LDFLAGS="-L/usr/local/opt/python@3.8/lib"
  44. export PKG_CONFIG_PATH="/usr/local/opt/python@3.8/lib/pkgconfig"
  45.  
  46. export PATH=$PATH:$PYTHONPATH
  47.  
  48.  
  49. #   PIP for us is now PIP3 and the PYTHON command is now PYTHON3
  50. #   Test it by typing PYTHON -V and PYTHON3 -V
  51. #   If everything went correctly, you now have both versions available to you.
  52.  
  53.  
  54. #   Brew's MacVim is here: /usr/local/Cellar/macvim/[the version number]/MacVim.app
  55. #   Double click that or type "open MacVim.app" and once launched, drag the icon
  56. #   where you want it in your Dock
  57.  
  58. #   The easiest way to run your Python script in Vim is via
  59.  
  60. :!python3 %
  61.  
  62. #   The '%' part is your current buffer. You can set this up as a key-binding for
  63. #   running your code with one key-press.
  64.  
  65. # That's basically it. Now you can wander off and customise the rest to your heart's content.
Add Comment
Please, Sign In to add comment