I am using windows 10 OS with Python 3.5.
I am trying to run a program related to torch. So I installed Pytorch with the help of the instructions specified on their website: Pytorch installation
See the following image for selection of the downloadable:
I installed it using :
pip install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp35-cp35m-win_amd64.whl
pip install torchvision
I have encountered the following error:
Error
Traceback (most recent call last):
File "C:\Python35\lib\site-packages\twisted\trial\runner.py", line 701, in findByName
__import__(name)
File "C:\Users\aims\Desktop\CNN\source\cnn4matrix.py", line 4, in <module>
import torch
File "C:\Python35\lib\site-packages\torch\__init__.py", line 78, in <module>
from torch._C 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:\Python35\lib\site-packages\twisted\trial\runner.py", line 803, in loadByName
return self.suiteFactory([self.findByName(name, recurse=recurse)])
File "C:\Python35\lib\site-packages\twisted\trial\runner.py", line 704, in findByName
return self.loadFile(_name, recurse=recurse)
File "C:\Python35\lib\site-packages\twisted\trial\runner.py", line 674, in loadFile
module = SourceFileLoader(name, fileName).load_module()
File "<frozen importlib._bootstrap_external>", line 385, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 806, in load_module
File "<frozen importlib._bootstrap_external>", line 665, in load_module
File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\aims\Desktop\CNN\source\cnn4matrix.py", line 4, in <module>
import torch
File "C:\Python35\lib\site-packages\torch\__init__.py", line 78, in <module>
from torch._C import *
ImportError: DLL load failed: The specified module could not be found.
After searching a lot I couldn't found anything related. Instead I found that I have tried: Reinstall with upgrade mode, the numpy library.
Please let me know what I can try.
EDITED:
This is the scenario for me: I have install torch from the website instructions and then opened python terminal. just written import torch and the issue is what I got. Have a look at the image: https://ibb.co/fL53HT
Please see this following thread:
https://github.com/pytorch/pytorch/issues/574
Basically, the problem might be that you have a folder called 'torch' in the same directory from where you are invoking python. So instead of the pytorch library being loaded, the folder named 'torch' is being picked up.
Do this: cd .. (to change directory), and then start python and import torch, it should work.
the one solution here if doesn't work after reinstalling Anaconda, then you can use sth. like Dependency Walker, open
[Anaconda PATH]\Lib\site-packages\torch\lib\_C.pyd
to detect what's wrong there.
and the other solution is caused by the directory torch which is generated in the same directory by compiling the source. try to simply changing the directory before open python.
Related
I am using sounddevice in my project running on Ubuntu - When I build a single file using pyinstaller it is failing with (The code works well when running the source python file):
Traceback (most recent call last):
File "Run_SD.py", line 2, in <module>
File "Smart_Device.py", line 26, in init Smart_Device
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller/loader/pyimod03_importers.py", line 540, in exec_module
File "sounddevice.py", line 71, in <module>
OSError: PortAudio library not found
[213] Failed to execute script Run_SD
Unfortunately I can't simply apt get install the required portaudio on the machine, so it needs to be included in the package. I have tried adding in the lib using:
--add-binary libportaudio.so:. --add-binary libportaudio.a:.
But this isn't working. I'm guessing I need to actually import the portaudio library into my python source - is that correct? Any pointers on how to do this?
I fixed this problem by editing:
versions/3.8.5/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-sounddevice.py
elif is_linux:
path = os.path.join(
sfp[0], "_sounddevice_data", "portaudio-binaries", "libportaudio.so"
)
versions/3.8.5/lib/python3.8/site-packages/sounddevice.py
elif _platform.system() == 'Linux':
_libname = 'libportaudio.so'
Then included the libportaudio.so in the pyinstaller build:
--add-binary _sounddevice_data/portaudio-binaries/libportaudio.so:./_sounddevice_data/portaudio-binaries/
This question already has answers here:
Getting error Bad File Descriptor while installing pip
(6 answers)
Closed 6 months ago.
One time I tried to install pygame with pip, but it doesn't find pip.
can't open file 'pip' [errno 2] no such file or diretory
when I do "py pip install pygame"
So I tried reinstalling python like 4 times, and tried almost all the possible installation ways but it doesn't work. So I tried installing pip manually, I tried all possible ways but have the same error:
[errno 9]: bad file descriptor.
I tried many times.
So after that I tried to install via pycharm when I try to install it shows "no package installation tools, install" and when I click on install, it shows the same error.
[errno 9]: bad file descriptor.
After this I tried using poetry but when I do poetry install win10toast it shows:
Traceback (most recent call last):
File "C:\Users\acer\.poetry\bin\poetry", line 16, in <module>
from poetry.console import main
File "C:\Users\acer\.poetry\lib\poetry\console\__init__.py", line 1, in <module>
from .application import Application
File "C:\Users\acer\.poetry\lib\poetry\console\application.py", line 5, in <module>
from .commands.about import AboutCommand
File "C:\Users\acer\.poetry\lib\poetry\console\commands\__init__.py", line 4, in <module>
from .check import CheckCommand
File "C:\Users\acer\.poetry\lib\poetry\console\commands\check.py", line 1, in <module>
from poetry.factory import Factory
File "C:\Users\acer\.poetry\lib\poetry\factory.py", line 21, in <module>
from .repositories.pypi_repository import PyPiRepository
File "C:\Users\acer\.poetry\lib\poetry\repositories\pypi_repository.py", line 9, in <module>
from cachecontrol import CacheControl
File "C:\Users\acer\.poetry\lib\poetry\_vendor\py3.8\cachecontrol\__init__.py", line 9, in <module>
from .wrapper import CacheControl
File "C:\Users\acer\.poetry\lib\poetry\_vendor\py3.8\cachecontrol\wrapper.py", line 1, in <module>
from .adapter import CacheControlAdapter
File "C:\Users\acer\.poetry\lib\poetry\_vendor\py3.8\cachecontrol\adapter.py", line 5, in <module>
from requests.adapters import HTTPAdapter
File "C:\Users\acer\.poetry\lib\poetry\_vendor\py3.8\requests\__init__.py", line 112, in <module>
from . import utils
File "C:\Users\acer\.poetry\lib\poetry\_vendor\py3.8\requests\utils.py", line 27, in <module>
from ._internal_utils import to_native_string
File "C:\Users\acer\.poetry\lib\poetry\_vendor\py3.8\requests\_internal_utils.py", line 11, in <module>
from .compat import is_py2, builtin_str, str
File "C:\Users\acer\.poetry\lib\poetry\_vendor\py3.8\requests\compat.py", line 61, in <module>
from http.cookies import Morsel
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 779, in exec_module
File "<frozen importlib._bootstrap_external>", line 915, in get_code
File "<frozen importlib._bootstrap_external>", line 973, in get_data
OSError: [Errno 9] Bad file descriptor
Please help, everything I do just fails and I really need it, coding on repl.it is really hard.
I had the same error and checked for the solution in google in fact i even visited this page too. But before few minutes I found the solution for this error. And here you go with the answer.
Just install python in any other directory(other than the c drive).
This should probably work.
I'm working on a Django project which requires Python3.7.3 virtual environment on Ubuntu 16.
So I created a virtual environment and installed all the requirements in it and verified it, activated it.
But when I try to run the Django server using runserver it is giving me below error.
Traceback (most recent call last):
File "/usr/lib/python3.7/decimal.py", line 3, in <module>
from _decimal import *
ModuleNotFoundError: No module named '_decimal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "./interfaces/control/manage.py", line 8, in <module>
execute_from_command_line(sys.argv)
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 224, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/path/lib/python3.7/site-packages/django/core/management/__init__.py", line 36, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/path/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/path/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 10, in <module>
from django.core.servers.basehttp import (
File "/home/path/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 17, in <module>
from django.core.handlers.wsgi import LimitedStream
File "/home/path/lib/python3.7/site-packages/django/core/handlers/wsgi.py", line 8, in <module>
from django.core.handlers import base
File "/home/path/lib/python3.7/site-packages/django/core/handlers/base.py", line 7, in <module>
from django.urls import get_resolver, set_urlconf
File "/home/path/lib/python3.7/site-packages/django/urls/__init__.py", line 1, in <module>
from .base import (
File "/home/path/lib/python3.7/site-packages/django/urls/base.py", line 4, in <module>
from django.utils.encoding import iri_to_uri
File "/home/path/lib/python3.7/site-packages/django/utils/encoding.py", line 4, in <module>
from decimal import Decimal
File "/usr/lib/python3.7/decimal.py", line 8, in <module>
from _pydecimal import *
File "/usr/lib/python3.7/_pydecimal.py", line 436, in <module>
import contextvars
File "/usr/lib/python3.7/contextvars.py", line 1, in <module>
from _contextvars import Context, ContextVar, Token, copy_context
ModuleNotFoundError: No module named '_contextvars'
Note that it is first going to Django project in my virtualenv here.
/home/path/lib/python3.7/site-packages/django/core/management/__init__.py
Again it is searching in the global location of python here.
/usr/lib/python3.7/_pydecimal.py
Can someone please let me know why it is going to the global location and throwing the error.
The issue was with Global Python interpreter itself.
I followed Installing Python 3.7 on Ubuntu from Source in https://linuxize.com/post/how-to-install-python-3-7-on-ubuntu-18-04/ for installing Python 3.7.
Somehow it is not installing all the required packages for python interpreter.
Everything works fine if I install using Installing Python 3.7 on Ubuntu with Apt.
In my case, the python version installed in the virtual environment was 3.7.2 and the only version I had in my Computer was 3.7.3. So, I reinstalled the version 3.7.2 and it worked.
Hope it works for you !!!
For me, I checked in the location and found out that somehow my requirements.txt had changed Werkzeug to 1.5x version. So I reverted those changes, which fixed my issue.
Try this.
pip3 install Werkzeug==2.0.1
I have freshly installed windows 10 and I am trying to run the following code.
import pyttsx3;
engine = pyttsx3.init();
engine.say("I will speak this text");
engine.runAndWait() ;
This use to work on my previous windows 10 installation but now it is giving me following error
Traceback (most recent call last):
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\__init__.py", line 44, in init
eng = _activeEngines[driverName]
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/ayush/Desktop/sample.py", line 2, in <module>
engine = pyttsx3.init();
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\__init__.py", line 46, in init
eng = Engine(driverName, debug)
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\driver.py", line 75, in __init__
self._module = importlib.import_module(name)
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
import win32com.client
File "C:\Users\ayush\AppData\Local\Programs\Python\Python36\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: %1 is not a valid Win32 application.
I am using python 3.6.6 64 bit on windows 10.
I have spent many hours trying different solutions like reinstalling python, tried python versions 3.5 and 3.7, reinstalling pyttsx3, also tried solutions given in few related questions but nothing is working.
Thanks in advance
Seems like win32api.pyd (which really is DLL) is not a win32 application. So I think it's loading 64bit drivers to 32bit runtime.
In this case, I will try to uninstall 64bit python, delete it's folder and install a 32bit version. I believe this will solve your problem, since you don't really need 64bit python.
Now the problem is in win32*.pyds, so it seems like your pyttsx3 is 32bit.
According to pypi.org, you can try pip install pypiwin32 to fix both win32 and win32api errors.
I tried installing Python 32 bits but customized with all options available such as a complete library, doing this worked wonders in breaking the errors! Just lauch the .exe launcher again, hit Modify and then just install every option!
I am trying to install TensorFlow (not GPU version) on Windows 7. I have installed Python 3.5.2, which I can verify:
$ python --version
Python 3.5.2
I installed TensorFlow using the following command, and it seemed to work:
$ pip3 install --upgrade tensorflow
But when I enter the Python shell to validate the installation, I get this error:
>>> import tensorflow as tf
Traceback (most recent call last):
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
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\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\__init__.py", line 24, in <module>
from tensorflow.python import *
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\__init__.py", line 51, in <module>
from tensorflow.python import pywrap_tensorflow
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 18, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 577, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 906, in create_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
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\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 21, in <module>
_pywrap_tensorflow_internal = swig_import_helper()
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 20, in swig_import_helper
return importlib.import_module('_pywrap_tensorflow_internal')
File "C:\Users\kimlesj1\AppData\Local\Programs\Python\Python35\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: No module named '_pywrap_tensorflow_internal'
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
In my case, either cudnn v5 or v6 cannot work alone. I looked into the self check script, it seems that the proper installation of both cudnn64_5.dll and cudnn64_6.dll are checked:
cudnn5_found = False
try:
cudnn5 = ctypes.WinDLL("cudnn64_5.dll")
cudnn5_found = True
except OSError:
candidate_explanation = True
print("""
- Could not load 'cudnn64_5.dll'. The GPU version of TensorFlow
requires that this DLL be installed in a directory that is named in
your %PATH% environment variable. Note that installing cuDNN is a
separate step from installing CUDA, and it is often found in a
different directory from the CUDA DLLs. You may install the
necessary DLL by downloading cuDNN 5.1 from this URL:
https://developer.nvidia.com/cudnn""")
cudnn6_found = False
try:
cudnn = ctypes.WinDLL("cudnn64_6.dll")
cudnn6_found = True
except OSError:
candidate_explanation = True
if not cudnn5_found or not cudnn6_found:
print()
if not cudnn5_found and not cudnn6_found:
print("- Could not find cuDNN.")
elif not cudnn5_found:
print("- Could not find cuDNN 5.1.")
else:
print("- Could not find cuDNN 6.")
print("""
The GPU version of TensorFlow requires that the correct cuDNN DLL be
installed
in a directory that is named in your %PATH% environment variable. Note
that
installing cuDNN is a separate step from installing CUDA, and it is often
found in a different directory from the CUDA DLLs. The correct version of
cuDNN depends on your version of TensorFlow:
* TensorFlow 1.2.1 or earlier requires cuDNN 5.1. ('cudnn64_5.dll')
* TensorFlow 1.3 or later requires cuDNN 6. ('cudnn64_6.dll')
if either v5 or v6 is not found in Path, an OSError will occur. So I put both in my Path environment variable, and the check passed.
This is a known issue while installing tensorflow-gpu.
If you are using conda the best way to solve this problem is by doing a conda installation of tensorflow-gpu. The steps are given below. (Tested in both Windows 10 and Ubuntu 16.04)
Uninstall existing installation of tensorflow-gpu
pip uninstall tensorflow-gpu
Then install the tensorflow-gpu using conda
conda install tensorflow-gpu
This should install tensorflow-gpu in your conda environment with all the dependencies.
If you are not using anaconda distribution of python, you may try using the correct versions of cudatoolkit, CuDNN and python. A list of common errors and their corresponding github threads with solutions can be found here.
https://www.tensorflow.org/install/errors
I would recommend you to use conda install than pip install if you don't want to spent much time on figuring out what went wrong and how to fix it.
The script tensorflow_self_check.py works perfectly in my case. It points out that I miss the file cudnn64_6.dll of cuDNN v6. It is important to notice that in the official guide of TensorFlow for Window (https://www.tensorflow.org/install/install_windows), they insist that it must be cuDNN v5.1 with cuDNN64_5.dll ! They should update this guide by adding this tensorflow_self_check.py script.
EDIT: I should read carefully the release note of TensorFlow 1.3.0 https://github.com/tensorflow/tensorflow/blob/r1.3/RELEASE.md: "All our prebuilt binaries have been built with cuDNN 6. We anticipate releasing TensorFlow 1.4 with cuDNN 7."