pip check fails, conda list fails, conda environment broken all of a sudden

0

One fine day I woke up and my conda enviroment broke which was really weird because my pip, conda, tensorflow and numpy worked the previous day.

I started the day by accidentally installing a wrong package: pip install telegram-bot

Collecting telegram-bot
  Using cached https://files.pythonhosted.org/packages/0c/89/b5f6cdebf62f1b37dfc0fd53fee0f92760531a51d834e5238b3110429e93/telegram-bot-0.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/fy/xjkb7k0d3q16fqp1578b63f00000gn/T/pip-build-muqgbeev/telegram-bot/setup.py", line 12, in <module>
        import telegram
      File "/private/var/folders/fy/xjkb7k0d3q16fqp1578b63f00000gn/T/pip-build-muqgbeev/telegram-bot/telegram/__init__.py", line 15, in <module>
        from telegram import Bot, ChatActions
    ImportError: cannot import name 'Bot'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/fy/xjkb7k0d3q16fqp1578b63f00000gn/T/pip-build-muqgbeev/telegram-bot/

At this point conda list failed mysteriously:

$conda list

# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

    Traceback (most recent call last):
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/exceptions.py", line 1001, in __call__
        return func(*args, **kwargs)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/cli/main.py", line 84, in _main
        exit_code = do_call(args, p)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/cli/conda_argparse.py", line 82, in do_call
        exit_code = getattr(module, func_name)(args, parser)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/cli/main_list.py", line 142, in execute
        show_channel_urls=context.show_channel_urls)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/cli/main_list.py", line 80, in print_packages
        show_channel_urls=show_channel_urls)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/cli/main_list.py", line 45, in list_packages
        installed = sorted(PrefixData(prefix, pip_interop_enabled=True).iter_records(),
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 116, in iter_records
        return itervalues(self._prefix_records)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 145, in _prefix_records
        return self.__prefix_records or self.load() or self.__prefix_records
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 69, in load
        self._load_site_packages()
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/core/prefix_data.py", line 258, in _load_site_packages
        python_record = read_python_record(self.prefix_path, af, python_pkg_record.version)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/gateways/disk/read.py", line 245, in read_python_record
        pydist = PythonDistribution.init(prefix_path, anchor_file, python_version)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/common/pkg_formats/python.py", line 78, in init
        return PythonInstalledDistribution(prefix_path, anchor_file, python_version)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/common/pkg_formats/python.py", line 382, in __init__
        super(PythonInstalledDistribution, self).__init__(anchor_full_path, python_version)
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/common/pkg_formats/python.py", line 106, in __init__
        self._check_files()
      File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/conda/common/pkg_formats/python.py", line 116, in _check_files
        assert isfile(fpath)
    AssertionError

`$ /Users/sunyitao/anaconda3/bin/conda list`

  environment variables:
                 CIO_TEST=<not set>
               CONDA_ROOT=/Users/sunyitao/anaconda3
                     PATH=/Users/sunyitao/google-cloud-sdk/bin:/Users/sunyitao/anaconda3/bin:/us
                          r/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.d
                          otnet/tools:/Library/Frameworks/Mono.framework/Versions/Current/Comman
                          ds:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin
               PYTHONPATH=::/Users/sunyitao/slim
       REQUESTS_CA_BUNDLE=<not set>
            SSL_CERT_FILE=<not set>

     active environment : None
       user config file : /Users/sunyitao/.condarc
 populated config files : /Users/sunyitao/.condarc
          conda version : 4.6.2
    conda-build version : 3.17.7
         python version : 3.6.5.final.0
       base environment : /Users/sunyitao/anaconda3  (writable)
           channel URLs : https://conda.anaconda.org/intel/osx-64
                          https://conda.anaconda.org/intel/noarch
                          https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/osx-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /Users/sunyitao/anaconda3/pkgs
                          /Users/sunyitao/.conda/pkgs
       envs directories : /Users/sunyitao/anaconda3/envs
                          /Users/sunyitao/.conda/envs
               platform : osx-64
             user-agent : conda/4.6.2 requests/2.20.0 CPython/3.6.5 Darwin/18.2.0 OSX/10.14.2
                UID:GID : 501:20
             netrc file : None
           offline mode : False

So I googled and did pip install -U setuptools and conda update conda with no errors, but installing telegram-bot still failed. But what I really wanted to install was pip install python-telegram-bot which succeeded.

So I ran this to check if the first package is completely removed:

$pip uninstall telegram-bot
Cannot uninstall requirement telegram-bot, not installed

Ran conda list again but same error.

I moved on and did some stuff with tensorflow working fine. After a while I install lightgbm with conda.

Downloading and Extracting Packages
lightgbm-2.2.1       | 617 KB    | ##################################################################################################### | 100%
numpy-base-1.15.4    | 6.0 MB    | ##################################################################################################### | 100%
llvm-openmp-4.0.1    | 454 KB    | ##################################################################################################### | 100%

Now when I run import tensorflow as tf I get this:

Using TensorFlow backend.
File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 32, in <module>
    from tensorflow.python.framework import fast_tensor_util
  File "__init__.pxd", line 872, in init tensorflow.python.framework.fast_tensor_util
ValueError: numpy.ufunc has the wrong size, try recompiling. Expected 192, got 216

I originally had numpy 1.16 from pip and another version of numpy from anaconda. So I uninstalled both versions with pip and then did conda uninstall numpy --force so it would not delete all my packages which depended on numpy. I ran conda install numpy which succeeded.

But now when I import numpy I get:

ModuleNotFoundError: No module named 'numpy'

Did a sanity check with:

$which pip
/Users/sunyitao/anaconda3/bin/pip
$which conda
/Users/sunyitao/anaconda3/bin/conda
$which python
/Users/sunyitao/anaconda3/bin/python

pip check:

$pip check
Exception:
Traceback (most recent call last):
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2797, in _dep_map
    return self.__dep_map
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2608, in __getattr__
    raise AttributeError(attr)
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2788, in _parsed_pkg_info
    return self._pkg_info
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2608, in __getattr__
    raise AttributeError(attr)
AttributeError: _pkg_info

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/commands/check.py", line 20, in run
    missing_reqs_dict, incompatible_reqs_dict = check_requirements(dists)
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/operations/check.py", line 10, in check_requirements
    missing_reqs = list(get_missing_reqs(dist, installed_dists))
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/operations/check.py", line 30, in get_missing_reqs
    for requirement in dist.requires():
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2552, in requires
    dm = self._dep_map
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2799, in _dep_map
    self.__dep_map = self._compute_dependencies()
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2808, in _compute_dependencies
    for req in self._parsed_pkg_info.get_all('Requires-Dist') or []:
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 2790, in _parsed_pkg_info
    metadata = self.get_metadata(self.PKG_INFO)
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 1468, in get_metadata
    value = self._get(self._fn(self.egg_info, name))
  File "/Users/sunyitao/anaconda3/lib/python3.6/site-packages/pip-9.0.3-py3.6.egg/pip/_vendor/pkg_resources/__init__.py", line 1577, in _get
    with open(path, 'rb') as stream:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/sunyitao/anaconda3/lib/python3.6/site-packages/parso-0.3.1.dist-info/METADATA'
You are using pip version 9.0.3, however version 19.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

I am deliberating reinstalling everything now but it is really a last resort option that could take the entire day.

Edit: I have fixed the numpy issue by running

conda config --add channels conda-forge
conda install numpy --force-reinstall

Now tensorflow and numpy are working again, but pip check and conda list still fails. When I activate a different enviroment pip check and conda list will work so it seems to be a issue with my base enviroment.

Sun Yi Tao

Posted 2019-02-01T05:40:08.153

Reputation: 1

No answers