Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django 1.9a1 __init__.py is visible in eclipse/PyDev even though it should be deleted (Windows)

I'm having a strange behaviour here:

I just upgraded to Django 1.9.4 from Django 1.9a1 using pip. The installation went fine and Django was running smoothly, but during start up, it still showed the version number "1.9a1".

Just to make sure I uninstalled Django again using pip and confirmed that my django folders are no longer existing in C:\Program Files (x86)\Python 3.5\lib\site-packages (neither the "django" nor the "Django-1.9.4" folder).

After starting the server again, I was surprised to read the error message

from django.core.management import execute_from_command_line
File "C:\Program Files (x86)\Python 3.5\lib\site-packages\django\__init__.py", line 1, in <module>
from django.utils.version import get_version
ImportError: No module named 'django.utils'

I expected the error to be something like "package django not found" or similar. Since eclipse provides the file name as link, I clicked on it an eclipse opened a file with content

from django.utils.version import get_version
VERSION = (1, 9, 0, 'alpha', 1)
__version__ = get_version(VERSION)
[...]

I double-checked that this file is not available via command line and via windows explorer.

Where is this file located and how can I get rid of it? Or is it generated automatically (and if yes, how can I correct this mechanism)

Or am I missing something completely obvious?

Additional info: I re-installed Django 1.9.4 and init.py file located at C:\Program Files (x86)\Python 3.5\lib\site-packages\django__init__.py shows the correct version info. But still, if I run a Django project, the version info given is 1.9a1 .

Even when I open a cmd prompt and enter

python -c "import django; print(django.get_version())"

the answer is 1.9a1

Update 2016-03-13 17:57: I uninstalled again and used the explicit ==1.9.4 suggested by alecxe. This solved part of the problem: Now, if I open the command line,

python -c "import django; print(django.get_version())"

gives me the correct answer (1.9.4). But in Eclipse/PyDev, my project is no longer starting. The first error message is:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x03F72108>
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python 3.5\lib\site-packages\django\apps\config.py", line 118, in create
    cls = getattr(mod, cls_name)
AttributeError: module 'django.contrib' has no attribute 'admin'

Of course, the admin module is existing on the file system.

Just to check, I started a new project in the console using

django-admin startproject mysite

and the new project is sucessfully created.

When I use PyDev inside Eclipse to start a new project (using "new"/"PyDev Django Project"), the process fails! The project directory as well as manage.py are created, but the project directory is empty (no init.py, settings.py, urls.py, wsgi.py).

It seems like Eclipse/PyDev is not using the correct django installation, even though all file names given are the correct one. Is there maybe any caching involved? And yes, I re-started Eclipse after re-installation.

Additional Info 2016-03-14 17:44: I just re-started my computer and surprisingly, my eclips was now able to run my project again - the error described above disappearde, BUT the django version number displayed is 1.9a1 again! Now I fired up the command prompt and python -c "import django; print(django.get_version())" gave me 1.9a1 again, too! What I did next was to start the command prompt again as administrator and - tataa - I got a 1.9.4.

So the problem seems to be related to admin privileges which might be due to installing python in C:\Program Files (x86)\Python 3.5. I used the console window with admin rights for all pip installs / uninstalls described above. Is there some windows mechanism which could explain this behaviour?

Solution 2016-03-14 18:17: I now searched my whole C: drive for folders containing "django", and I found one in

C:\Users\[my_username]\AppData\Local\VirtualStore\Program Files (x86)\Python 3.5\Lib\site-packages\django

and - surprise surprise - it contained the init.py file with the wrong version number. So it seems like I installed the 1.9a1 without admin privileges and eclipse always used this version since it is started without admin privileges, too. After some research about Windows VirtualStore I decided to manually delete the whole C:\Users\[my_username]\AppData\Local\VirtualStore\Program Files (x86)\Python 3.5 folder.

Immediately after, my cmd-window showed me version 1.9.4, independent of admin- or non-admin-mode. And - most important - when I ran my django project in eclipse, it showed the correct version number, too. Just to be sure, I created a new django project using the PyDev wizard, and all project files were created correctly.

So in summary, the problem was due to a previous install of django without admin rights, followed by a django installation with admin rights. The responsible mechanism was the Windows VirtualStore, not Eclipse or PyDev.

I will leave the whole description of my Odyssee as is, maybe it helps someone to find the topic. I will give a short summary answer below.

like image 487
OBu Avatar asked Mar 10 '16 17:03

OBu


2 Answers

The long story is described above, the short answer is:

I had an additional installation of django in my C:\Users\[my_username]\AppData\Local\VirtualStore\Program Files (x86)\Python 3.5\Lib\site-packages\django folder. This was due to installing the 1.9a1 version without admin rights.

Since eclipse was accessing django without admin rights as well, it used the outdated version, and not the recent one which was installed usind pip with admin rigths.

I deleted the C:\Users\[my_username]\AppData\Local\VirtualStore\Program Files (x86)\Python 3.5 folder and after a restart of eclipse everything worked.

like image 127
OBu Avatar answered Nov 11 '22 16:11

OBu


What I remember helped me in a similar case was uninstalling Django completely and installing it over again:

pip uninstall django
pip install django==1.9.4

You may also need to check and manually remove django directory and the egg file if it is left in the C:\Program Files (x86)\Python 3.5\lib\site-packages directory after uninstalling django via pip.

like image 25
alecxe Avatar answered Nov 11 '22 15:11

alecxe