Wednesday, January 29, 2014

Re: virtualenv on Windows

Oops, my memory failed me. They don't work with pip, but they do work
with easy_install, which virtualenvs have as well (at least mine do).

http://stackoverflow.com/a/5442340/150999

For example,

easy_install C:\Users\sam\Downloads\Pygments-1.6.win-amd64-py2.7.exe



On 29 January 2014 16:27, Mike Dewhirst <miked@dewhirst.com.au> wrote:
> On 29/01/2014 2:23pm, Sam Lai wrote:
>>>
>>> However, even after downloading from that site they cannot be installed
>>> manually into a virtualenv! Only pip can do that.
>>
>>
>> You can install the packages from
>> http://www.lfd.uci.edu/~gohlke/pythonlibs/ by simply running -
>>
>> pip install <path to the .exe file>
>
>
> I did try that earlier but had no luck. Maybe I got the incantation wrong?
>
> (proj-x) C:\users\miked\env\proj-x>pip install
> C:\install_kits\python\postgresql\psycopg2-2.4.5.win32-py2.7.exe
>
> Exception:
> Traceback
> ...
> ValueError: ('Missing distribution spec',
> '\\install_kits\\python\\postgresql\\psycopg2-2.4.5.win32-py2.7.exe')
>
> Mike
>
>
>>
>> ... from inside your virtualenv. Those .exe files are pip-compatible
>> ZIP archives
>>
>> On 29 January 2014 13:56, Mike Dewhirst <miked@dewhirst.com.au> wrote:
>>>
>>> A little while ago I suggested to someone using Windows to implement
>>> virtualenv "later". So I thought I'd document my experience here.
>>>
>>> In summary, it probably works well if you have Visual Studio. The process
>>> outlined below shows a clumsy workaround if you don't.
>>>
>>> Hope it helps someone
>>>
>>> Mike
>>>
>>> - - - - - -
>>>
>>> $pip install virtualenv # first step (requires pip obviously)
>>>
>>> $mkdir c:\users\miked\env
>>>
>>> $virtualenv --no-site-packages c:\users\miked\env\proj-x
>>> New python executable in c:\users\miked\env\proj-x\Scripts\python.exe
>>> Installing setuptools, pip...done.
>>>
>>> Now copy your "myproject-x" into c:\users\miked\env\proj-x\myproject-x
>>>
>>> At this point on Linux one would install virtualenv-wrapper but that is
>>> unfortunately not available for Windows so a simple workaround is ...
>>>
>>> 1. mkdir \users\miked\bin # could be anything eg \users\miked\bat
>>>
>>> 2. Add C:\users\miked\bin to the path environment variable
>>>
>>> 3. Create a batch file called C:\users\miked\bin\proj-x.bat containing:
>>>
>>> cd \users\miked\env\proj-x\myproject-x
>>> ..\Scripts\activate
>>>
>>> 4. Create another batch file
>>> C:\users\miked\env\proj-x\myproject-x\exit.bat
>>> containing:
>>>
>>> cd \users\miked\
>>> \users\miked\env\proj-x\Scripts\deactivate
>>>
>>> 5. Test the workaround by opening a command prompt somewhere and entering
>>> proj-x. You should see:
>>>
>>> C:\Documents and Settings\Mike Dewhirst\Desktop>cd
>>> \users\miked\env\proj-x\myproject-x
>>>
>>> C:\users\miked\env\proj-x\myproject-x>..\Scripts\activate
>>> (proj-x) C:\users\miked\env\proj-x\myproject-x>
>>>
>>> 6. Test the exit batch file by entering exit at that command prompt:
>>>
>>> C:\users\miked\env\proj-x\myproject-x>..\Scripts\activate
>>> (proj-x) C:\users\miked\env\proj-x\myproject-x>exit
>>>
>>> (proj-x) C:\users\miked\env\proj-x\myproject-x>cd \users\miked\
>>>
>>> (proj-x) C:\users\miked>\users\miked\env\proj-x\Scripts\deactivate
>>> C:\users\miked>
>>>
>>> This should let you get into and out of the virtualenv quite easily.
>>>
>>> Now comes the difficult bit for Windows - installing stuff in the new
>>> Python's site-packages. First, though, discover what you already have
>>> installed in your main site-packages:
>>>
>>> pip freeze > requirements.txt # lists existing site-packages
>>>
>>> Here is mine, most of which I don't want in proj-x
>>>
>>> Django==1.5.4
>>> Jinja2==2.7.1
>>> MarkupSafe==0.18
>>> Pygments==1.6
>>> South==0.7.6
>>> Sphinx==1.1.3
>>> coverage==3.7
>>> django-discover-runner==1.0
>>> docutils==0.9.1
>>> filemov==1.1.1-2728-py2.7
>>> pillow==2.3.0
>>> pss==1.38
>>> psycopg2==2.4.5
>>> py2exe==0.6.9
>>> pytz==2012h
>>> pywin32==218
>>> virtualenv==1.11.2
>>>
>>> So I edit it down to the following, create a directory and save it as
>>> C:\users\miked\env\proj-x\requirements\requirements.txt
>>>
>>> Django==1.5.4
>>> South==0.7.6
>>> coverage==3.7
>>> django-discover-runner==1.0
>>> pillow==2.3.0
>>> psycopg2==2.4.5
>>> pytz==2013.9
>>>
>>> pip install -r C:\users\miked\env\proj-x\requirements\requirements.txt
>>>
>>> And this where (my) problems start. First pip will download the packages
>>> successfully but I don't have Visual Studio installed so those packages
>>> requiring compilation don't get installed. Here is a snippet of pip
>>> output
>>> after the downloads:
>>>
>>> Installing collected packages: Django, South, coverage,
>>> django-discover-runner, pillow, psycopg2, pytz
>>> Running setup.py install for Django
>>>
>>> ... and so on until errors start to appear. In my case the signal is:
>>>
>>> error: Unable to find vcvarsall.bat
>>>
>>> Afterwards, pip freeze shows:
>>>
>>> (proj-x) C:\users\miked\env\proj-x>pip freeze
>>> Django==1.5.4
>>> South==0.7.6
>>> coverage==3.7
>>> django-discover-runner==1.0
>>>
>>> ... which indicates pillow, psycopg2 and pytz did not install.
>>>
>>> But how come they were installed in the main site-packages? That's
>>> because
>>> they were originally downloaded from
>>> http://www.lfd.uci.edu/~gohlke/pythonlibs/ and installed manually.
>>>
>>> However, even after downloading from that site they cannot be installed
>>> manually into a virtualenv! Only pip can do that. The only workaround I
>>> have
>>> found is to manually copy them from the main site-packages to the new
>>> virtualenv site-packages. Clumsy.
>>>
>>> My proj-x requirements.txt file now looks like this ...
>>>
>>> Django==1.5.4
>>> South==0.7.6
>>> coverage==3.7
>>> django-discover-runner==1.0
>>> # pillow==2.3.0 http://www.lfd.uci.edu/~gohlke/pythonlibs/
>>> # psycopg2==2.4.5 http://www.lfd.uci.edu/~gohlke/pythonlibs/
>>> # pytz==2013.9 http://www.lfd.uci.edu/~gohlke/pythonlibs/
>>>
>>> After the above clumsy workaround everything works well and pip freeze
>>> displays ...
>>>
>>> Django==1.5.4
>>> South==0.7.6
>>> coverage==3.7
>>> django-discover-runner==1.0
>>> pillow==2.3.0
>>> psycopg2==2.4.5
>>> pytz==2013.9
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to django-users+unsubscribe@googlegroups.com.
>>> To post to this group, send email to django-users@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/django-users.
>>> To view this discussion on the web visit
>>>
>>> https://groups.google.com/d/msgid/django-users/52E86DE2.5010907%40dewhirst.com.au.
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/52E8914E.6020107%40dewhirst.com.au.
>
> For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABxbXqVB6Ld5xhc%3Dodof538ROsqFg3LrZoU1tK7MZ3%3DW0a7gyA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment