user3199840
user3199840

Reputation: 535

Django-admin creates wrong django version inside virtualenv

I've created a n new directory, a virtualenv and installed a django-toolbelt inside it. The django-version should be 1.8 but when I call 'django-admin.py version' it says 1.6. So when I start a new project it creates a 1.6. I thought virtualenv was supposed to prevent this. What am I doing wrong?

Edit: I think it has to do with the PATH (?). Like it's calling the wrong django-admin version. I'm on Windows 7. Still don't know how to fix it.

Upvotes: 1

Views: 2221

Answers (4)

A. S.
A. S.

Reputation: 89

I had the same problem. Could be related to your zsh/bash settings.

I realized that using zsh (my default) I would get django-admin version 1.11 despite the Django version was 2.1! When I tried the same thing with bash I would get django-admin version 2.1 (the correct version). Certainly a misconfiguration.

So, I strongly suggest you check your zsh or bash settings to check for paths you might have.

Upvotes: 0

aforwardz
aforwardz

Reputation: 3389

I came across this problem too. In the official document, I found that, in a virtual environment, if you use the command 'django-admin', it would search from PATH usually in '/usr/local/bin'(Linux) to find 'django-admin.py' which is a symlink to another version of django. This is the reason of what happened finally.

So there are two methods to solve this problem:

  1. re-symlink your current version django-admin(site-packages/django/bin/django-admin.py) to 'usr/local/bin/django-admin' or 'usr/local/bin/django-admin.py'
    REMIND: This is a kind of global way so that it will effects your other django projects, so I recommend the second method
  2. cd to your_virtual_env/lib/python3.x/site-packages/django/bin/(of course you should activate your virtual environment), and then use 'python django-admin.py startproject project_name project_full_path' to create django project

Upvotes: 3

geckon
geckon

Reputation: 8774

Try and install Django into the virtual environment as well:

pip install django

It should install the latest version, you can also specify a particular version (let's say 1.8.2) if you need to:

pip install django==1.8.2

Either way you'll have the correct version of Django in your virtual environment and it should work as you expect then.

You can also use the following command to see what version you have installed:

pip show django

Update:

It seems that you have the correct version installed in your virtual environment, but for some reason your Windows 7 use the system Django installation instead while you use manage.py or django-admin.py directly. However, you can use python manage.py or python django-admin.py instead, which seems to work as expected (and use the virtualenv Django installation).

Upvotes: 2

chandu
chandu

Reputation: 1063

Create a virtual environment for a project:

$ mkdir cd my_project_folder
$ cd my_project_folder 
$ virtualenv venv
$ source venv/bin/activate

And now install django

(venv) ~$ pip install django==1.8

manage.py runserver in virtualenv using wrong django version

pip / virtualenv / django installation issue

Upvotes: -1

Related Questions