1

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.

ferrangb
  • 2,012
  • 2
  • 20
  • 34
user3199840
  • 525
  • 2
  • 13
  • 35
  • You should install django inside that virtualenv. – GwynBleidD Aug 11 '15 at 10:50
  • 1
    It should be inside the folder venv\Lib\site-packages. And it looks like the correct version there. I activated the virtualenv before doing a pip install django-toolbelt. – user3199840 Aug 11 '15 at 10:57

4 Answers4

3

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
aforwardz
  • 3,109
  • 1
  • 10
  • 15
2

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).

geckon
  • 8,316
  • 4
  • 35
  • 59
  • It seems like it installed the correct version inside the virtualenv when i installed the django-toolbelt. But the django-admin command seems to go for my system wide 1.6 version instead. Or something. – user3199840 Aug 11 '15 at 11:00
  • Yes and I get "Requirement already satisfied". Should i try to upgrade instead? – user3199840 Aug 11 '15 at 11:09
  • @user3199840 You can try but if `pip show` tells you that you have 1.8.x installed then it probably won't help either. It's weird though. Do you have the virtualenv activated? – geckon Aug 11 '15 at 11:11
  • When inside the activated venv. Pip show django shows version 1.8.3. So guess thats means the version installed inside the venv is the correct version. – user3199840 Aug 11 '15 at 11:16
  • @user3199840 Then the question is why the wrong version is used instead. What does `python manage.py version` print? – geckon Aug 11 '15 at 11:29
  • It seems to give me the correct version when doing "python django-admin.py version" instead of just "django-admin.py version". I think there might be something with the PATH. – user3199840 Aug 11 '15 at 11:35
  • Windows 7. I've tried with a newer version of virtualenv and the with "--no-site-packages"-command when creating it. But it did'nt make any difference. – user3199840 Aug 11 '15 at 12:04
  • It seems that Win7 behave somewhat strange there. I don't have Win here so I can't verify that. I'm quite sure that on Linux it should work though. Can you use `python manage.py/django-admin.py` instead of just `manage.py/django-admin.py`? – geckon Aug 11 '15 at 12:18
  • Yes, I can use it like that if I'm in the directory where the django-admin.py file is. And call it with "python django-admin.py". It feels like it's going to be problematic when starting new projects and apps. – user3199840 Aug 11 '15 at 12:42
  • 1
    Well, starting new apps is as simple a creating a new folder with an empty `__init__.py` inside and adding it to `settings.INSTALLED_APPS`, you really don't need `django-admin` for that. – spectras Aug 11 '15 at 16:57
0

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.

A. S.
  • 81
  • 8
-1

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

Community
  • 1
  • 1
chandu
  • 1,053
  • 9
  • 18
  • This is what I did but with pip install django-toolbelt at the end instead and I'm pretty sure it should install Django 1.8 as part of it. – user3199840 Aug 11 '15 at 11:12
  • 1
    http://stackoverflow.com/questions/17098092/manage-py-runserver-in-virtualenv-using-wrong-django-version – chandu Aug 11 '15 at 11:23
  • 1
    http://stackoverflow.com/questions/7976089/pip-virtualenv-django-installation-issue – chandu Aug 11 '15 at 11:25
  • Yey! It seems like there is something with the path. Because when I call 'python django-admin.py version' and not just 'django-admin.py version' it gives me the correct version. – user3199840 Aug 11 '15 at 11:31