How to Create Virtual Environment in Python 2.7

Virtual Environment is an environment where the developers or programmers can avoid the global dependency of library packages installed in python. Virtual environments are effective when, the software has to be shipped as whole without creating any dependency issues.

Here we can learn about how to create Virtual environment using CMD (multi-step) and Pycharm(quicker πŸ™‚ ). Lets go!

CMD:

  1. Installing Virtual Environment type: β€œpip install virtualenvβ€œ

2. Verify installed version using β€œpython -m virtualenv –versionβ€œ

3. Now lets create a folder as a virtual environment, by β€œpython -m virtualenv <foldername>β€œ, eg: β€œpython -m virtualenv pandatestingβ€œ

4. We can activate the environment by, go to Scripts folder available in virtual environment and run β€œactivate.bat”

5. Let try installing a package inside the virtual environment. β€œpip install pandasβ€œ

6. OK, but if I want to install multiple packages and even some with particular version, how could I do it.. Hmm.. the answer is requirement. Lets see the snip of how requirements looks like,

Now copy the file to virtual folder and install using below command β€œpip install -r requirements.txtβ€œ

Now the Virtual environment is ready for you!

Pycharm

Now, lets do the quicker way using pycharm,

  1. Create a new project in pycharm

2. Create Virtual Environment using PyCharm

3. You can see the virtual environment is created and now you can add requirements.txt

4. When you open a requirements.txt, you could see the package requirement inspection (image of bulb) pops up and give you the status of package installed.

One thought on “How to Create Virtual Environment in Python 2.7

Leave a comment

Design a site like this with WordPress.com
Get started