Search This Blog

Thursday, April 24, 2014

Virtualenv+Git how to

If you do Python development, and don't use virtualenv, you should start right away! Not convinced? Just do some internet searches and get convinced. The problem then becomes, how to handle this with your preferred SCM. I use Git, so that's what I'll describe, but the concepts should easily translate to other SCMs.

 See, the issue is that the actual virtual environment folder shouldn't be under Git's control, cause different developers may use different platforms, so each developer/system combo will require a different virtual environment, suited for their specific need (virtualenv wil take care of this last part). Briefly, the idea is to create an outer folder, where all the code you (and possibly others) write lives. This folder should also contain all the information required to create the virtual environment, which is created as a subfolder. In other words:
- projectFolder/
    - requirements.txt
    - vEnvFolder/
        - .Python -> ...
        - bin/
        - include/
        - lib/
With this directory structure, simply add projectFolder/vEnvFolder/ to the .gitignore file and that's it! The requirements.txt file should be generated by using pip freeze, after installing all necessary dependencies in the virtual environment. Here's my complete workflow:
[~]$ cd gitProject/
[gitProject]$ virtualenv --no-site-packages vEnv
[gitProject]$ source vEnv/bin/activate
(vEnv)[gitProject]$ pip install 
(vEnv)[gitProject]$ pip freeze > requirements.txt
(vEnv)[gitProject]$ echo vEnv >> .gitignore
(vEnv)[gitProject]$ git add .
(vEnv)[gitProject]$ git commit -m "added virtualenv"
When checking out the project, the flow is as follows:
[~]$ git clone gitProject 
[~]$ cd gitProject 
[gitProject]$ virtualenv --no-site-packages vEnv
[gitProject]$ source vEnv/bin/activate
(vEnv)[gitProject]$ pip install -r requirements.txt
(... ready to rumble)
I don't know if this is the best/recommended alternative, but so far it has worked for me.


  1. A deep research has been done for the Austral sound for the entertainment of the people. This sound has been considered as one of the most beautiful and soothing sound for the ears of the human beings. Yes, there is no doubt for the people I n this sound.

  2. This is reasonable solution for those people who are interested to use a fine featured made virtual system. For writing of assigned projects hiring of help from gonerdify review is very useful for students of all classes.

  3. This comment has been removed by the author.

  4. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog.
    Really very informative post you shared here. Kindly keep blogging.
    If anyone wants to become a Front end developer learn from Javascript Online Training from India .
    or learn thru JavaScript Online Training from India.
    Nowadays JavaScript has tons of job opportunities on various vertical industry. ES6 Training in Chennai

  5. Thank you for sharing your article. Great efforts put it to find the list of articles which is very useful to know, Definitely will share the same to other forums.
    KissAnime alternatives

  6. WinStar World Casino and Resort Tickets - JtmHub
    Get your chance to 대구광역 출장안마 experience the magic 오산 출장안마 of 순천 출장샵 Las Vegas right at JTM's new and improved casino and 동두천 출장마사지 resort venue!Jan 10, 2022John Mulaney ConcertsFeb 8, 2022Shinedown 광주 출장마사지