[PYTHON] Avoiding the pitfalls of using a Mac (for Linux users?)

Good evening. I'm a Mac user.

I think the Mac is a nice machine, but I'm often addicted to using it without thinking. As the basic Unix environment is complete, especially for Linux users, there are subtle differences and strange behavior. It can be frustrating. In this entry, I'll summarize some of them that I'm addicted to and how to deal with them.

# 6/18 Added about virtualenv # 6/21 iterm edition added # 7/17 Added to MacVim edition

In addition, the tools I use

So, I mainly develop using Python. Also, I will omit the introduction of each tool and so on because there are many other articles.

homebrew edition

Googling and hitting the introductory script. In addition, since you can see options and useful advice for each formula, it may be good to add a habit of brew info frequently for the introduction package.

~ Homebrew edition finished ~

iTerm2

iTerm seems to be better, so I use iTerm. Please install from the official.

Disable vulnerable keys

Perhaps you are always launching the CUI. So ⌘ + w is an evil keybinding that can cause an outburst and hit the monitor. Let's erase it. From the menu, open Preference-> Keys. Add ⌘ + w or ⌘ + q to Global Shortcut Keys to make it ignore.

Enable meta key

On the Mac, you can put out incomprehensible symbols by hitting various keys together with Alt. Since the symbols rarely come into play during coding, we will make it possible to use it as a meta key. With this, you of emacser are also safe.

Open the settings you want to use with Preference-> Profiles. If you don't understand well, I think you should go to solarized and import the theme for iTerm2. Then open Keys and set Left option key acts as: to + Esc.

Let's restart the terminal. I think that it works like deleting a word with alt + d. You did it, did not you?

zsh edition

Since I have been made into a body that can not live without zsh, I will introduce zsh. However, Apple's standard zsh script under / etc does something wrong, so you have to do something about it.

You can either rewrite / etc / zshenv yourself or install it as brew install --disable-etcdir zsh. The above details are written carefully as it is with brew info zsh.

After the installation is completed, please refer to http://tukaikta.blog135.fc2.com/blog-entry-195.html and change the login shell.

Next, let's load the zsh completion functions. It can be installed with brew install zsh-completions. Next, set the fpath.

fpath = (
        #zsh-completions
        /usr/local/share/zsh-completions(N-/)

        #homebrew
        /usr/local/share/zsh/functions(N-/)
        )
export fpath

It looks like the above. If you are interested, use brew --prefix. In old entries etc., completion functions for brew etc. are brought in separately with symbolic links, but now there is a good one in zsh-completions, so it is useless.

Basic commands

The commands that come standard with MacOS seem to be derived from old BSD, and it is very stressful because the options are different and the behavior is strange, so let's replace them.

Let's introduce "openssl", "readline", "git", "coreutils", "gnu-sed", "wget", "gawk", "ctags", "sl".

It's coreutils I wrote above, but if you put it in normally, you'll need to type the command name prefixed with g. Set PATH and MANPATH by referring to brew info. Also, let's give priority to homebrew tools.


BREW_PATH=`/usr/local/bin/brew --prefix`
typeset -U path
path=(
    #Something like my own script or something I built myself
    $HOME/Dropbox/bin/mac(N-/)
    $HOME/Dropbox/bin(N-/)
    $HOME/bin(N-/)

    #Prioritize the introduction with homebrew
    $BREW_PATH/bin(N-/)

    ##Homebrew puts python and pip at the same time
    ##It goes into the PATH below, but regarding the command/usr/local/Automatically symbolic link to bin
    ##It seems that it is no longer necessary to add the following because it has come to be stretched. For more information brew info python
    #$BREW_PATH/share/python(N-/)

    #The default command is the GNU command
    $(brew --prefix coreutils)/libexec/gnubin(N-/)

    /usr/bin(N-/)
    /bin(N-/)
    #sbin
    /usr/local/sbin(N-/)
    /usr/sbin(N-/)
    /sbin(N-/)
    )
export path

alias sed='gsed'

Please do the first part as you like. For the time being, prioritizing coreutils should give you the same behavior and options as GNU's. Now the shell script that worked on Linux doesn't work! It won't happen (maybe)

tmux edition

Mac terminal emulators such as iTerm2 do not seem to work well with the clipboard on tmux. This creates a tragic situation where you are using Vim and with set clipboard = unnamed enabled, Vim on your device, including MacVim, can't paste at all.

Install reattach-to-user-namespace from brew to avoid the above.

Next, install the script to start tmux in cooperation with the above tools by referring to https://gist.github.com/elasticdog/1462391.

Finally,"tmux save-buffer - | reattach-to-user-namespace pbcopy"And"reattach-to-user-namespace pbpaste | tmux load-buffer - && tmux paste-buffer" It is also possible to link the tmux register with the clipboard by attaching such an operation to an appropriate binding of tmux.

Speaking of which, there are tmux that seems to be adjusted for iTerm, but I think that homebrew is good because it seems to be meaningless.

Python

Mac standard Python is not good, so let's use brew. Since I want to use openssl installed by homebrew, explicitly specify brew install python --with-brewed-openssl.

