Import error theano "cannot import gof name"
I'm currently getting an error
ImportError: cannot import name gof
when importing theano.
>>> import theano Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> import theano File "C:\Python27\lib\site-packages\theano\__init__.py", line 63, in <module> from theano.compile import ( File "C:\Python27\lib\site-packages\theano\compile\__init__.py", line 9, in <module> from theano.compile.function_module import * File "C:\Python27\lib\site-packages\theano\compile\function_module.py", line 16, in <module> from theano import gof ImportError: cannot import name gof I am using python 2.7.10 (). Theano is installed using pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git . We hope that you will offer a solution to this problem.
In most cases, when I see this error, it is caused by two errors:
1) Syntax error in Theano. Update Theano and make sure that you do not have a local modification. I observed this mistake with Master Teano, but just in case.
2) When several versions of Theano are installed that are installed.
In both cases, uninstall the entire version of Theano. Do this several times to make sure that they are not there. Then install again.
From memory, this always solved the problem when it was not a syntax error during development (but not in the main version of Theano that you are using)
This ImportError may be caused by Theano being unable to compile the gof module gof . If so, you will see an error message that looks like " Exception: Compilation Failed (return status=1): C:\Long\Path\...\mod.cpp:1: sorry, unimplemented: 64-bit mode not compiled in ".
Commit with Conda
If you install theano in a conda environment, make sure you have the C compiler available for that environment.
Team
conda install m2w64-toolchain will provide a C compiler for your environment that is isolated from the rest of the machine.
After the m2w64-toolchain package is installed, import theano should work
Manual Lock
If you install Theano yourself, two points from these topics may help:
- Install the bleeding version of Theano
- Install
libpythonfrom http://www.lfd.uci.edu/%7Egohlke/pythonlibs/
I assume that you are using Windows 7 or later.
If you installed Python Anaconda, open Windows Powershell or Command Prompt and type conda install mingw libpython before entering pip install theano
Alternatively, if you do not have Anaconda, download these packages from
Then open a command prompt, navigate to each folder and enter
python setup.py install
Now run Python and import theano
Possible mistakes:
If you get a RuntimeError: " To use MKL 2018 with Theano, you MUST set" MKL_THREADING_LAYER = GNU "in your environement, " then
Go to Control Panel> System> Advanced System Settings and select "Environment Variables".
In the "System variables" section, enter the new variable name
MKL_THREADING_LAYERand set itsGPUvalue
If you get other kinds of errors, try the following:
Make an empty file named
.theanorc(file extension without file name) in your home folder C: \ Users \ <username>. If you get the error message "You must enter a file name", see https://stackoverflow.com/a/4646/Open
.theanorcand write the following:[global] cxx=C:\<path to Anaconda>\Anaconda3\MinGW\bin\g++.exeRun Python again and import theano. If this works, you can remove
.theanorc