knelson
knelson

Reputation: 126

Python 3.5 install pyvenv

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.

Upvotes: 2

Views: 2617

Answers (3)

knelson
knelson

Reputation: 126

Kesh's answer led me in the right direction.

The problem was that I didn't actually have pip installed in my venv.

It turns out, when I built python3.5 from source, I did not have the libssl-dev package. It looks like one of the dependencies of ensurepip was the python ssl package that didn't get installed because I didn't have libssl-dev.

To fix the problem, I rebuilt python 3.5 for source with the libssl-dev package installed. The rebuilt python now included the ssl package, which allowed ensurepip to install pip in my virtual environment.

Upvotes: 2

Keshan Nageswaran
Keshan Nageswaran

Reputation: 8188

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 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?
  3. Comprehensive beginner's virtualenv tutorial?

Upvotes: 2

Engineero
Engineero

Reputation: 12938

Try installing it locally:

pip install --user -r requirements.txt

which would, I believe, install the file in a sub-directory of your $HOME directory (which your virtual env I would think would set). Otherwise I think you could just use:

/path/to/virtualenv/pip install -r requirements.txt

Upvotes: 1

Related Questions