Linux
嘗試使用 virtualenv Django 1.4.1
我在伺服器上有 Django 1.2.1。我需要使用虛擬 Python 來安裝 Django 1.4.1 和我想要的 PostgreSQL 適配器。我正在嘗試在我的伺服器上設置此軟體。所以我跑
virtualenv --python=python2.6 env . env/bin/activate pip install -r requirements.txt
輸出
:~/arkisto$ virtualenv --python=python2.6 env Running virtualenv with interpreter /usr/bin/python2.6 New python executable in env/bin/python2.6 Also creating executable in env/bin/python Installing distribute..................................................................................................................................................................................done. :~/arkisto$ . env/bin/activate (env):~/arkisto$ pip install -r requirements.txt Requirement already satisfied (use --upgrade to upgrade): psycopg2 in /usr/lib/python2.6/dist-packages (from -r requirements.txt (line 2)) Downloading/unpacking django==1.4.1 (from -r requirements.txt (line 1)) Downloading Django-1.4.1.tar.gz (7.7Mb): 7.7Mb downloaded Running setup.py egg_info for package django Installing collected packages: django Found existing installation: Django 1.2.3 Not uninstalling Django at /usr/lib/pymodules/python2.6, outside environment /home/users/sa/tentti/env Running setup.py install for django changing mode of build/scripts-2.6/django-admin.py from 644 to 755 changing mode of /home/users/sa/arkisto/env/bin/django-admin.py to 755 Successfully installed django Cleaning up...
然後在伺服器中查看 Django 的版本
(env)$ django-admin --version 1.2.3
您如何使用這些命令安裝的軟體?
在 virtualenv 中通過 pip 安裝時,django 管理腳本通常安裝在名稱下
django-admin.py
(帶有文件副檔名)。很可能係統範圍的 django 安裝了這個腳本而沒有擴展,所以你回退到它。嘗試
$ django-admin.py --version
根據您的 virtualenv 版本,您可能需要在創建 venv 時添加 –no-site-packages 標誌,如下所示:
virtualenv --python=python2.6 --no-site-packages env
這會告訴 virtualenv 不要讓全域安裝的包在你的 venv 中可用。