2

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.

2
  • Possible duplicate of Using Python 3 in virtualenv Commented Feb 9, 2017 at 18:37
  • "As I understand it, virtualenv acts as an operating system within my mac's operating system" No. It acts as an environment isolated from your working environment. A virtual environment, you might say... Commented Feb 9, 2017 at 18:51

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

5 Comments

Thank you, Haifeng. I'm struggling now because the path that my project was installed looks a bit different than yours. My looks like: /Users/Main/Desktop/Python_practice/Lamba/myproject. From the myproject directory I entered virtualenv venv. Did I install the virtual environment in the wrong location initially?
@basiclanguage no matter where you store the venv, it is isolated from your OS python, and you know the installed packages are for the specific project:)
Okay cool, what would be the difference between these two: python3 -m pip install virtualenv & virtualenv -p /usr/bin/python3.5 venv-name-A ?
i think it should be pip install virtualenv, in which installs virtulenv package. the latter command is creating venv based on python3.5
This really clears it up for me, Haifeng. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.