Cheatsheet virtualenvwrapper

This is a cheatsheet for virtualwrapper.

Install virtualenvwrapper

pip install virtualenv

pip install virtualenvwrapper-win

Set environment variable

Add an environment variable WORKON_HOME to specify the path to store environments. By default, this is %USERPROFILE%\Envs. I have set it to the following.

WORKON_HOME=%PYTHON27%\env

Main commands

mkvirtualenv <name>

lsvirtualenv

workon <name>

cdvirtualenv

deactivate

add2virtualenv <full or relative path>

setprojectdir <full or relative path>

cdproject

cdsitepackages

lssitepackages

 

Cleanup the default Python environment

I have been messing around with Python these last few weeks. Playing with Python means installing a lot of packages. I did this without using virtualenv, so my default Python environment had a lot of packages installed globally.

I now have a couple of projects that I want to work on and I what each project to have its own clean environment. That means using virtualenv. When running virtualenv without with the option --no-site-packages all the packages that are installed globally are included in the virtualenv.

I wanted to remove all the global packages to have a clean default environment. I did this by running the following command.

Windows

pip freeze > remove.txt && pip uninstall -y -r remove.txt && del remove.txt

Linux

pip freeze > remove.txt && pip uninstall -y -r remove.txt && rm remove.txt

After cleaning up the default envrionment by removing all the global packages don’t forget to install virtualenv en virtualenvwrapper-win by running the following command.

pip install virtualenvwrapper-win

For quick instructions of the main commands please check out virtualenvwrapper-win Github page.

Python and Windows

I’m back… It has been a while since my last post. To busy doing other things and not keeping up with my techie skills. I have decided it is time for some new projects. I have a few ideas lined up. Python, Flask, Angular 2 and Ionic 2 are my tools of choice. So I will be blogging about my adventures the comings weeks, months, …

Okay, this blog is going to be on setting up Python on Windows. Just some quick for myself with notes for later reference.

  • Install Python
  • Set environment variable %PYTHON27%
  • Add the following Python dirctories to path: bin & scripts
  • Setup virtualenv, a tool for creating isolated Python virtual environments, each with their own libraries and site-packages:
    pip install virtualenv
  • Install virtualenvwrapper, provides a set of commands which makes working with virtual environments much more pleasant. It also places all your virtual environments in one place:
    pip install virtualenvwrapper-win
  • Add an environment variable WORKON_HOME to specify the path to store environments. My choice: %PYTHON27%\env.
  • For an  overview of the main commands check the repository on GitHub.
  • In order to keep your environment consistent, it’s a good idea to “freeze” the current state of the environment packages. To do this, run:
    pip freeze > requirements.txt
  • This will create a requirements.txt file, which contains a simple list of all the packages in the current environment, and their respective versions. You can see the list of installed packages without the requirements format using “pip list”. Later it will be easier for a different developer (or you, if you need to re-create the environment) to install the same packages using the same versions:
    pip install -r requirements.txt
  • Install Flask-DebugToolbar an extension that adds a toolbar overlay to Flask applications containing useful information for debugging:
    pip install flask-debugtoolbar
  • Check the Flask-DebugToolbar documentation for more information on the use.
  • Install initpy that helps initialize Python projects. It has support for different types of projects: single file project, Flask, Tornado Web, Falcon and Hosted.
    pip install initpy