How do I install Theano and Lasagne in Anaconda (Jupyter)? - python

I have been trying to install Lasagne and Theano in Anaconda (Jupyter) on MacOS Sierra (10.12.3) to use this neural network: neural-storyteller
However when I try to import them in Jupyter:
import lasagne
import theano
I get this error:
ImportError Traceback (most recent call last)
<ipython-input-2-7d877a974cd7> in <module>()
----> 1 import lasagne
2 import theano
//anaconda/lib/python2.7/site-packages/lasagne/__init__.py in <module>()
11 section 'Install from PyPI' in the installation docs for more details:
12 http://lasagne.readthedocs.org/en/latest/user/installation.html#install-from-pypi
---> 13 """)
14 else:
15 del theano
ImportError: Could not import Theano.
Please make sure you install a recent enough version of Theano. See
section 'Install from PyPI' in the installation docs for more details:
http://lasagne.readthedocs.org/en/latest/user/installation.html#install-from-pypi
My guess is that I installed Theano on a different version of python because when I make a normal python file (.py) and import lasagne and theano they work. Also, when I look in the anaconda folder in the User directory there is no theano folder but there is one in the miniconda2 folder (/Users/Pit/miniconda2/pkgs/theano-0.9.0-py27_0).
I could just use a .py file, but I also need the caffe library which I could only get to work with Anaconda python.
Does anybody know how to install the right version of theano that works in Anaconda (Jupyter)?
Any help would be much appreciated

I had faced the same issue. I think it's because Theano installation was not proper. So here is what I did and it started working after that :
In Anaconda Prompt
conda install theano
Follow through the installation. It would probably ask for some confirmations.
Then,
pip install -r https://raw.githubusercontent.com/Lasagne/Lasagne/master/requirements.txt
After that,
pip install https://github.com/Lasagne/Lasagne/archive/master.zip
I think that should do the trick. It started working after that in my case. Restart the kernel once.
For more context : https://pypi.org/project/Lasagne/

You should check which jupyter and which python is being called by using the command:
which python
If you do:
which jupyter
they should be in the same directory. For example:
$:/home/spark : which jupyter
~/anaconda2/bin/jupyter
$:/home/spark : which python
~/anaconda2/bin/python
If they're not the same, then that could explain why you cannot import some libraries (because they're installed under a different python instance).
Unless you need both, I would remove either anaconda or miniconda to make things simpler and less confusing.
Theano works fine with Anaconda and in Jupyter in my experience.

Related

How to install Google Cloud DLP on Mac M1?

I am trying to download Google Cloud DLP on my Mac M1 running macOS Monterey. I am using Python 3.10.4 and pip 22.0.4.
I first tried using pip install google-cloud-dlp, but got an error when I went to import it that I have the wrong architecture (arm instead of x86-64 – hence M1 error).
I then uninstalled DLP and followed the advice of a StackOverflow post to download the library directly from GitHub. I did this, navigated to the directory, and ran sudo python3 setup.py install.
Now, when I try to import the library, I get the error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Input In [57], in <cell line: 1>()
----> 1 import google.cloud.dlp
ModuleNotFoundError: No module named 'google.cloud.dlp'
This is odd because when I run pip list I get this in the output:
google-api-core 2.7.2
google-auth 2.6.6
google-cloud-dlp 3.6.2
googleapis-common-protos 1.56.0
Now, when I run pip install google-cloud-dlp, I get a bunch of "Requirement already satisfied" messages, yet when I try to import, I get a ModuleNotFoundError.
I have tried importing in Atom, VSCode, and Jupyter-Notebook, and still get a ModuleNotFoundError. I feel dumb asking this question because it seems like it would be an easy fix, but any help is appreciated.
One potential issue is that you have multiple python versions installed. Is it possible that the script ran under in a different Python environment than the one used to print the installed versions?
Could you try following these steps?
Create virtualenv.
python3 -m venv env
source env/bin/activate
Install google-cloud-dlp.
pip install google-cloud-dlp
Run code.
$ python3
>>>import google.cloud.dlp
>>>
If you're still having trouble, try the steps on another environment like Cloud Shell to rule out an issue with your specific environment.

ModuleNotFoundError: No module named 'tensorflow' Vs code

I am running on windows 10. I am having problems with importing TensorFlow. I am in Vs code. I installed tensorflow using pip3. And here is the error:
Traceback (most recent call last):
File "c:/Users/USER/PycharmProjects/tt/main.py", line 1, in <module>
import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'
I created my project in pycharm.
I am using python 3.7.5 and TensorFlow 2.0.0. This is how I installed TF:
pip3 install tensorflow==2.0.0
please help I was having this problem for a week.
Thanks , In Advance
For your work/project, please try to create a new virtual environment and then install all your required packages.
Like this:
$ python3 -m venv env
Activate it:
$ source env/bin/activate
and then install the tensorflow package inside your virtual environment:
pip3 install tensorflow
I think you need to create environment separate
and then install tensorflow..
for more information regarding envirnoment Link
Do you have several different python environments on your pc? Which python interpreter are you using when you install tensorflow?
The Status Bar will show you the current interpreter in the lower left corner. Check whether it is the same with the one you use when you install tensorflow.
enter image description here
I was getting your exact error, but this worked for me:
File->settings
Workspace tab
Search for "interpreter"
Put the complete path to the python.exe you want to execute under "default interpreter path"
It seems VSCode either found (or included) an older version of python that couldn't find the things I installed with pip.
I am a bit of a python newb and I'm guessing the venv approach is superior, but I couldn't get that cooperating with VSCode on windows.

Error importing tensorflow (just installed) python 3.7

I have python 3.7 installed on a Windows 10 machine, no custom stuff at all, to install tensorflow I used:
pip3 install --user --upgrade tensorflow
but when I try importing it using:
import tensorflow
in a python script or shell it gives me the following error:
ImportError: DLL load failed: The specified module could not be found.
Am I doing something wrong?
edit: By the way pip version is 20.0.2, I precedently tried with pip 10.x and got the same result.
Regarding https://github.com/tensorflow/tensorflow/issues/35749 or https://github.com/tensorflow/tensorflow/issues/36859 (and the amount of same duplicate issues) there are some recents problems with tensorflow 2.1 for some windows computers.
A fix so far, is to use tensorflow 2.0 on windows :
pip install tensorflow==2.0
For more details, this is quite detailed : https://github.com/tensorflow/tensorflow/issues/36167#issuecomment-577886156

matplotlib can't load ft2font on Windows 10

I'm using Anaconda 5.0.1 with Python 2.7.14. When I open a jupyter notebook and try to run the following:
%matplotlib inline
I get the following error:
ImportError Traceback (most recent call last)
C:\toolkits.win\anaconda2\envs\dlc\lib\site-packages\matplotlib\font_manager.py in <module>()
56
57 import matplotlib
---> 58 from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
59 from matplotlib.compat import subprocess
60 from matplotlib.fontconfig_pattern import (
ImportError: DLL load failed: The specified procedure could not be found.
When I try to drill into the error, the problem is with ft2font:
In [1]: from matplotlib import ft2font
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a32e7826851f> in <module>()
----> 1 from matplotlib import ft2font
ImportError: DLL load failed: The specified procedure could not be found.
I double-checked and made sure freetype is installed:
(dlc) C:\Users\Larry>conda install freetype
Fetching package metadata .............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\toolkits.win\anaconda2\envs\dlc:
#
freetype 2.8 vc9hf582001_0 [vc9]
Any ideas?
conda install freetype --force-reinstall
Improving a bit on the above suggestion:
pip install matplotlib --force-reinstall
def _check_versions():
# Quickfix to ensure Microsoft Visual C++ redistributable
# DLLs are loaded before importing kiwisolver
from . import ft2font
Try install Microsoft Visual C++ redistributable
My solution: unstall matplotlib, and re-install it with pip.
I have the same issue and on my machine the problem was that Java (openJDK) was mentioned in the PATH-variable prior to Python (Anaconda in my case).
If you open a cmd and type
echo %PATH%
you can check if that is the case on your machine as well. If it states ...\Java\openJDK<version>\bin is before the Anaconda directories, the wrong freetype.dll library is getting found and the error occurs.
All you have to do is to change PATH to state the anaconda directories before the Java directories. This may raise another set of issues with Java though...
I found that if conda doesn't activate when the terminal starts up properly, you get this error.
I found that by opening the terminal, typing a bunch of stuff and pressing enter a a lot to prevent conda from activating and then when I tried to run a matplotlib inclusive script it would give me this error, but when I let it start without interference, it would not give me this error (it would run fine, at least past this error).
Considering this, it may be useful to keep import matplotlib at the top of the file if possible, so you don't wait a while and then find out that matplotlib won't load.
I solved this problem by installing the last Microsoft Visual C++ redistributable 2019.
In my case :
python 3.8.7
matplotlib : 20.3.3
test.py
result in IDLE
Debugged into same issue. It seems another access-deny issue.
Solution: Re-install matplotlib in elevated mode.
Launch Anaconda Prompt as Administrator
Run conda install matplotlib
Finish installing any required packages.

ModuleNotFoundError: No module named 'tensorflow'?

I got this error in Jupyter Notebook.
this may duplicate post but no any proper answer found
Neither below links helped me to solve this.
No module named tensorflow in jupyter
No module named tensor flow -- iPython notebook
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-b88de1945047> in <module>()
1 get_ipython().magic('matplotlib inline')
2 import numpy as np
----> 3 import tensorflow as tf
4 from tensorflow.contrib import rnn
5 import data_loader
ModuleNotFoundError: No module named 'tensorflow'
B:S -
enter image description here
I faced the same problem at first. I realized that in the conda-->envs -->
tensorflow-->Scripts-->idle.exe, is the python 3.5.5 shell. Where you can import tensorflow without any problems. So, I chaged the directory as C:\Users\Temp\Anconda3..... and then activated and deactived the tensorflow once. In the next step I entered the python mode and import tensorflow as tf worked right.
I had the same problem and I think I've found the solution!
See, I had installed both CPU and GPU versions of Tensorflow at the same time which apparently is wrong. Then, I uninstalled the GPU version, it didn't work this time either. So I uninstalled both of them and reinstalled the CPU version. It's working now.
BTW I'm on Win10(1803) and python 3.6.5 (not using anaconda.)
You can execute the following instructions and command to solve the issue: (do not include inverted commas)
Open Anaconda Prompt
type: "create --name py3-TF2.0 python = 3"
press "y" to continue
After successful completion:
type "conda activate py3-TF2.0"
type "pip install matplotlib"
type "pip install tensorflow==2.1.0"
type "conda deactivate"
type "pip install ipykernel"
type "conda install nb_conda_kernels"
Now exit the Anaconda prompt and open the Anaconda Navigator application. Switch to "py3-TF2.0" from the base environment using the Environment tab. Install Jupyter in the specified environment.
After successful installation, open Jupyter notebook and switch to "py3-TF2.0" kernel using Kernel Tab.
You're good to go for using TensorFlow 2.
Make Sure you use Anaconda 2020.02 or lower version.
As new version does not support TensorFlow 2.

Categories