Skip to content

Instantly share code, notes, and snippets.

@yonchu
Created November 25, 2012 18:32
Show Gist options
  • Save yonchu/4144711 to your computer and use it in GitHub Desktop.
Save yonchu/4144711 to your computer and use it in GitHub Desktop.
pythonのsite-packagesディレクトリへ移動(cd)
# Add the following function to ~/.bashrc or ~/.zshrc
function cdsite() {
local py_cmd
py_cmd=`cat << 'EOF'
from __future__ import print_function
import sys
import os
import site
site_prefix = site.PREFIXES[0]
version = str(sys.version_info[0]) + '.' + str(sys.version_info[1])
site_path = os.path.join(site_prefix, 'lib/python' + version, 'site-packages')
print(site_path)
EOF`
local site_path=$(python -c "$py_cmd")
[ -d "$site_path" ] || return 1
echo "$site_path"
cd "$site_path"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment