Install django1.7 with Python 3.4 using virtualenv

旧城冷巷雨未停 提交于 2019-12-18 11:30:16

问题


I have hit a bit of a brick wall regarding the set up of django 1.7 using a virtualenv configured to Python 3.4.

I have created a Python 3.4 virtualenv using:

sudo virtualenv --no-site-packages -p /usr/bin/python3.4 venv

I have then activated the env using:

source venv/bin/activate

Once in the activated virtualenv i have tried:

sudo pip install https://www.djangoproject.com/download/1.7b1/tarball/

This installs django in the Python 2.7 directory and not in the virtual environment.. Checking with pip freeze shows no installed packages

I have tried downloading the zip for django 1.7 and using python setup.py install within the environment but still get the install occurring outside of the env and in the 2.7 directory..

Any advice or pointers on what i'm doing wrong would be really appreciated!!


回答1:


sudo is unnecessary when creating a virtualenv and when installing with pip inside a virtualenv. Try the following instead:

$ virtualenv -p /usr/bin/python3.4 venv

$ source venv/bin/activate

(At this point, you can check that your virtualenv is active and using python 3.4 with which python, which should print something like /home/user/projects/venv/bin/python, and python --version, which should print Python 3.4.x)

$ pip install https://www.djangoproject.com/download/1.7b1/tarball/




回答2:


I think the problem is sudo. The point of virtualenv is that you should not have to run anything as root -- virtualenv will set up an environment in which you can install packages as a user. I imagine the issue is either that pip is assuming your use of sudo suggests that you want to install the package in the system package directory... or else that sudo itself is overriding the virtualenv changes to your environment in favor of root's default environment.

Create a new virtualenv without sudo. Then activate it and run pip install without sudo.




回答3:


try following

virtualenv --no-site-packages --distribute -p /usr/bin/python3 ~/.virtualenvs/py3

workon py3

pip install Django==1.7.4


来源:https://stackoverflow.com/questions/23256054/install-django1-7-with-python-3-4-using-virtualenv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!