I have a fresh install of Anaconda 4.5.10 (Python 3.6 64-bit version) on Ubuntu 16.04. I created a Python 2.7 conda env called py2.7
using the following command:
conda create -n py2.7 python=2.7
After activating the environment which pip
returns /home/sam/anaconda3/envs/py2.7/bin/pip
. When I try to install anything with pip I get a dependency error. For example:
(py2.7) sam@sam-M3:~$ pip install numpy
/home/sam/.local/lib/python2.7/site-packages/requests/__init__.py:80: RequestsDependencyWarning: urllib3 (1.22) or chardet (2.3.0) doesn't match a supported version!
RequestsDependencyWarning)
Traceback (most recent call last):
File "/home/sam/anaconda3/envs/py2.7/bin/pip", line 7, in <module>
from pip._internal import main
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 18, in <module>
from pip.commands import get_summaries, get_similar_commands
File "/usr/lib/python2.7/dist-packages/pip/commands/__init__.py", line 6, in <module>
from pip.commands.completion import CompletionCommand
File "/usr/lib/python2.7/dist-packages/pip/commands/completion.py", line 4, in <module>
from pip.basecommand import Command
File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 19, in <module>
from pip.req import InstallRequirement, parse_requirements
File "/usr/lib/python2.7/dist-packages/pip/req/__init__.py", line 3, in <module>
from .req_install import InstallRequirement
File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 18, in <module>
from pip._vendor.distlib.markers import interpret as markers_interpret
File "/home/sam/.local/lib/python2.7/site-packages/distlib/markers.py", line 108, in <module>
DEFAULT_CONTEXT = default_context()
File "/home/sam/.local/lib/python2.7/site-packages/distlib/markers.py", line 97, in default_context
'platform_python_implementation': platform.python_implementation(),
File "/usr/lib/python2.7/platform.py", line 1481, in python_implementation
return _sys_version()[0]
File "/usr/lib/python2.7/platform.py", line 1443, in _sys_version
repr(sys_version))
ValueError: failed to parse CPython sys.version: '2.7.15 |Anaconda, Inc.| (default, May 1 2018, 23:32:55) \n[GCC 7.2.0]'
I can see that the error is being caused by Python trying to access libraries in /usr/lib/python2.7
, but I want to only access libraries that are part of the conda py2.7 env. My issue is addressed here: https://stackoverflow.com/a/46672866/10274139, but the solution isn't clear. With the conda env activated, when I list my environmental variables, I see nothing about other Python paths:
(py2.7) sam@sam-M3:~$ env | grep python
CONDA_PYTHON_EXE=/home/sam/anaconda3/bin/python
Also, if I create a Python 3.7 conda env, I get no errors when I pip install
in that env.