Search code examples
pythonanacondapython-venv

Anaconda 3 for Linux Has No ensurepip?


This is my environment:

  • CentOS 64-bit 7.2.1511

  • Anaconda 3 4.1.1 64-bit (Python 3.5.2)

I want to create venv virtual environment by pyvenv. Unfortunately, I got this error message:

$ pyvenv test Error: Command '['/root/test/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

After searching the Internet, people said the module ensurepip is missing. I checked my Anaconda installation path /opt/anaconda3/lib/python3.5. There is no ensurepip folder.

Then, on my Windows 10 64-bit, I checked my Anaconda installation path D:\win10\Anaconda3\Lib\. There is an ensurepip folder! And I can successfully run python -m venv test to create a venv.

Then, I checked the download Anaconda python archives: D:\win10\Anaconda3\pkgs\python-3.5.2-0.tar.bz2 on Windows 10 and /opt/anaconda3/pkgs/python-3.5.2-0.tar.bz2 on CentOS 7.

The one archive on Windows 10 does has a ensurepip subfolder. But the one on CentOS 7 doesn't!

Does anyone know this difference? Is it a bug of Anaconda?


Solution

  • Yes, Anaconda3/2 for Linux and Mac OS do not have ensurepip installed.

    According to this issue record, it is NOT a bug, this is done intentionally when the Python in Anaconda being compiled without the --with-ensurepip=install flag.

    I think the rationale (of Continuum Analytics) is that, in Anaconda Distribution, conda is the boss to manage the packages and virtual environments, and

    pip (and it's setuptools dependency) are installed independent of Python as conda packages.

    So instead of running pyvenv test, you can first run pyvenv test --without-pip, then download the get-pip.py from pip's homepage, and install the pip in activated test venv.

    Just like the following:

    $ #===== First create the venv without pip, and **activate** it.
    $ pyvenv test --without-pip
    $ cd test/
    $ ls bin/
    activate       activate.csh   activate.fish  python@        python3@
    $ echo $PATH
    Whatever/Else:In/Your/System
    $ source bin/activate
    (test) $ echo $PATH
    /Users/YaOzI/test/bin:Whatever/Else:In/Your/System
    (test) $
    (test) $ #===== Then install the pip independently.
    (test) $ python ~/Downloads/get-pip.py
    Collecting pip
      Using cached pip-8.1.2-py2.py3-none-any.whl
    Collecting setuptools
      Downloading setuptools-26.0.0-py2.py3-none-any.whl (459kB)
        100% |████████████████████████████████| 460kB 1.3MB/s 
    Collecting wheel
      Downloading wheel-0.29.0-py2.py3-none-any.whl (66kB)
        100% |████████████████████████████████| 71kB 5.7MB/s 
    Installing collected packages: pip, setuptools, wheel
    Successfully installed pip-8.1.2 setuptools-26.0.0 wheel-0.29.0
    (test) $ ls bin/
    activate   activate.fish     easy_install-3.5*  pip3*  python@   wheel*
    activate.csh  easy_install*  pip*     pip3.5*   python3@
    (test) $
    (test) $ #===== Now you can play around with pip
    (test) $ pip list
    (test) $