basiclanguage
basiclanguage

Reputation: 23

Understanding virtualenv in relation to python

I'm having a difficult time wrapping my head around how to utilize virtualenv and python3 together. As I understand it, virtualenv acts as an operating system within my mac's operating system. I installed virtualenv through the terminal and can activate/deactivate it successfully, but how do I use python3 with it?

I understand the python shell, I understand the terminal, but after I created the my_projects directory for virtualenv, how can I ensure I'm creating something in a virtualenv with python?

I'm not using homebrew or anaconda.

Upvotes: 2

Views: 219

Answers (2)

Anurag Misra
Anurag Misra

Reputation: 1544

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them.

It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

For example, you can work on a project which requires Django 1.10 while also maintaining a project which requires Django 1.8.

For more understanding refer to this Python Guide.

Upvotes: 1

Haifeng Zhang
Haifeng Zhang

Reputation: 31885

the virtual environment will isolate from the OS python. You can create a virtual env per project. For example project projectA, you can create an venv inside projectA as:

cd projectA
virtualenv -p /usr/bin/python3.5 venv-name-A

When you install any packages for projectA, you do: /path/to/venv-name-A/bin/pip install <pkg-name>

When you run your projectA, you do: /path/to/venv-name-A/bin/python projectA-file.py

You can create as many venvs as you want. You can install any packages on any envs without breaking your OS python accidentally.

Upvotes: 0

Related Questions