What's the How to Install Pip, Virtualenv, and Distribute for Python

installing modules in python - pip, distribute, nose, virtualenv

To solve your issue,

Just install (or upgrade) the setuptools:

sudo easy_install -U setuptools

Then you can run again: pip install virtualenv

pip installs packages in virtualenv and globally when called from bash script

Running this in a bash script runs the commands in a different shell, then returns you to your original shell. Running source <path>/bin/activate runs this in you current shell, hence this works from the command line. Your bash script looks like:

#!/bin/bash
source "<absolute path>/venv/bin/activate"
which pip
pip install psutil
pip listenter code here

If you call this with source script.sh this will run this in you current shell and should work as expected. Hope this helps. There is some other methods here:
https://stackoverflow.com/a/13122219/7473057

An example method for virtualenvs:

  1. create an environment python -m venv venv_test or virtualenv venv_test
  2. activate the environment: source ./venv_test/bin/activate (on cmd line)
  3. run script ./script.sh, which has source "<absolute path>/venv/bin/activate" removed.

Alternatively, I think what you are after is a subshell, running everything inside, which is in the link above.

pip installing in global site-packages instead of virtualenv

Funny you brought this up, I just had the exact same problem. I solved it eventually, but I'm still unsure as to what caused it.

Try checking your bin/pip and bin/activate scripts. In bin/pip, look at the shebang. Is it correct? If not, correct it. Then on line ~42 in your bin/activate, check to see if your virtualenv path is right. It'll look something like this

VIRTUAL_ENV="/Users/me/path/to/virtual/environment"

If it's wrong, correct it, deactivate, then . bin/activate, and if our mutual problem had the same cause, it should work. If it still doesn't, you're on the right track, anyway. I went through the same problem solving routine as you did, which piping over and over, following the stack trace, etc.

Make absolutely sure that

/Users/kristof/VirtualEnvs/testpy3/bin/pip3

is what you want, and not referring to another similarly-named test project (I had that problem, and have no idea how it started. My suspicion is running multiple virtualenvs at the same time).

If none of this works, a temporary solution may be to, as Joe Holloway said,

Just run the virtualenv's pip with its full path (i.e. don't rely on searching the executable path) and you don't even need to activate the environment. It will do the right thing.

Perhaps not ideal, but it ought to work in a pinch.

Link to my original question:

VirtualEnv/Pip trying to install packages globally

What is the official preferred way to install pip and virtualenv systemwide?

If you can install the latest Python (2.7.9 and up) Pip is now bundled with it.
See: https://docs.python.org/2.7//installing/index.html

If not :

Update (from the release notes):

Beginning with v1.5.1, pip does not require setuptools prior to running get-pip.py. Additionally, if setuptools (or distribute) is not already installed, get-pip.py will install setuptools for you.

I now run the regular:

curl --silent --show-error --retry 5 https://bootstrap.pypa.io/get-pip.py | sudo python

Here are the official installation instructions:
http://pip.readthedocs.org/en/latest/installing.html#install-pip

EDIT 25-Jul-2013:
Changed URL for setuptools install.

EDIT 10-Feb-2014:
Removed setuptools install (thanks @Ciantic)

EDIT 26-Jun-2014:
Updated URL again (thanks @LarsH)

EDIT 1-Mar-2015:
Pip is now bundled with Python

How to get pip to install packages into the virtual environment?

It works well for me after following docs:

Common installation tools such as Distribute and pip work as expected
with venvs - i.e. when a venv is active, they install Python packages
into the venv without needing to be told to do so explicitly. Of
course, you need to install them into the venv first
: this could be
done by running distribute_setup.py with the venv activated, followed
by running easy_install pip. Alternatively, you could download the
source tarballs and run python setup.py install after unpacking, with
the venv activated.

Install pip and virtualenv, a chicken and the egg dilemma?

tl;dr Answer would be VirtualEnv first.
You can have two of them each for Python version 2.x and 3.x

[edit]

I am really doubtful if installing (there is no install, you merely download and execute a script) VirtualEnv system wide/per-user even matters. The whole point of Using VirtualEnv is to create isolated development sandboxes so that the libraries from one project doesn't conflict with each other. For example you can a Python 2.x project using Beautiful-soup Version < 4.x and A Python 3.x project Using Beautiful-soup Version 4.0 in two different Virtual Environments.

How you get VirtualEnv script on your system doesn't really matter, and since once you have it and pip is self contained within VirtualEnv, it just makes sense to get VirtualEnv first. Also once you are in with python, you would have many projects, and for each, the recommended way would be to have a Virtual Environment, and then install dependencies via pip. You can later do "pip freeze > requirements.txt" and then a "pip install requirements.txt" to simply replicate your exact libraries across two systems [say dev and production] and so on...

Where does pip install packages with a virtual environment?

This very much depends on which version (not in the semantic version sense, but of the having-multiple-"versions" of pip installed when you create a venv) of pip your script is using, as well as its configuration (including possibly your environment).

Assuming your script has a line like

/some/path/to/pip install <some package>

and assuming that that pip has installed at least one package, you can use

/some/path/to/pip show <that package>

and it'll give you output that looks like:

$ pip show numpy
Name: numpy
Version: 1.14.5
Summary: NumPy: array processing for numbers, strings, records, and objects.
Home-page: http://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: /usr/lib/python3/dist-packages
Requires:

The location line second to last should help answering your question.



Related Topics



Leave a reply



Submit