Error while installing keras in conda using pip - python-3.x

Can anyone help here.
I am trying to install keras in conda using pip and I get below error:
(C:\Users\HARSHALL\Anaconda3) C:\Users\HARSHALL>pip install --upgrade keras
Traceback (most recent call last):
File "C:\Users\HARSHALL\Anaconda3\Scripts\pip-script.py", line 6, in
from pip import main
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip_init_.py", line 28, in
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip\vcs\mercurial.py", line 9, in
from pip.download import path_to_url
File "C:\Users\HARSHALL\Anaconda3\lib\site-packages\pip\download.py", line 41, in
from pip._vendor.requests.adapters import BaseAdapter, HTTPAdapter
ImportError: No module named 'pip._vendor.requests.adapters'

Related

Import error while launching PyTorch Lightning project on Colab TPU

I followed this guide to launch my PyTorch Lightning project on Google Colab TPU. So I installed
!pip install cloud-tpu-client==0.10 https://storage.googleapis.com/tpu-pytorch/wheels/torch_xla-1.9-cp37-cp37m-linux_x86_64.whl
Then
!pip install pytorch-lightning
Then I
!pip install torch torchvision torchaudio
!pip install -r requirements.txt
After installing the project requirements, I restarted the runtime as requested and re-ran the cloud-TPU-client install, the pytorch-lightning install, and both command from above. It ran smoothly.
But just after the TPU has started with version PyTorch version 1.9, I get the following import error :
WARNING:root:TPU has started up successfully with version pytorch-1.9
Traceback (most recent call last):
File "synthesizer_train.py", line 2, in <module>
from synthesizer.train import train
File "/content/Real-Time-Voice-Cloning/synthesizer/train.py", line 6, in <module>
from synthesizer.models.tacotron import Tacotron
File "/content/Real-Time-Voice-Cloning/synthesizer/models/tacotron.py", line 7, in <module>
import pytorch_lightning as pl
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/__init__.py", line 20, in <module>
from pytorch_lightning.callbacks import Callback # noqa: E402
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/callbacks/__init__.py", line 14, in <module>
from pytorch_lightning.callbacks.base import Callback
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/callbacks/base.py", line 26, in <module>
from pytorch_lightning.utilities.types import STEP_OUTPUT
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/__init__.py", line 18, in <module>
from pytorch_lightning.utilities.apply_func import move_data_to_device # noqa: F401
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/apply_func.py", line 26, in <module>
from pytorch_lightning.utilities.imports import _compare_version, _TORCHTEXT_AVAILABLE
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/imports.py", line 101, in <module>
from pytorch_lightning.utilities.xla_device import XLADeviceUtils # noqa: E402
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/xla_device.py", line 24, in <module>
import torch_xla.core.xla_model as xm
File "/usr/local/lib/python3.7/dist-packages/torch_xla/__init__.py", line 142, in <module>
import _XLAC
ImportError: /usr/local/lib/python3.7/dist-packages/_XLAC.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN2at13_foreach_erf_EN3c108ArrayRefINS_6TensorEEE
Trainer was launched with the flag TPU_cores=8.
The model had run on CPU and GPU beforehand (ie on another session).
I tried to downgrade PyTorch to 1.9 (the same as the one shown when TPU is starting) because Colab uses torch 1.10.0+cu111 and a different error appeared :
WARNING:root:TPU has started up successfully with version pytorch-1.9
Traceback (most recent call last):
File "synthesizer_train.py", line 2, in <module>
from synthesizer.train import train
File "/content/Real-Time-Voice-Cloning/synthesizer/train.py", line 6, in <module>
from synthesizer.models.tacotron import Tacotron
File "/content/Real-Time-Voice-Cloning/synthesizer/models/tacotron.py", line 7, in <module>
import pytorch_lightning as pl
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/__init__.py", line 20, in <module>
from pytorch_lightning.callbacks import Callback # noqa: E402
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/callbacks/__init__.py", line 14, in <module>
from pytorch_lightning.callbacks.base import Callback
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/callbacks/base.py", line 26, in <module>
from pytorch_lightning.utilities.types import STEP_OUTPUT
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/__init__.py", line 18, in <module>
from pytorch_lightning.utilities.apply_func import move_data_to_device # noqa: F401
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/apply_func.py", line 29, in <module>
if _compare_version("torchtext", operator.ge, "0.9.0"):
File "/usr/local/lib/python3.7/dist-packages/pytorch_lightning/utilities/imports.py", line 54, in _compare_version
pkg = importlib.import_module(package)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.7/dist-packages/torchtext/__init__.py", line 5, in <module>
from . import vocab
File "/usr/local/lib/python3.7/dist-packages/torchtext/vocab/__init__.py", line 11, in <module>
from .vocab_factory import (
File "/usr/local/lib/python3.7/dist-packages/torchtext/vocab/vocab_factory.py", line 4, in <module>
from torchtext._torchtext import (
ImportError: /usr/local/lib/python3.7/dist-packages/torchtext/_torchtext.so: undefined symbol: _ZTVN5torch3jit6MethodE
Is there anything I can do to train the model on TPU ?
Thank you very much
Actually the same problem has also been described and the suggested solution did work for me.
So in the details they suggest to downgrade PyTorch to 1.9.0+cu111 (mind the +cu111) after installing torch_xla.
Consequently here are the steps I followed to launch my Lightning project on Google Colab with TPU :
!pip install cloud-tpu-client==0.10 https://storage.googleapis.com/tpu-pytorch/wheels/torch_xla-1.9-cp37-cp37m-linux_x86_64.whl
!pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchtext==0.10.0 -f https://download.pytorch.org/whl/cu111/torch_stable.html
And then the project's pip :
!pip install torch torchvision torchaudio pytorch-lightning
!pip install -r requirements.txt
And it worked even though after this last step, I had to restart runtime.
Based on above solution, we could additionally fix the issue for sure by finding the version of cuda installed with
import torch
torch.version.cuda
10.2
Based on this cuda version perform this pip install command
!pip install cloud-tpu-client==0.10 torchvision==0.12.0+cu102 torch==1.11.0+cu102 https://storage.googleapis.com/tpu-pytorch/wheels/colab/torch_xla-1.11-cp37-cp37m-linux_x86_64.whl -f https://download.pytorch.org/whl/cu102/torch_stable.html
Pls notice the cu102 in three places in the above command

AttributeError: type object 'h5py.h5.H5PYConfig' has no attribute '__reduce_cython__'

I've tried to reinstall h5py hdp5 etc.
My conda version is 4.9.2 python 3.8.5
Is there anyone with a similar issue ? Is there an alternative to h5py ?
Traceback (most recent call last):
File "D:\X_train.h5\test.py", line 17, in <module>
import h5py
File "C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py", line 34, in <module>
from . import version
File "C:\ProgramData\Anaconda3\lib\site-packages\h5py\version.py", line 17, in <module>
from . import h5 as _h5
File "h5py\h5.pyx", line 1, in init h5py.h5
ImportError: DLL load failed while importing defs: La procédure spécifiée est introuvable.
runfile('D:/X_train.h5/test.py', wdir='D:/X_train.h5')
Traceback (most recent call last):
File "D:\X_train.h5\test.py", line 17, in <module>
import h5py
File "C:\ProgramData\Anaconda3\lib\site-packages\h5py\__init__.py", line 34, in <module>
from . import version
File "C:\ProgramData\Anaconda3\lib\site-packages\h5py\version.py", line 17, in <module>
from . import h5 as _h5
File "h5py\h5.pyx", line 41, in init h5py.h5
AttributeError: type object 'h5py.h5.H5PYConfig' has no attribute '__reduce_cython__'
This is a fixed bug in the h5py's interface.
Try:
pip install --upgrade h5py
You should try:
pip install h5py==2.9
Uninstall all older h5py. Then this command:
conda install -c anaconda h5py
Some packages like tensorflow 2.6 need you to downgrade h5py. Try pip install h5py==3.1
Refer this image:
pip install --upgrade h5py
This will update your package and tell us the right version needed for Tensorflow
pip install h5py==version
In my case, I had TensorFlow 2.5.0 which needed h5py=3.1.0

python3 path only running google-appengine modules

When running django projects with python3 or installing modules with pip, I am getting google-appengine errors, even if my project is not using google appengine.
When running pip3 freeze I get the following results:
andrew#andrew:~/dev/quickistock$ pip3 freeze
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
File "/home/andrew/.local/lib/python3.5/site-packages/pip/__init__.py", line 26, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/home/andrew/.local/lib/python3.5/site-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/home/andrew/.local/lib/python3.5/site-packages/pip/locations.py", line 10, in <module>
from distutils.command.install import install, SCHEME_KEYS # noqa
File "/usr/local/google-cloud-sdk/platform/google_appengine/lib/distutils/distutils/command/install.py", line 258
raise DistutilsOptionError, \
^
SyntaxError: invalid syntax
The file usr/local/google-cloud-sdk/platform/google_appengine/lib/distutils/distutils/command/install.py has lines like this and is compatible with python 2.1. Note. this is not the official google repository but it's accurate:
print "config vars:"
This means that install.py is a python 2 file and you are running pip from python 3. There probably is some incompatibility between them.

Python cannot import name 'NUMPY_MKL'

I am trying to run a wavenet implementation (which uses tensorflow + librosa). However, I keep running into the error "cannot import name 'NUMPY_MKL'".
I have already installed tensorflow, numpy+mk1, scipy and librosa. Tensorflow itself is loading fine, but error is triggered when I run the wavenet implementation which uses librosa.
My spec/details:
Python 3.5.2
Numpy+MK1 (numpy-1.13.1+mkl-cp35-cp35m-win_amd64.whl)
Scipy (scipy-0.19.1-cp35-cp35m-win_amd64.whl)
Windows 10 x64
Nvidia CUDA v8.0 (cudnn 5.1)
Hope you can help. Full error log below:
Traceback (most recent call last):
File "train.py", line 20, in <module>
from wavenet import WaveNetModel, AudioReader, optimizer_factory
File "D:\musicAI\wavenet\__init__.py", line 2, in <module>
from .audio_reader import AudioReader
File "D:\musicAI\wavenet\audio_reader.py", line 7, in <module>
import librosa
File "C:\Python35\lib\site-packages\librosa\__init__.py", line 12, in <module>
from . import core
File "C:\Python35\lib\site-packages\librosa\core\__init__.py", line 108, in <module>
from .time_frequency import * # pylint: disable=wildcard-import
File "C:\Python35\lib\site-packages\librosa\core\time_frequency.py", line 10, in <module>
from ..util.exceptions import ParameterError
File "C:\Python35\lib\site-packages\librosa\util\__init__.py", line 67, in <module>
from .utils import * # pylint: disable=wildcard-import
File "C:\Python35\lib\site-packages\librosa\util\utils.py", line 5, in <module>
import scipy.ndimage
File "C:\Python35\lib\site-packages\scipy\__init__.py", line 61, in <module>
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'
Managed to fixed this by doing a complete uninstall of numpy+mk1, then installing it again.
I was previously doing:
pip install --ignore-install path\numpy.whl
Do this instead to get it working:
pip uninstall numpy # this removes the existing copy
pip install path\numpy.whl # this install the numpy+mk1 from local .whl file

Keras-ImportError: cannot import name ctc_ops

I have Anaconda 4.3.1 installed in my laptop after the commands cd /home/username/anaconda3and source bin/activate ~/anaconda3 my package starts .
And I installed keras using pip3 conda install keras inside my anaconda. package.and made a document named keras.json inside my keras folder.
When I start my Python in anaconda3 and import keras this happens
>>> import keras'
Using TensorFlow backend.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tushar/.local/lib/python3.5/site-packages/keras/__init__.py", line 3, in <module>
from . import activations
File "/home/tushar/.local/lib/python3.5/site-packages/keras/activations.py", line 3, in <module>
from . import backend as K
File "/home/tushar/.local/lib/python3.5/site-packages/keras/backend/__init__.py", line 64, in <module>
from .tensorflow_backend import *
File "/home/tushar/.local/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 6, in <module>
from tensorflow.python.ops import ctc_ops as ctc
ImportError: cannot import name 'ctc_ops'
After following this I could not get any solution. I would appreciate any help.
I had this same exact issue (I was using pip instead of conda to install keras / tensorflow, however). Make sure you have the most up-to-date version of tensorflow (tensorflow-1.0.1 as of March 31st, 2017).
sudo pip install tensorflow --upgrade
fixed the problem for me (I was running tensorflow-0.9.0rc0 before and was getting the same ImportError: cannot import name ctc_ops error as you)

Resources