Tensorflow - ImportError: Could not find 'msvcp140.dll' - python-3.x

I am just a beginner to a tensorflow and trying to install TensorFlow with CPU support only.
Initially, I downloaded and installed Python 3.5.2 version from https://www.python.org/downloads/release/python-352/
After successful installation, I ran the command pip3 install --upgrade tensorflow which installed tensorflow-1.8.0.
To test installation i just ran following commands:
> python
> import tensorflow as tf
But this gave me an error:
ImportError: Could not find 'msvcp140.dll'. TensorFlow requires that
this DLL be installed in a directory that is named in your %PATH%
environment variable. You may install this DLL by downloading Visual
C++ 2015 Redistributable Update 3 from this URL:
https://www.microsoft.com/en-us/download/details.aspx?id=53587
I searched for this issue and found link to an issue https://github.com/tensorflow/tensorflow/issues/17393.
According to above i tried running command
pip install tensorflow==1.5
But, this didn't solved my problem.
I even tried downloading msvcp140.dll and manually coping it under C:\Windows\SysWOW64 folder and reinstalling python and tensorflow.
How do I fix this problem.
Thanks in advance.

I copied msvcp140.dll to path C:\Users\PCName\AppData\Local\Programs\Python\Python35
and it worked for me.
I also switched back to tensorflow 1.8 from 1.5.

download msvcp140.dll or click https://www.dll-files.com/msvcp140.dll.html
find your python path
path will find easy from your error
error will show like this
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\sky network\AppData\Local\Programs\Python\Python36\lib\site-
packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\sky network\AppData\Local\Programs\Python\Python36\lib\site-
packages\tensorflow\python\__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\sky network\AppData\Local\Programs\Python\Python36\lib\site-
packages\tensorflow\python\pywrap_tensorflow.py", line 30, in <module>
self_check.preload_check()
File "C:\Users\sky network\AppData\Local\Programs\Python\Python36\lib\site-
packages\tensorflow\python\platform\self_check.py", line 55, in preload_check
% build_info.msvcp_dll_name)
from my error the python path is
"File "C:\Users\sky network\AppData\Local\Programs\Python\Python36"
if u cant find the AppData folder
click folder view option and enable hidden files
paste the file "msvcp140.dll" into
C:\Users\sky network\AppData\Local\Programs\Python\Python36

You can download the package from the url https://www.microsoft.com/en-us/download/details.aspx?id=53587 and install it. This will solve the issue.

Related

CuPy import failing due to missing DLL file although it appears in my directories

I am attempting to use cuPy to speed up some background numpy operations in my python code but when attempting to import cupy I am told that the DLL load failed and the module could not be found, cupy_backends.cuda.libs import nvrtc. (Specific errors at end of post)
I've attempted almost everything the error message suggests. I check my version of cupy and cuda which are cupy-cuda111==8.4.0, I have Cuda 11.2 installed as well. I am running Windows 10 and Python 3.7.6 on Spyder 3. I have tried uninstalling cupy via pip uninstall in hopes of reinstalling correctly but it just hangs and never uninstalls the package.
It appears I have the file its looking for when I go search manually via my file explorer. (Imaged Below)
I am fairly inexperienced when it comes to handling things like this so any help would be greatly appreciated. The entire error message and trace is copied below:
import cupy as cp
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\__init__.py", line 20, in <module>
from cupy import core # NOQA
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\core\__init__.py", line 1, in <module>
from cupy.core import core # NOQA
File "cupy\core\core.pyx", line 1, in init cupy.core.core
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\cuda\__init__.py", line 5, in <module>
from cupy.cuda import compiler # NOQA
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\cuda\compiler.py", line 14, in <module>
from cupy_backends.cuda.libs import nvrtc
ImportError: DLL load failed: The specified module could not be found.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<ipython-input-1-e011b0e859cc>", line 1, in <module>
import cupy as cp
File "C:\ProgramData\Anaconda3\lib\site-packages\cupy\__init__.py", line 41, in <module>
raise ImportError(_msg) from e
ImportError: CuPy is not correctly installed.
If you are using wheel distribution (cupy-cudaXX), make sure that the version of CuPy you installed matches with the version of CUDA on your host.
Also, confirm that only one CuPy package is installed:
$ pip freeze
If you are building CuPy from source, please check your environment, uninstall CuPy and reinstall it with:
$ pip install cupy --no-cache-dir -vvvv
Check the Installation Guide for details:
https://docs.cupy.dev/en/latest/install.html
original error: DLL load failed: The specified module could not be found.

