Why do I need to use pip3 but not pip

Peter J. Holzer hjp-python at hjp.at
Sat Mar 30 07:43:17 EDT 2019


On 2019-03-30 15:57:55 +0530, Arup Rakshit wrote:
> This is awesome. Now where should I put my source code? I see many folders into it.

You don't. In my opinion virtual environments should be expendable: You
can destroy and recreate them at will. That leaves two possibilies:

1) Use a "central repository" of virtual environments. For example, I
   have a directory ~/venv/ which contains the virtual environments.

   My project directories are elsewhere, so when I'm working on a
   project, I' usually do something like:
    % venv project-environment
    % cd ~/wrk/project/src
    % pip install -r requirements.txt 
   The first (venv is a litte shell function I wrote, see below)
   activates the environment, the second cds to the source code (note
   that the environment and the project don't have to have the same
   name, although they often do), the third installs any required
   packages into the virtual environment (of course I do that only after
   they change, not every time).

2) Put each virtual environment into a subdirectory of the project, like
   this:
        .
        ├── project1
        │   ├── src
        │   └── venv
        └── project2
            ├── src
            └── venv

   Then I would do something like:
    % cd project1
    % venv
    % cd src
    % pip install -r requirements.txt

I started with the second method and switched to the first. I like the
flexibility: I can reuse the same environment for multiple projects or
test the same project in multiple environments. I can also easily see
which environments I have and delete them if I don't need them any more
(I can always recreate them with pip install -r requirements.txt)

The requirements.txt file contains the packages your project needs.
Every project should have one. Some people like to generate it
automatically with "pip freeze", but I prefer to write it myself and put
only first-level requirements (not requirements of those requirements)
into it. I also only put version numbers into it if I know that I need a
specific version (or range of versions). Normally getting the newest
version is fine.

Finally, here is my venv function:

venv() {
    for d in venv/"$1" ve/"$1" ~/venv/"$1" "$1"
    do
        if [ -f "$d"/bin/activate ]
        then
            . "$d"/bin/activate
            break
        fi
    done
}


        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20190330/bc195484/attachment.sig>


More information about the Python-list mailing list