0

I'm trying to wrap my head around virtualenv and pip still.

If I use pip to install a library, it doesn't matter where I 'cd' to, because it installs the libraries in the same place right (which i dont even know where that is)? So I guess my question is, when I install something with pip, how do I make sure it only installs that library inside of my virtual environment? Do I need to cd to that directory first? or is there a command I'm supposed to use with pip to make sure it only installs to the virtualenv project I'm working in?

3 Answers 3

2

Activate virtualenv first:

source virt_name/bin/activate

Then after that, install the libraries:

pip install module_name

Note: Don't use sudo with pip because sometimes it will assume you want to install in /usr/local/lib/site-packages.

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

Comments

1

Generally speaking, if you do not use virtualenv --system-site-packages to create your virtualenv, you should be only working with your per-environment packages. Providing you run the activate script before installing anything.

i.e. Do the following, if you want to install something in your virtualenv.

  1. Run activate script
    1. Windows: [ve_directory]\Script\activate.bat
    2. Linux: source [ve_directory]/bin/activate
  2. pip install [your requirements]

I think it doesn't matter where your current working directory is.

Reference: http://www.virtualenv.org/en/latest/#the-system-site-packages-option

Comments

0

When you create a new environment with virtualenv, among other things it creates a bash script venv/bin/activate (where venv is the folder you specified when you created the environment; libraries are located there as well, by the way). When you run it in your shell the environment variables become arranged so that pip installs new libraries in this environment's folder. See virtualenv docs for details, section "activate script".

Comments

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.