Set virtualenv on Python projects

Set virtualenv on Python projects

Allan Porras
Allan Porras May 29 2016 • 1 min read
Share:

Sometimes we need different python packages versions in different projects. It’s like to have 3 computers, and running a different Python project on each computer, and the first project is using Django 1.8, the second project Django 1.7, and the third project Django 1.9.4.

Really I need 3 different computers to do that? Not at all.

Virtualenv is the hero, downloadable from pip, and it make our life easier. It let us to have a lot of Python projects, using their different dependence and versions, all living at the same computer but different environment. Check out the next image.

To install virtualenv, just you need to type:

pip install virtualenv 

This line will download, install and config virtualenv and their own dependence.

Now we are enabled to create a new virtual environment over any existing Python project. For this example, we already have a project called “mall4g”. We need to browse to the directory and run the command, where “mall4g” is a directory.

virtualenv mall4g

This will create extra directories:  lib, bin, include, local. Probably you want to ignore that directories when you push your code to Git.

Now, to activate:

source bin/activate

Done. Now, all python packages installed by using pip, will be located automatically under our “local” directory. No stress. No more problems.

Request follow-up 🤙

About 4Geeks

Founded in 2012, 4Geeks is a global software engineering and revenue growth consulting firm for Fortune 500, Global 2000 and fast-growing SMBs. Provides top solutions to multiple industries including Retail, Healthcare, Banking & Financial Services, B2B SaaS, Manufacturing and Education. HQ in the USA, and delivery centers across Latin America.

Weekly Business Newsletter

Actionable Growth Hacks

Receive relevant news, advice, trends in your industry and invitations to exclusive events, direct to your inbox every week.

Subscribe on LinkedIn