AttributeError: module 'theano' has no attribute 'ifelse' - keras

I am installing anaconda environment with keras, and using theano backend. But I cannot get theano to work. here is what I have done and also errors noted afterwards.
Step 1: download the latest version of anaconda, then install in linux by ' bash Anaconda3-5.0.1-Linux-x86_64.sh'
Step 2: conda install -c conda-forge keras, which installs keras 2.0.9
This also installs theano 1.0.1, as shown below:
The following NEW packages will be INSTALLED:
keras: 2.0.9-py36_0 conda-forge
libgpuarray: 0.7.5-0 conda-forge
mako: 1.0.7-py36_0 conda-forge
pygpu: 0.7.5-py36_0 conda-forge
theano: 1.0.1-py36_1 conda-forge
The following packages will be SUPERSEDED by a higher-priority channel:
conda: 4.3.30-py36h5d9f9f4_0 --> 4.3.29-py36_0 conda-forge
conda-env: 2.6.0-h36134e3_1 --> 2.6.0-0 conda-forge
Next, testing theano:
python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
>>> theano.ifelse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'theano' has no attribute 'ifelse'
The error shown in the last line is preventing me using theano and keras properly. all my code that works on a different platform does not work, because they will generate an error like that.
I also tried to follow instructions on http://deeplearning.net/software/theano/install_ubuntu.html with a fresh anaconda installation to just install theano, without keras. But after installation, with the testing line above, I get the same error.
Any suggestion on how to fix this?

It is not import by default.
Try to use
import theano.ifelse

Related

"no module named torch". But installed pytorch 1.3.0 with conda in Ubuntu 18.04.02 Server Edition

installed pytorch with conda :
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda install
pytorch torchvision cpuonly -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
I updated conda:
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda update
conda
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
Installed mkl=2019 :
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda install
mkl=2019
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda list | grep
torch
cpuonly 1.0 0 pytorch
facenet-pytorch 0.1.0 pypi_0 pypi
pytorch 1.3.0 py3.7_cpu_0 [cpuonly] pytorch
torchfile 0.1.0 pypi_0 pypi
torchvision 0.4.1 py37_cpu [cpuonly] pytorch
But it still says "no module torch" :
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ python3
Python 3.8.0 (default, Oct 30 2019, 16:20:23)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>>
I discovered that the problem appears only with python 3.8.0 version
(base) marco#pc:~/facenet_pytorch$ python3
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>
Ubuntu 18.04.02 Server Edition
Or, may be, it's just a matter of python environments, as you said.
But I do not understand why just activating conda environment, with "conda activate", it doesn't work
Marco
First create a Conda environment using:
conda create -n pytorch_env python=3 ( you can create with any python version )
Activate the environment using:
conda activate pytorch_env
Now install PyTorch using:
conda install pytorch-cpu torchvision -c pytorch
Go to python shell and import using the command:
import torch
Thanks all for your kind answers.
I solved the problem
- first, "downgrading" python from 3.8.0 to 3.7.3 because I checked in PyTorch's chat environment that PyTorch is not yet compatible with python 3.8.0
- and then, after removing everything already installed, installing the latest version of PyTorch via cunda, as you kindly explained
Pytorch can be installed via pip and conda. For that, you need to create a separate conda environment. Thus, it will not corrupt the base environment.
Steps to create a new conda environment as follows:
conda create -n conda_pytorch python=3.6
source activate conda_pytorch
Follow the below command to install pytorch via pip:
pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
Pytorch installation via conda:
conda install pytorch torchvision cpuonly -c pytorch
Verify the pytorch installation in the python shell using:
import torch

ModuleNotFoundError when importing package that is installed in conda environment

Unable to import flask-migrate dependencies that are missing python version/sub-version from build version (3rd column of conda list output).
Flask-migrate was installed from conda-forge using:
conda install -c conda-forge flask-migrate
Several dependencies were installed simultaneously and are found in conda list -n venv but cannot be imported to python.
(venv) C:\Users\Colin\Documents\Projects\microblog>python
Python 3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import alembic
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'alembic'
From what I have found, the packages that are raising ModuleNotFoundErrors upon import are all missing the python version in the 3rd column of conda list.
Successfully import: py36_0 or py36_1000 or py36* etc.
ModuleNotFoundError: py_0 or py_1
Why are installed packages raising ModuleNotFoundError when imported to python?
I believe the packages with py_0 environment were all installed as Noarch packages from conda. I'm not sure why my system is unable to import the Noarch packages but I was able to work around the problem by manually downloading the win64-py36_0.tar.bz2 files and installing them locally using:
conda install /package-path/package-filename.tar.bz2

Linux pyarrow undefined symbol

