Dreamhost 是小型项目的绝佳主机。它也是 Django 友好的托管。除了 python 和 Django 版本之外,所有的好东西都有点过时了。好吧,弄清楚如何在 Dreamhost 上更新 Python 2.7.3、Django 1.4 是一整天的工作,我真的很想与找到它的人分享
问问题
6572 次
2 回答
48
我目前有私人服务器、一个 shell 帐户和一点运气。所以这就是我所做的:
SSH 到您的主机以升级 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
配置系统以使用我们的新 Python。打开 ~/.bashrc 并添加以下行
export PATH="$HOME/Python27/bin:$PATH" export LD_LIBRARY_PATH=$HOME/Python27/lib #save it and run source ~/.bashrc
你现在可以检查你的python版本
which python
安装
easy_install
,pip
cd ~/tmp wget http://peak.telecommunity.com/dist/ez_setup.py python ez_setup.py easy_install pip # Or even shorter wget https://bootstrap.pypa.io/get-pip.py python get-pip.py
安装
virtualenv
pip install virtualenv virtualenv $HOME/<site>/env #Switch to virtualenv source $HOME/<site>/env/bin/activate
您还可以将环境路径添加到
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/<site>/env/bin/django-admin.py startproject project
passenger_wsgi.py
使用HOME/<site>/
以下内容创建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/<site>/env/bin/python", "python2.7.3", *sys.argv) sys.path.insert(0,'$HOME/<site>/env/bin') sys.path.insert(0,'$HOME/<site>/env/lib/python2.7/site-packages/django') sys.path.insert(0,'$HOME/<site>/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, os
BASE_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 path
PYTHON_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,请将最后两行替换为
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
- 享受 :D
Dreamhost 上的新版本 python 将不再返回sys.executable
所以你这是我的乘客wsgi版本
import sys, os
VIRTUAL_ENV_PYTHON = 'venv-python' # Python > 2.7.6 dreamhost not return sys.executable
BASE_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 False
sys.path.append(os.path.join(BASE_DIR)) #You must add your project here or 500
#Switch to new python
PYTHON_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'
))
于 2012-06-08T17:52:24.337 回答
1
目前 Dreamhost 将服务器更新为 Ubuntu 12.04,但出现错误:
Import Error: <path-to-python>/_io.so undefined symbol: PyUnicodeUCS2_Decode
在编译自定义 python 并运行“python ez_setup.py”之后
解决方案是在第 1 步使用 --enable-unicode=ucs4 编译 python
./configure --enable-shared --prefix=$HOME/Python27 --enable-unicode=ucs4
于 2014-10-13T10:07:37.477 回答