Is there a way to install django with pip to point to a specific python version in virtualenv

I have a system installed with CentOS. It currently runs python2.6, but python2.7 is also installed.

I want to run django 1.7 which is also installed. If I run django outside of virtualenv it uses python2.6 by default. I didn't install it myself.

What I'm guessing is a way to get around this to create a virtualenv. What I did and used --python = python2.7. But when I create virtualenv and install new django 1.7 in it (using pip) it still uses python2.6 instead of 2.7.

Since I am doing all this via ssh, I would like it to be easy (instead of compiling from source, etc.). Is there a way to tell django to use python2.7 when I install it with pip in virtualenv? Or a surefire way to fix this problem?

Here's what I did:

ssh.

$ mkdir project; cd project
$ virtualenv env --python=python2.7
$ cd env
$ source bin/activate
$ sudo easy_install-2.7 pip
$ pip install django==1.7

      

Then I go to my python interpreter. The interpreter has 2.7 working and if I import django everything works fine. But as soon as I run

django-admin.py start project project_name

it went back to using 2.6.

+3


source to share


2 answers


Call django-admin.py, like this one python django-admin.py

, in your activate virtualenv. Alternatively, you can do /path/to/virtualenv/bin/python django-admin.py

. The best solution is probably adding a shebang to django-admin.py which looks like #!/usr/bin/env python

which should use the python interpreter of your active virtualenv. See fooobar.com/questions/145465 / ...



+5


source


You can use pyenv , which will allow you to install the Python interpreter based on which directory you are in. I also use it with pyenv-virtualenv to get all the benefits of isolating my packages for each application.



There's a bit of a learning curve, but it's worth it if you need to switch Python interpreters to match, for example, a production server.

+1


source







All Articles