Trouble with VirtualEnv on Windows

602 views
Skip to first unread message

Joshua Russo

unread,
Oct 14, 2012, 6:25:41 PM10/14/12
to django...@googlegroups.com
This is probably a VirturalEnv problem as opposed to a Django problem but I was wondering if someone here could point me in the right direction.

I'm trying to setup clean environment for a demonstration of Django on Tuesday but I get the following when I try to setup the project within the virtual environment. You can see that if I just run python from within the virtual environment I do have access to the libraries, but if I try to use the django-admin.py script, the libraries aren't found. Any thoughts?

(django-tutorial) C:\dev\venv\django-tutorial>Scripts\django-admin.py startproject testsite
Traceback (most recent call last):
  File "C:\dev\venv\django-tutorial\Scripts\django-admin.py", line 2, in <module>
    from django.core import management
ImportError: No module named django.core

(django-tutorial) C:\dev\venv\django-tutorial>C:\dev\venv\django-tutorial\Script
s\python.exe
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core import management
>>> management
<module 'django.core.management' from 'C:\dev\venv\django-tutorial\lib\site-pack
ages\django\core\management\__init__.pyc'>
>>>

Joshua Russo

unread,
Oct 14, 2012, 10:45:55 PM10/14/12
to django...@googlegroups.com
I suppose I was a little light on the details of how I setup the environment. I don't often setup a new environment from scratch so I used this post as the basis: http://slacy.com/blog/2011/06/django-postgresql-virtualenv-development-setup-for-windows-7/ 

The versions of each program I used / ended up with were:
   Python 2.7.3 (32 bit)
   Postgres 9.2 (32 bit)
   Setuptools 0.6c11 for Python 2.7 
   Psycopg2 2.4.5 for Python 2.7 (32 bit)
   VirtualEnv 1.8.2
   Django 1.4.1

Jani Tiainen

unread,
Oct 15, 2012, 12:55:55 AM10/15/12
to django...@googlegroups.com
Because the setup procedure used there is faulty.

This is what happens:

When installing Python install package will bind .PY(C) file execution
to use _always_ main installation. It won't follow any path settings
which virtualenv relies on.

I'm not sure can you even overcome that restriction easily on cmd. I
know that powershell can do it (don't know how though) or personally I
use TCC/LE.

Also psycopg2 is installed on main installation and virtualenv created
with --no-site-packages should disable it from virtualenv.

This is the battle tested procedure how I do set up my environment:

http://djangonautlostinspace.wordpress.com/2012/04/16/django-and-windows/
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/YuSLHUyt6xIJ.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.


--
Jani Tiainen

- Well planned is half done and a half done has been sufficient before...

Joshua Russo

unread,
Oct 15, 2012, 8:07:47 AM10/15/12
to django...@googlegroups.com
Sweet! Thank you!

Frank Bieniek

unread,
Oct 15, 2012, 2:00:59 AM10/15/12
to django...@googlegroups.com
Hi,

do a "pip freeze" after you have activated your environment,
this way you see the packages that are visible to the python interpreter inside your virtual env.

Possible Problem
You have installed all packaged before you created the virtual env.
-> virtual env shows no components.
pip install componentname should solve the problem.

or:
Windows reads the registry for some packages (mainly none native packages) and
inside the virutual env this does not work.
Try to recreate the virtualenv with --system-site-packages option set.

another solution - use vagrant: - google for djangocon 2012 vagrant

Thanks
Frank
--

Jani Tiainen

unread,
Oct 16, 2012, 12:46:41 AM10/16/12
to django...@googlegroups.com
Hi,

Don't forget "yolk". Very powerful tool to display virtualenv contents
in readable format. You can install it with pip install yolk.
Reply all
Reply to author
Forward
0 new messages