在Mac(Lion 10.7.4)上安装Django的开发环境MEMO
1:安装Xcode 4.3.2,而且必须安装Command Line Tools组件和PackageMaker
Command Line Tools: Preference -> Download -> Command Line Tools PackageMaker: Open Developer Tool -> More Developer Tools... 到官网去下载Auxiliary Tools for Xcode安装
2:安装MacPorts 参见 http://guide.macports.org/chunked/installing.html
3:安装下列基础软件:sudo port install [PACKAGE_NAME]
mysql55 mysql55-server python27 python25 py27-virtualenv py27-pip
4:MySQL Settings
* Settings $ cd /opt/local/bin/ $ sudo ln -s /opt/local/lib/mysql55/bin/mysql mysql $ sudo ln -s /opt/local/lib/mysql55/bin/mysql_config mysql_config $ sudo cp my.cnf /etc/ * initial db $ sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db * launch ** register $ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql55-server.plist ** stop $ sudo launchctl unload /Library/LaunchDaemons/org.macports.mysql55-server.plist ** start $ sudo launchctl load /Library/LaunchDaemons/org.macports.mysql55-server.plist
** set the password
/opt/local/lib/mysql55/bin/mysqladmin -u root password '111111'
其中my.cnf
# Example MySQL config file for small systems. # # This is for a system with little memory (<= 64M) where MySQL is only used # from time to time and it's important that the mysqld daemon # doesn't use much resources. # # You can copy this file to # /etc/my.cnf to set global options, # mysql-data-dir/my.cnf to set server-specific options (in this # installation this directory is /usr/local/mysql/data) or # ~/.my.cnf to set user-specific options. # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients [client] #password = your_password port = 3306 default-character-set = utf8 # Here follows entries for some specific programs # The MySQL server [mysqld] port = 3306 #skip-locking key_buffer_size = 16K max_allowed_packet = 1M table_open_cache = 4 sort_buffer_size = 64K read_buffer_size = 256K read_rnd_buffer_size = 256K net_buffer_length = 2K thread_stack = 128K default-storage-engine=InnoDB character_set_server=utf8 collation-server=utf8_general_ci ft_min_word_len=1 # Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows # (using the "enable-named-pipe" option) will render mysqld useless! # #skip-networking server-id = 1 # Uncomment the following if you want to log updates #log-bin=mysql-bin # binary logging format - mixed recommended #binlog_format=mixed # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = /usr/local/mysql/data/ #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = /usr/local/mysql/data/ # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M #innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 5M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M character_set_server=utf8 [mysql] no-auto-rehash default-character-set = utf8 # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M [mysqlhotcopy] interactive-timeout
5:Python Settings
# Set default python version to 2.7 $ sudo port select --set python python27 # Install virtualenvwrapper sudo pip-2.7 install virtualenvwrapper # Setup virtualenvwrapper $ sudo vi /etc/bashrc Add the following line and save: source $HOME/.bashrc $ vi ~/.bashrc Add the following lines and save: export WORKON_HOME=$HOME/.pyvirtualenvs export VIRTUALENVWRAPPER_PYTHON=/opt/local/bin/python2.7 source /opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenvwrapper.sh $ mkdir ~/.pyvirtualenvs # If /usr/local/bin/virtualenv already exists, switch to the new version $ cd /usr/local/bin/ $ sudo mv virtualenv virtualenv.old $ sudo ln -s /opt/local/bin/virtualenv-2.7 virtualenv
6:Python Development Enviroment Setup
如果安装完之后,升级了MySQL的话,需要重新安装Mysql-python,从而重新配置
# Python environment create mkvirtualenv --no-site-packages --python=/opt/local/bin/python2.7 your_env_name # Module install $ workon your_env_name # use pip_list file to install all dependency modules(Django, Mysql-python, python_memcached.....)
$ pip install -r pip_list
# Deactivate environment
$ deactivate
7:Redis Install
# redis install sudo port install redis # Register as a service (The below command registers redis w/ launchctl) sudo port load redis # Run server redis-server /opt/local/etc/redis.conf
8:Memcached Install
# memcached install sudo port install memcached # Register as a service (The below command registers memcached w/ launchctl) sudo port load memcached
9:Redis Python Libarary Install
# activate your_env_name work on your_env_name # install pip install redis