Tag Archives: anaconda

How to solve “import cv2 failed ImportError: DLL load fail: Cannot find the specified module” in Anaconda environment

First refer to https://blog.csdn.net/wss794/article/details/83119939
conda install -c https://conda.binstar.org/menpo opencv
> > > import cv2
: : ImportError:DLL Load Fail: The specified module was not found
Analysis: the Internet should be found under the Opencv and Python version does not correspond caused.
Solution: reference https://blog.csdn.net/weixin_41679065/article/details/83413498
Uninstall opencV and install it with Anaconda Navigator. No more errors will be reported
Note: The Navigator automatically matches the opencV version that corresponds to the current environment.

ImportError: Importing the multiarray numpy extension module failed.

Numpy of

pycharm suddenly became unavailable. At first, I thought numpy version was a problem. Uninstall, reinstall, upgrade, and degrade were not allowed.

then I tested the numpy of anaconda and found that it could be used, but pycharm could not. However, I checked the setting repeatedly, and there was no problem.

finally put solution : system environment variable Path to the bin level C:\ProgramData\Anaconda3\Library\bin, and then restart the computer.

at first I just introduced Anaconda3, but before using numpy I had no problem, maybe I updated conda, the package is confused, so the environment variable introduced must be bin level.

Anaconda + vscode usage problem summary

anaconda+vscode use problem

1, anaconda environment in vscode can not be used in the problem

  1. installation plug-in
    python and Anaconda Extension Pack
  2. in Anaconda configure corresponding environment
    here in addition to the base I also configure python and tfenv environment, here we take tfenv as an example, we can set the compiler version we want 2.x or 3.x, we can also install the package we want, very convenient.
  3. select our compiler

    > in the lower left corner we can choose which interpreter we want to interpreter. Then, from the middle option that appears, we select the pen-to-last one which is tfenv: Conda environment
  4. to install the corresponding package
    our program needs the matplotlib package, first we install the package in anaconda, as shown in the figure, click apply (we can also install the matplotlib through the corresponding command of anaconda in CMD, we will not go into details here)

    after we install the matplotlib package, we run as shown in the figure, showing “ModuleNotFoundError: “No module named ‘matplotlib’ is mainly because although we chose the corresponding python.exe interpreter, the environment corresponding to tfenv did not import

    . There are two solutions
  • vscode default terminal is generally powershell: powershell solution
  • set terminal to CMD, then activate the tfenv environment with the command activate tfenv, and there will be no problem in running the program
  • The PIP installation package was successful but the import failed

    the problem I ran into was not installing the package in the virtual environment, taking the jieba package as an example

    enter python in the virtual environment, and then you can import the package. We thought it was packaged, but it was actually installed in the basic environment.

    When

    USES conda list to view the packages in the current environment, there is no jieba package.

    conda list

    forgot the screenshot,,,,

    so you need to install jieba using the PIP of the virtual environment.


    after confirming wrapping in a virtual environment, switching to a python environment cannot be done by simply typing python commands. Instead, use virtual environment Python, just like the previous PIP.

    for example, you now have two files, test.py and test.sh.

    test.py

    import torch
    print(torch.__version__)
    

    test.sh

    python test.py

    you can see that the PIP version printed in the virtual environment is different from the one printed in the bash script.

    so while I installed jieba in the pytorch1.4 environment, the command I used directly was not python in pytorch1.4, but python in the base environment.

    summary:

    1. whether the package to the environment
    2. used the python interpreter is not the package environment interpreter

    there are a lot of ways to do it online, so this is a supplement to what’s possible.

    Install PyTorch in Anaconda environment

    download address: https://download.pytorch.org/whl/torch_stable.html

    my CPU is python 3, 7 win10 system corresponding to the following

    2 switch directory

    copies the downloaded WHL file to the site-packages directory in the lib of anaconda.
    directory such as: E:\Anaconda3\Lib\site-packages.

    3 installation
    After

    open the anaconda prompt and switch to the site-packages directory:
    (base) C:\Users\Lenovo> E:
    (base) E:> cd Anaconda3\Lib\site-packages
    (base) E:\Anaconda3\Lib\site-packages> For example, my WHL file name is:
    torch 1.3.0+cpu-cp37-cp37m-win_amd64. WHL

    test: import torch
    no error should be no problem