I am running Python 3.7.2 and using Miniconda3 to create a new environment named test-env. I have installed the pyarrow package from the default channel into this environment; however, when I try and import pyarrow, the Python interpreter gives me an undefined symbol error:
Import Error: /test-env/lib/python3.7/site-packages/pyarrow/lib.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZNK5arrow6Status8ToStringB5cxx11Ev
From other threads on SO, I gather that this is due to a compiler incompatibility. I'm not a developer so I'm not sure how to fix this.
I had the same error after I installed by conda install, after I conda uninstall, I did pip install, the issue went away.
>>> import pyarrow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dv6/anaconda3/envs/spark/lib/python3.6/site-
packages/pyarrow/__init__.py", line 54, in <module>
from pyarrow.lib import cpu_count, set_cpu_count
ImportError: /home/dv6/anaconda3/envs/spark/lib/python3.6/site-
packages/pyarrow/lib.cpython-36m-x86_64-linux-gnu.so: undefined symbol:
_ZNK5arrow5Field8B5cxx11Ev
>>> quit()
Then I conda uninstall
(spark) dv6#dv6:~$ conda uninstall pyarrow
Then I pip install
(spark) dv6#dv6:~$ pip install pyarrow --user
Collecting pyarrow
Downloading pyarrow-0.16.0-cp36-cp36m-manylinux2014_x86_64.whl (63.1 MB)
|████████████████████████████████| 63.1 MB 25 kB/s
Requirement already satisfied: numpy>=1.14 in
./anaconda3/envs/spark/lib/python3.6/site-packages (from pyarrow) (1.18.1)
Requirement already satisfied: six>=1.0.0 in
./anaconda3/envs/spark/lib/python3.6/site-packages (from pyarrow) (1.14.0)
Installing collected packages: pyarrow
Successfully installed pyarrow-0.16.0
(spark) dv6#dv6:~$ python -c "import pyarrow"
(spark) dv6#dv6:~$
Here is my Python version
(spark) dv6#dv6:~$ python
Python 3.6.10 |Anaconda, Inc.| (default, Jan 7 2020, 21:14:29)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
I would recommend opening a ticket at https://issues.apache.org/jira/projects/ARROW/issues/ARROW-4774?filter=allopenissues
Provide how you installed pyarrow (pip or conda), which distribution of linux. If you can reproduce this in a clean environment, even better.

conda update sklearn - does not update

I am using anaconda python
conda --v
conda 4.3.25
I am trying to update sklearn package. I followed instructions from here:
conda update scikit-learn (also scipy and numpy). When I try to install the packages, it shows that it is installing sklearn 0.19
conda install scikit-learn
The following NEW packages will be INSTALLED:
numpy: 1.13.1-py27_0
scikit-learn: 0.19.0-np113py27_0
scipy: 0.19.1-np113py27_0
Proceed ([y]/n)? y
However, when I check package version, it still shows 0.15
import sklearn
sklearn.__version__
'0.15.2'
I further created environment in python.
$conda create -n sklearn python=2.7 anaconda
it shows below:
The following NEW packages will be INSTALLED:
scikit-image: 0.13.0-np112py27_0
scikit-learn: 0.18.1-np112py27_1
source activate sklearn
$python
Python 2.7.13 |Anaconda 4.4.0 (x86_64)| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import sklearn
>>> sklearn.__version__
'0.15.2'
Further, when I looked at packages in pycharm I see both 15.2 and 19.1. Please see attached screenshot.
How to resolve this?
I see that packages get installed in to folder ./local/lib/python2.7/site-packages. Is this expected with Conda?
I found that there was a conflict of conda package folder with pip installation folder. I checked for paths using
import sys
print sys.path
and found that pip installation folder has precedence over conda folder.
Deleting the pip installation folder solved this.

Something wrong with scikits.talkbox with Python3?

I am migrating a Python program from 2.10 to 3.6. The packages scikits.talkbox is part of it. However, I cannot figure out how to use it any more. The installation from pip seems to work fine but I cannot import it. Has anyone faced this problem before ?
[manjaro#manjaro-pc ~]$ python --version
Python 3.6.0
[manjaro#manjaro-pc ~]$ sudo pip install scikits.talkbox
Collecting scikits.talkbox
Using cached scikits.talkbox-0.2.5.tar.gz
Requirement already satisfied: numpy in /usr/lib/python3.6/site-packages (from scikits.talkbox)
Installing collected packages: scikits.talkbox
Running setup.py install for scikits.talkbox ... done
Successfully installed scikits.talkbox-0.2.5
[manjaro#manjaro-pc ~]$ python
Python 3.6.0 (default, Jan 16 2017, 12:12:55)
[GCC 6.3.1 20170109] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import scikits.talkbox
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.6/site-packages/scikits/talkbox/__init__.py", line 5, in <module>
__all__ += tools.__all__
AttributeError: module 'tools' has no attribute '__all__'
The answer to your question is this link Error while importing scikits.talkbox
Even I am facing this issue
I have switched to librosa
There is another way for MFCC features: python_speech_features
http://python-speech-features.readthedocs.io/en/latest/

Resources