Forums

Can't upgrade Django within virtualenv

My virtualenv is currently using Django 1.6.6 and I'm trying to upgrade to Django 1.7. However, pip3 install -U django results in PermissionError: [Errno 13] Permission denied: '/usr/local/bin/django-admin.py', which occurs after pip tries to uninstall the current Django installation (1.6.6). The same thing happens when I try to manually uninstall Django from the virtualenv. How do I upgrade? At this point the only thing I can think of is to create a new virtualenv to upgrade to 1.7, but that doesn't seem like an ideal solution at all.

So I can upgrade if I do pip install -U django but not 'pip3 install -U python'. My code is written in Python3 though, so I need to update its version of Django.

Ah! I was just playing around to see what's going on and your second post gave me the clue I needed. pip3 is not installed into the virtualenv, it's the version that is installed on PythonAnywhere, so it's trying to downgrade the Django that is installed for everyone. The pip executable that you run when you've activated a virtualenv is specific to the version of Python that you specified when you created the virtualenv (with the --python argument), so you don't need to specify pip3, because that's already built-in (assuming you created the virtualenv correctly).

I'll try making a virtualenv with the python3 executable specified. Thanks for the quick response!

I'm having trouble pointing to the python3 executable in usr/lib/ because I have insufficient permissions. What is the best way to do this?

Here's a log of my session that successfully installed Django 1.6 and the upgraded to 1.7:

14:25 ~ $ mkvirtualenv django-upgrade --python=`which python3.3`                                                                                            
Running virtualenv with interpreter /usr/bin/python3.3
Using base prefix '/usr'
New python executable in django-upgrade/bin/python3.3
Also creating executable in django-upgrade/bin/python
Installing distribute.......................................................................................................................................
............................................................................................................................................................
............................................................................................................................................................
..................................................done.
Installing pip................done.
14:32 ~ $ workon django-upgrade
(django-upgrade)15:52 ~ $ pip install django==1.6
Downloading/unpacking django==1.6
  Downloading Django-1.6.tar.gz (6.6MB): 6.6MB downloaded
  Running setup.py egg_info for package django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
  Running setup.py install for django
    changing mode of build/scripts-3.3/django-admin.py from 664 to 775

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of /home/glenn/Envs/django-upgrade/bin/django-admin.py to 775
Successfully installed django
Cleaning up...
(django-upgrade)15:59 ~ $ pip install django==1.7                                                                                                           
Downloading/unpacking django==1.7
  Downloading Django-1.7.tar.gz (7.5MB): 7.5MB downloaded


  Running setup.py egg_info for package django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
  Found existing installation: Django 1.6
    Uninstalling Django:
      Successfully uninstalled Django
  Running setup.py install for django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of build/scripts-3.3/django-admin.py from 664 to 775
    changing mode of /home/glenn/Envs/django-upgrade/bin/django-admin.py to 775
    Installing django-admin script to /home/glenn/Envs/django-upgrade/bin
Successfully installed django
Cleaning up...
(django-upgrade)16:14 ~ $

I didn't know I could use 'which python3.3' to automatically fill in the interpreter path. This worked. Thanks!