在Dreamhost上使用virtualenv更新新的Django和Python 2.7。*(帶乘客)
我目前有私人服務(wù)器,一個(gè)外殼帳戶和一點(diǎn)運(yùn)氣。所以這是我的工作:
SSH到您的主機(jī)以升級(jí)python
cd ~
mkdir tmp cd tmp wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz tar zxvf Python-2.7.3.tgz cd Python-2.7.3 ./configure –enable-shared –prefix=$HOME/Python27 –enable-unicode=ucs4 make make install
配置系統(tǒng)以使用我們的新Python。打開?/ .bashrc并添加以下行
export PATH='$HOME/Python27/bin:$PATH'
export LD_LIBRARY_PATH=$HOME/Python27/lib
#save it and run source ~/.bashrc
您現(xiàn)在可以使用檢查您的python版本 which python
安裝easy_install,pip
cd ~/tmp
wget http://peak.telecommunity.com/dist/ez_setup.pypython ez_setup.pyeasy_install pip
Or even shorterwget https://bootstrap.pypa.io/get-pip.pypython get-pip.py
安裝 virtualenv
pip install virtualenv
virtualenv $HOME//env #Switch to virtualenv source $HOME//env/bin/activate
您還可以將env路徑添加到 bashrc
export PATH='$HOME/<site>/env/bin/:$PATH' source ~/.bashrc
安裝Django和其他所有東西
pip install django
pip install .... pip install .... pip install ....
建立專案
cd $HOME/<site>/
python $HOME//env/bin/django-admin.py startproject project
創(chuàng)建passenger_wsgi.py于HOME/<site>/與下列內(nèi)容
import sys, os
cwd = os.getcwd() sys.path.append(cwd) sys.path.append(cwd + ‘/project’) #You must add your project here or 500
#Switch to new python #You may try to replace $HOME with your actual path if sys.version < “2.7.3”: os.execl(“$HOME//env/bin/python”, “python2.7.3”, *sys.argv)
sys.path.insert(0,’$HOME//env/bin’) sys.path.insert(0,’$HOME//env/lib/python2.7/site-packages/django’) sys.path.insert(0,’$HOME//env/lib/python2.7/site-packages’)
os.environ[‘DJANGO_SETTINGS_MODULE’] = “project.settings” import django.core.handlers.wsgi application = django.core.handlers.wsgi.WsgiHandler()
或者這樣
import sys, osBASE_DIR = os.path.dirname(os.path.abspath(__file__))sys.path.append(os.path.join(BASE_DIR)) #You must add your project here or 500#Switch to new python#You may try to replace $HOME with your actual pathPYTHON_PATH = os.path.join(BASE_DIR, ’env’, ’bin’, ’python’)if sys.executable != PYTHON_PATH: os.execl(PYTHON_PATH, 'python2.7.12', *sys.argv)
如果您使用的是django 1.7,請(qǐng)將最后兩行替換為
from django.core.wsgi import get_wsgi_applicationapplication = get_wsgi_application()享受:D
Dreamhost上的新版本python將不再返回,sys.executable因此您這是我的passenger_wsgi版本
import sys, osVIRTUAL_ENV_PYTHON = ’venv-python’ # Python > 2.7.6 dreamhost not return sys.executableBASE_DIR = os.path.dirname(os.path.abspath(__file__))def is_venv_python(): if len(sys.argv) > 0:last_item = sys.argv[len(sys.argv)-1]if last_item == VIRTUAL_ENV_PYTHON: return True return Falsesys.path.append(os.path.join(BASE_DIR)) #You must add your project here or 500#Switch to new pythonPYTHON_PATH = os.path.join(BASE_DIR, ’env’, ’bin’, ’python’)if not is_venv_python(): os.execl(PYTHON_PATH, 'python2.7.12', *sys.argv + [VIRTUAL_ENV_PYTHON])sys.path.insert(0, os.path.join(BASE_DIR, ’env’, ’bin’))sys.path.insert(0, os.path.join( BASE_DIR, ’env’, ’lib’, ’python2.7’, ’site-packages’))解決方法
Dreamhost是小型項(xiàng)目的理想主機(jī)。而且它也是Django友好的托管。除python和Django版本外,其他所有功能都過時(shí)了。好吧,這是一整天的工作,要弄清楚如何在dreamhost上更新Python2.7.3,Django 1.4,我真的想與任何發(fā)現(xiàn)它的人分享
相關(guān)文章:
1. msxml3.dll 錯(cuò)誤 800c0019 系統(tǒng)錯(cuò)誤:-2146697191解決方法2. WMLScript的語(yǔ)法基礎(chǔ)3. ASP中解決“對(duì)象關(guān)閉時(shí),不允許操作。”的詭異問題……4. 解決ASP中http狀態(tài)跳轉(zhuǎn)返回錯(cuò)誤頁(yè)的問題5. html小技巧之td,div標(biāo)簽里內(nèi)容不換行6. xml中的空格之完全解說7. XML入門的常見問題(四)8. 無線標(biāo)記語(yǔ)言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁(yè)9. ASP中if語(yǔ)句、select 、while循環(huán)的使用方法10. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享
