Shawn
Shawn

Reputation: 77

pip installing does not install to virtualenv

I'm very new to all of this, so bear with me.

I started, and activated, a virtual environment. But when I pip install anything, it installs to the computer, not the the virtual env.

I'm on a Mac, trying to build a Django website.

Example: With the virtual machine activated. I type:

python -m pip install Django

Then I can deactivate the virtual env, and type:

pip freeze

And it will list out the freshly installed version of Django.

Any clue as to why this is happening?

Upvotes: 2

Views: 7028

Answers (3)

SLDem
SLDem

Reputation: 2182

If you want to install to your virtualenvironment you have to activate it, otherwise it will install to the main Python folder.

Upvotes: 1

Avatazjoe
Avatazjoe

Reputation: 506

Run this line from your project folder where "env" is your virtual enviroment

# A virtualenv's python:
$ env/bin/python -m pip install django

Upvotes: 7

Cshitiz Dhingra
Cshitiz Dhingra

Reputation: 175

Confirm you’re in the virtual environment by checking the location of your Python interpreter, it should point to the env directory.

On macOS and Linux:

which python
.../env/bin/python

As long as your virtual environment is activated pip will install packages into that specific environment and you’ll be able to import and use packages in your Python application.

Upvotes: 0

Related Questions