Tensorflow 2.4.0 import error cannot import name 'multi_worker_mirrored_2x1_cpu'

I'm getting an error upon loading tensorflow==2.4.0 in Python. I've tried uninstall and reverting to an earlier version (but still 2), but can't seem to be able to solve it. Anyone any idea? The full error is:
File "<stdin>", line 1, in <module>
File "C:\Users\CX667CJ\AppData\Roaming\Python\Python38\site-packages\tensorflow\__init__.py", line 49, in <module>
from ._api.v2 import __internal__
File "C:\Users\CX667CJ\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\__internal__\__init__.py", line 11, in <module>
from . import distribute
File "C:\Users\CX667CJ\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\__internal__\distribute\__init__.py", line 10, in <module>
from . import combinations
File "C:\Users\CX667CJ\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\__internal__\distribute\combinations\__init__.py", line 20, in <module>
from tensorflow.python.distribute.strategy_combinations import multi_worker_mirrored_2x1_cpu
ImportError: cannot import name 'multi_worker_mirrored_2x1_cpu' from 'tensorflow.python.distribute.strategy_combinations' (C:\Users\CX667CJ\AppData\Roaming\Python\Python38\site-packages\tensorflow\python\distribute\strategy_combinations.py)```
0
I don't know but I opened the adminstrator cmd if don't know just hover over command promp and right click and you'll see the option of open in admistrator mode click over it just uninstall using pip uninstall package_name and don't close because the package_will be cached down and when you again command pip install package_name it should work ,just because it worked for me LOL if you close it you have to download it again like ffpyplayer is of 25 mbs so why to do that
I saw similar issue today
from tensorflow.python.distribute.strategy_combinations import
multi_worker_mirrored_2x1_cpu ImportError: cannot import name
'multi_worker_mirrored_2x1_cpu' from
'tensorflow.python.distribute.strategy_combinations'
(C:\Users\sharm\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\distribute\strategy_combinations.py)
I checked out the file and could not locate 'multi_worker_mirrored_2x1_cpu'.
Looked into tensorflow repo on git. this file was present there.
So I considered reinstalling tensorflow (use virtualenv if you don't), closed my program and restarted everything. I no longer got this issue now.
Also consider,
pip3 install --upgrade tensorflow-gpu --user
version = 2.4.1
Let me know if this resolves your issue as well.

Installation of numpy through Anaconda

getting up to speed on Anaconda, I keep receiving an error message when I try to import 'numpy' into Python.
Here is what I have done so far:
Downloaded anaconda from anaconda.com (64-Bit Graphical
Installer (466 MB) with Python 3.7 for Windows);
Installed anaconda (under C:\Users\'Username'\Anaconda3 | Option 'Register Anaconda3 as my default Python 3.7')
Now I'm trying to import numpy into Python using idle.exe, which produces following error message:
Warning: os.path.expanduser("~") points to
h:\,
but the path does not exist.
Futhermore, after executing "'import 'numpy;" in IDLE I get the following error message.
Unfortunately none of the advice was helpful. Numpy seems to be properly installed.
Warning (from warnings module): File "C:\Users\'Username'\Anaconda3\lib\site-
packages\numpy\__init__.py", line 140
from . import _distributor_init
UserWarning: mkl-service package failed to import, therefore Intel(R) MKL
initialization ensuring its correct out-of-the box operation under condition
when Gnu OpenMP had already been loaded by Python process is not assured.
Please install mkl-service package, see http://github.com/IntelPython/mkl-
service
Traceback (most recent call last):
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\__init__.py",
line 24, in <module>
from . import multiarray
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\multiarray.py",
line 14, in <module>
from . import overrides
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\overrides.py",
line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\'Username'\Anaconda3\Scripts\myscripts\import_test.py", line 1,
in <module>
import numpy
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\__init__.py", line
142, in <module>
from . import core
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\__init__.py",
line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from
"C:\Users\'Username'\Anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
Many thanks in advance for any help and suggestions.

Pip install openslide completes successfully but when I import it "the specified module is not found"

I need to open SVS images in Python 3.7 and it seems that Openslide is the only module capable of opening images of that size (30k*30k pixels). I have used pip install openslide-python as well as python -m pip install openslide-python and pip 3 install... etc.
I know the module has been successfully installed because if I run any of those commands again the command line returns requirement already satisfied however when I run Python and try to import openslide it gives the error at the bottom.
My guess was that the .whl or .tar.gz files were in the wrong path so I made a bunch of copies and put them in the openslide folders within the Anaconda3 folder. The error persists. I have included the full error code below for clarity.
Extra: If I run help("modules") openslide shows up along with numpy, math, sklearn etc. I can import and run all other modules without issue.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\brimk\Anaconda3\lib\site-packages\openslide\__init__.py", line 29, in <module>
from openslide import lowlevel
File "C:\Users\brimk\Anaconda3\lib\site-packages\openslide\lowlevel.py", line 41, in <module>
_lib = cdll.LoadLibrary('libopenslide-0.dll')
File "C:\Users\brimk\Anaconda3\lib\ctypes\__init__.py", line 434, in LoadLibrary
return self._dlltype(name)
File "C:\Users\brimk\Anaconda3\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
My issue was resolved by the answer from my hero!
It seems that, at least for Openslide, running Python from the Path to the Bin is the easiest solution. It can be done this way.
Download the Windows Binary here.
Extract the download to whatever path you want.
Open command window
pip3 install openslide-python (pip2 if Python 2)
cd C:\Users\Path\to\Openslide-Win64-20171122\bin
python
import openslide
In the future you will have to run python from the path to the Openslide bin (Step 4). This can be done more rigorously by adding that file path to the PATH as described in detail here as well as in the answer above.

No module named 'torch' or 'torch.C'

Would appreciate an explanation like I'm 5 simply because I have checked all relevant answers and none have helped.
I have installed Python.
I have installed Pycharm.
I have installed Anaconda.
I have installed Microsoft Visual Studio.
I have not installed the CUDA toolkit.
In Anaconda, I used the commands mentioned on Pytorch.org (06/05/18)
conda install pytorch -c pytorch
pip3 install torchvision
Both have downloaded and installed properly, and I can find them in my Users/Anaconda3/pkgs folder, which I have added to the Python path.
Trying to enter
import torch
in the Python console proved unfruitful - always giving me the same error,
No module named 'torch'
I have also tried using the Project Interpreter to download the Pytorch package. It worked for numpy (sanity check, I suppose) but told me to go to Pytorch.org when I tried to install the "pytorch" or "torch" packages.
When trying to use the console in PyCharm, pip3 install codes (thinking maybe I need to save the packages into my current project, rather than in the Anaconda folder) return me an error message saying
torch-0.4.0-cp35-cp35m-win_amd64.whl is not a supported wheel on this
platform.
The same message shows no matter if I try downloading the CUDA version or not, or if I choose to use the 3.5 or 3.6 Python link (I have Python 3.7)
Currently the closest I have gotten to a solution, is manually copying the "torch" and "torch-0.4.0-py3.6.egg-info" folders into my current Project's lib folder.
However, when I do that and then run "import torch" I received the following error:
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs) File "C:\Users\Michael\PycharmProjects\Pytorch_2\venv\lib\site-packages\torch__init__.py",
line 78, in
from torch._C import *
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.1.2\helpers\pydev_pydev_bundle\pydev_import_hook.py", line 19, in do_import
module = self._system_import(name, *args, **kwargs) ModuleNotFoundError: No module named 'torch._C'
pip uninstall torch
then
pip install torch worked for me.
I encountered the same problem because I updated my python from 3.5 to 3.6 yesterday. I think the connection between Pytorch and Python is not correctly changed. Thus, I installed Pytorch for 3.6 again and the problem is solved.
Check the install command line here[1].

Resources