Solve the problem that the installed module cannot be import ed

Keywords: Anaconda pip Python Pycharm

System: windows 10

Tools: python 3.7, pycharm, anaconda

Problem: numpy cannot import

First, check where the environment corresponding to your pycharm s interpreter is and whether there is any numpy package installed in it. Here I am in the base environment.

In the anaconda prompt window, enter conda list (this is to check the package in the base environment) [CONDA - N XXX (environment name) list to check the package in the specified environment]. After checking, it is found that there are numpy packages.

Then, in the anaconda prompt window, enter conda uninstall numpy, uninstall numpy in the base environment [similarly, CONDA uninstall - N XXX (environment name) numpy], and then conda install numpy is reinstalled. It is found that import is still not possible.

-------------Well, I'll try again-------------

In the anaconda prompt window, use the pip command to uninstall and install numpy.

Check out numpy first

(base) C:\Users\Christine Yang>pip show numpy
Name: numpy
Version: 1.16.5
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: c:\anaconda\lib\site-packages
Requires:
Required-by: torchvision, tables, statsmodels, seaborn, scikit-learn, PyWavelets, pytest-doctestplus, pytest-arraydiff, patsy, pandas, numexpr, numba, mkl-random, mkl-fft, matplotlib, imageio, h5py, Bottleneck, bokeh, bkcharts, astropy

Then unload and reload

(base) C:\Users\Christine Yang>pip uninstall numpy
Uninstalling numpy-1.16.5:
  Would remove:
    c:\anaconda\lib\site-packages\numpy
    c:\anaconda\lib\site-packages\numpy-1.16.5-py3.7.egg-info
    c:\anaconda\scripts\f2py-script.py
    c:\anaconda\scripts\f2py.exe
Proceed (y/n)? y
  Successfully uninstalled numpy-1.16.5

(base) C:\Users\Christine Yang>pip install numpy
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/a9/38/f6d6d8635d496d6b4ed5d8ca4b9f193d0edc59999c3a63779cbc38aa650f/numpy-1.18.1-cp37-cp37m-win_amd64.whl (12.8MB)
     |████████████████████████████████| 12.8MB 7.0kB/s
Installing collected packages: numpy
Successfully installed numpy-1.18.1

To ensure the correct installation location, show again:

(base) C:\Users\Christine Yang>pip show numpy
Name: numpy
Version: 1.18.1
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: c:\anaconda\lib\site-packages
Requires:
Required-by: torchvision, tables, statsmodels, seaborn, scikit-learn, PyWavelets, pytest-doctestplus, pytest-arraydiff, patsy, pandas, numexpr, numba, mkl-random, mkl-fft, matplotlib, imageio, h5py, Bottleneck, bokeh, bkcharts, astropy

Finally, refresh the environment in pycharm and run the relevant code successfully!! (excitement)

----------------------------------------------------------------------------------------------

It also made me think about the difference between pip and conda commands

The main explanation is that pip allows you to install python packages in any environment, and conda allows you to install any language package in conda environment.

But that doesn't explain what happened to me this time. When running pip in anaconda prompt, because it is already in the basic environment of Anaconda by default, the installation and uninstallation of pip is also aimed at packages in the directory of anaconda.

For this reason, I tried the command of conda install again to see if the two commands search packages in different ways and from different sources.

(base) C:\Users\Christine Yang>conda install numpy
Collecting package metadata (current_repodata.json): done
Solving environment: /
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:

  - defaults/win-64::anaconda==2019.10=py37_0
  - defaults/win-64::astropy==3.2.1=py37he774522_0
  - defaults/win-64::bkcharts==0.2=py37_0
  - defaults/win-64::bokeh==1.3.4=py37_0
  - defaults/win-64::bottleneck==1.2.1=py37h452e1ab_1
  - defaults/noarch::dask==2.5.2=py_0
  - defaults/win-64::h5py==2.9.0=py37h5e291fa_0
  - defaults/win-64::imageio==2.6.0=py37_0
  - defaults/win-64::matplotlib==3.1.1=py37hc8f65d3_0
  - defaults/win-64::mkl_fft==1.0.14=py37h14836fe_0
  - defaults/win-64::mkl_random==1.1.0=py37h675688f_0
  - defaults/win-64::numba==0.45.1=py37hf9181ef_0
  - defaults/win-64::numexpr==2.7.0=py37hdce8814_0
  - defaults/win-64::numpy==1.16.5=py37h19fb1c0_0
  - defaults/win-64::pandas==0.25.1=py37ha925a31_0
  - defaults/win-64::patsy==0.5.1=py37_0
  - defaults/win-64::pytables==3.5.2=py37h1da0976_1
  - defaults/win-64::pytest-arraydiff==0.3=py37h39e3cac_0
  - defaults/win-64::pytest-astropy==0.5.0=py37_0
  - defaults/noarch::pytest-doctestplus==0.4.0=py_0
  - pytorch/win-64::pytorch==1.4.0=py3.7_cuda101_cudnn7_0
  - defaults/win-64::pywavelets==1.0.3=py37h8c2d366_1
  - defaults/win-64::scikit-image==0.15.0=py37ha925a31_0
  - defaults/win-64::scikit-learn==0.21.3=py37h6288b17_0
  - defaults/win-64::scipy==1.3.1=py37h29ff71c_0
  - defaults/win-64::seaborn==0.9.0=py37_0
  - defaults/win-64::statsmodels==0.10.1=py37h8c2d366_0
  - pytorch/win-64::torchvision==0.5.0=py37_cu101
done

## Package Plan ##

  environment location: C:\Anaconda

  added / updated specs:
    - numpy


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    _anaconda_depends-2019.03  |           py37_0           6 KB
    anaconda-custom            |           py37_1           3 KB
    numpy-base-1.16.5          |   py37hc3f5095_0         3.3 MB
    ------------------------------------------------------------
                                           Total:         3.3 MB

The following NEW packages will be INSTALLED:

  _anaconda_depends  pkgs/main/win-64::_anaconda_depends-2019.03-py37_0
  numpy-base         pkgs/main/win-64::numpy-base-1.16.5-py37hc3f5095_0

The following packages will be UPDATED:

  ca-certificates                               2019.8.28-0 --> 2020.1.1-0
  certifi                                  2019.9.11-py37_0 --> 2019.11.28-py37_0
  openssl                                 1.1.1d-he774522_2 --> 1.1.1d-he774522_3

The following packages will be DOWNGRADED:

  anaconda                                   2019.10-py37_0 --> custom-py37_1

From the above information, we found two problems: one is to report that my environment is inconsistent; the other is that the version of the package to be installed is numpy-base-1.16.5 | py37hc3f5095. In addition, there are related packages of anaconda.

After analyzing for a long time, I still don't know why pip can succeed in conda After that, you can find the reason in the existing environment.

Published 1 original article, praised 0 and visited 21
Private letter follow

Posted by enoyhs on Sun, 02 Feb 2020 22:45:58 -0800