Python 3.5 install pyvenv
Question: I am trying to get a virtual environment for a repo that requires python 3.5.
I am using Debian, and from what I can tell, python 3.5 does not have an
aptitude package. After reading some posts, it was recommended to download 3.5
source code and compile it.

After running the make and install, python3.5 was installed to /usr/local/bin.
I added that to the $PATH variable.

Here is where I ran into problems. After I ran:

    
    
    $ cd project-dir
    $ pyvenv env
    $ source env/bin/activate
    $ pip install -r requirements.txt
    

I was getting issues with needing sudo to install the proper packages. I ran:

    
    
    $ which pip
    

and it turns out that pip was still using the /usr/local/bin version of pip.

    
    
    $ echo $PATH
    

returned

    
    
    /home/me/project-dir/env/bin:/usr/local/bin:/usr/bin:/bin: ...
    

I am assuming that because the /usr/local path came after the virtual
environment's path in my PATH variable, it is using that version of pip
instead of my virtual environments.

What would be the best way to run the correct version of pip within the
virtualenv? The two options I can think of is moving the binaries over to
/usr/bin or modifying the activate script in my virtual env to place the
virtualenv path after /usr/local.


Answer: **Option 1** You can upgrade pip in a virtual environment manually by
executing

    
    
    pip install -U pip
    

**Option 2** Good method to upgrade pip inside that package `python -m
ensurepip --upgrade` does indeed upgrade the pip version in the system (if it
is lower than the version in ensurepip).

You are facing this problem, because venv uses
[ensurepip](https://docs.python.org/dev/library/ensurepip.html#module-
ensurepip) to add pip into new environments:

> Unless the --without-pip option is given, ensurepip will be invoked to
> bootstrap pip into the virtual environment.

Ensurepip package won't download from the internet or grab files from anywhere
else, because all required components are already included into the package.
Doing so would add security flaws and is thus unsupported.

Ensurepip is not designed to give you the newest pip, but just "a" pip. To get
the newest one use the manual way at the beginning of this post.

To check ensurepip version you can type into python console `import ensurepip
print(ensurepip.version())`

**More Findings for further reading:**

  1. To upgrade ensurepip manually using files - <https://github.com/python/cpython/commit/f649e9c44631c07e707842c42747b651b986dcc4>
  2. [What's the proper way to install pip, virtualenv, and distribute for Python?](http://stackoverflow.com/questions/4324558/whats-the-proper-way-to-install-pip-virtualenv-and-distribute-for-python)
  3. [Comprehensive beginner's virtualenv tutorial?](http://stackoverflow.com/questions/5844869/comprehensive-beginners-virtualenv-tutorial/14717552#14717552)