virtualenv

If you use virtualenv as it is, it will be awkward because the Mac default Python is prioritized.

First, make sure that homebrew's python and pip are prioritized by the PATH setting made in the basic command above. which python which pip

Next, put in virtualenv and virtualenvwrapper. I'm a man who uses pip.

After installation, write the following settings in .zprofile.

# --- virtualenv
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages --python=/usr/local/bin/python'
## virtualenv should use Distribute instead of legacy setuptools
#It seems that setuptools has been updated
#export VIRTUALENV_DISTRIBUTE=true
source /usr/local/bin/virtualenvwrapper.sh
#--- pip
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE = $HOME/.pip/cache

Originally, I feel that setting VIRTUALENVWRAPPER_PYTHON will do the trick, but for some reason I want to use standard python, so I set it explicitly with VIRTUALENVWRAPPER_VIRTUALENV_ARGS. By the way, my python combat power is farmer class, so if there is something wrong, please plunge into it.

After writing, let's reload the zsh settings.

Vim

You can build it yourself, but I'm not good at it, so I use brew. brew install vim --override-system-vi --with-lua --with-ruby --with-python --with-python3 Let's leave it as. Of course, lua, ruby and python3 are also introduced first. In particular, lua has been actively introduced recently, so it would be good to include it.

MacVim

Earlier MacVim had a crashing Python script, but with the latest version it works fine. Also, put in the best to benefit from ShougoWare's if_lua acceleration. brew install macvim --with-lua will do. Also, it seems that luajit is supported by the standard formula of brew, so if you want to include it, let's use --with-luajit.

Please refer to this blog for details. Latest patch & if_lua MacVim for fast search & completion!

Also, the binary of MacVim-Kaoriya has been updated with the binary with if_lua, so that may be fine.

Finally

I gave it as I wanted, so there may be additions and corrections in the future.

Recommended Posts

Avoiding the pitfalls of using a Mac (for Linux users?)
What Java users thought of using the Go language for a day
Can the F1C100s dream of embedded development for mediocre Linux users?
Impressions of using Flask for a month
A quick overview of the Linux kernel
A memo for utilizing the unit test mechanism KUnit of the Linux kernel
It's a Mac. What is the Linux command Linux?
How to access the contents of a Linux disk on a Mac (but read-only)
[AWS Lambda] Create a deployment package using the Docker image of Amazon Linux
Cut a part of the string using a Python slice
Create a QR code for the URL on Linux
A brief summary of Linux antivirus software for individuals
For Debian users who are having trouble with a bug in the Linux kernel 5.10
The story of creating a VIP channel for in-house chatwork
Reuse the behavior of the @property method by using a descriptor [16/100]
Try a similar search for Image Search using the Python SDK [Search]
Display the signal strength RSSI of a specific SSID (mac)
A rough summary of the differences between Windows and Linux
Mac Linux Check the capacity directly under a specific directory
A brief summary of Linux
The story of creating a database using the Google Analytics API
A memorandum of using eigen3
A memorandum of understanding for the Python package management tool ez_setup
A brief summary of Graphviz in python (explained only for mac)
How to get the printer driver for Oki Mac into Linux
On Linux, the time stamp of a file is a little past.
The story of making a standard driver for db with python.
How to output the output result of the Linux man command to a file
Check the memory protection of linux kerne with the code for ARM
Evaluate the performance of a simple regression model using LeaveOneOut cross-validation
Try using Elasticsearch as the foundation of a question answering system
Finding the optimum value of a function using a genetic algorithm (Part 1)
Host the network library Mirror for Unity on a Linux server
[Kaggle] I made a collection of questions using the Titanic tutorial
[Must-see for beginners] Basics of Linux
The story of writing a program
Display the signal strength RSSI of a specific SSID (raspberry pi (linux))
Randomly play the movie on ChromeCast for a certain period of time
Installation method using the pip command of the Python package (library) Mac environment
Latin learning for the purpose of writing a Latin sentence analysis program (Part 1)
The story of having a hard time introducing OpenCV with M1 MAC
Guidelines for reincarnating in the world of linux programming development (C / C ++ language)
[Linux] Command to get a list of commands executed in the past
View the full path (absolute path) of a file in a directory in Linux Bash
I measured the run queue wait time of a process on Linux
[Mac] Build a Python 3.x environment at the fastest speed using Docker
A note about the functions of the Linux standard library that handles time
Try using a Linux server as a backup destination for Time Machine (Ver. 2020)
Trial to judge the timing of the progress display of the for loop using 0b1111 ~
How to play a video while watching the number of frames (Mac)
A useful note when using Python for the first time in a while
Linux (for users and su / sudo commands)
[Understanding in 3 minutes] The beginning of Linux
Find the dates for a jarring tournament
A memorandum of using Python's input function
Measure the relevance strength of a crosstab
Create a graph using the Sympy module
Change the list in a for statement
Build a TOP screen for Django users
[Mac] Building a virtual environment for Python
Notes on using OpenCL on Linux on the RX6800