When I issue an Anaconda prompt conda search pytorch
then I get pytorch installed even issuing conda list command gives me:
pytorch 1.5.1 py3.7_cuda102_cudnn7_0 pytorch
But when I start python on command prompt and then issue import pytorch i get ModuleNotFoundError: No module named 'pytorch'.
Even I tried to do the same after issuing
conda create -n pytorch_env -c pytorch pytorch torchvision
conda activate pytorch_env
conda install -c pytorch pytorch torchvision
as written in Installing PyTorch via Conda but of no use. BTW does it require a restart of the machine after installing Anaconda? Also, let me know how I can use PyTorch in Jupyter notebooks.
Verify the installation with import torch not pytorch. Example code below, source.
from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)
If above throws same issue in Jupyter Notebooks and if you already have GPU enabled, try restarting the Jupyter notebook server as sometimes it requires restarting, user reported.
when I tried to import this package from Jupyter notebook, I got following error message: ModuleNotFoundError: No module named 'torch'. Then, I tried installing Jupyter notebook application from Anaconda navigator for my environment(torch).
Restarted my Jupyter notebook and ran import torch and this time it worked
Otherwise, you need CPU only version of PyTorch.
conda install pytorch torchvision cpuonly -c pytorch
Related
I cannot seem to properly install pytorch on my computer, so here is the background of what I have done:
I had already installed python on my computer and it worked. I used it in Eclipse, using pyDev, so I don't know if that could be the problem. Now I want to install pytorch, so I installed anaconda and entered the command for installing pytorch. To get the right command, I use https://pytorch.org/get-started/locally/, where I tried the options both with and without cuda. In both cases I get an error when I type "import torch".
I have also installed miniconda and tried the same with that without succes. I also tried to work in IDLE in stead of Eclipse, but I keep getting the "no module named 'torch'" error. Each time I run a command in anaconda it appears that the installation is succesfull, but I still can't import 'torch'.
Any idea what the problem could be or what I could try?
Open command prompt or terminal and type:
pip3 install pytorch
If it says pip isn't installed then type: python -m pip install -U pip
Then retry importing Pytorch module
Using anaconda, I think you can check to see if pytorch is properly installed inside your conda environment using conda list inside your environment. If it is shown in the list of installed packages, you can directly try to run python in command line and import torch as in the official Pytorch tutorial:
import pytorch
torch.cuda.is_available()
For IDEs like Eclipse, you need to edit the settings of your project so that it uses the correct conda environment.
Try to create conda-env and reinstall pytorch on conda-env.
Then try to import torch again.
import torch
torch.cuda.is_available()
I'm using anaconda ver 3, and I have installed python as well separately from anaconda. I installed python ver 2.7 and ver 3.6 from python website.
Now, I have installed keras from anaconda command prompt by using conda install keras. However, when I open jupyter notebook and write :
import keras
it says :
no module named keras
I also tried importing tensorflow but it gave me the same error
As far as i know, keras is a version of tensorflow. You should try installing tensorflow instead and then run
import tensorflow as tf
tf.__version__
if you get '2.1.0' or any 2., you should be all set!
EDIT1: Keras is part of tensorflow not a version (as pointed out in the comments).
EDIT2: The link below gives good details on environments activation/creation.
https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
Okay so what I did is first updated anaconda by using :
conda update conda
and then I installed python :
conda install python=3.7
and finally I installed keras again :
conda install keras
And now I can import both packages of keras and tenserflow
In Anaconda Navigator, I switched to running applications on tensorflow and installed jupyter 5.6.0. I then open up a Python3 notebook. I then import tensorflow, keras and numpy without issue. Then when I try to import matplotlib, the notebook says ImportError: No module named 'matplotlib'.
I tried running the following command in my anaconda prompt in both base and after activating tensorflow: pip3 install matplotlib
And it says:
(tensorflow) C:\Users\danie>pip3 install matplotlib
Requirement already satisfied
for 7 different lines. What am I doing wrong?
Add import sys and sys.executable to the top of your notebook, then run it. This shows you the directory of the running kernel. With this information, from a new command-line (not a Python console) run C:\path\to\python.exe -m pip install matplotlib
! pip install matplotlib ,worked perfect for me in the tensorflow environment (Jupyter)
I have already downloaded tensorflow library via Anaconda,but I am unable to launch Spyder inside tensorflow environment, and I also cannot import tensorflow in the Anaconda prompt.
The following are the specifications:
python version : 3.6.1.final.0
platform : win-64
conda version : 4.3.21
conda is private : False
conda-env version : 4.3.21
conda-build version : not installed
requests version : 2.14.2
I get the following error:
File "C:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\util\tf_should_use.py", line 28, in <module>
from backports import weakref # pylint: disable=g-bad-import-order
ImportError: cannot import name 'weakref'
I'm guessing you either:
Followed the installation process for the Python 3.5 version of TensorFlow (unfortunately, the 3.6 process is not currently documented on TensorFlow website).
Followed the right process - but did it through the Windows Command Prompt, and not through Anaconda Prompt (see my answer here why this is bad).
Somehow messed up your Spyder installation.
... or some combination thereof.
Anyway, the following should cover everything:
Open Start --> Anaconda Prompt, and then:
conda create -n tensorflow36 anaconda python=3.6
activate tensorflow36
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.2.0-cp36-cp36m-win_amd64.whl
spyder
Note the conda create command will take a while to finish.
You should now have a shortcut in your Start Menu (under Anaconda group) called "Spyder (tensorflow36)" which you can use to start the right Spyder environment going forward.
Now, to make sure everything installed correctly:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
I had a similar problem when followed the instructions to install Tensorflow in the official website, but Spyder was not recognizing Tensorflow. It said that the module was not installed.
The problem is that Tensorflow and Spyder were installed in different Anaconda environments.
I solved it by changing the environment in Anaconda Navigator and installing Spyder inside the environment I had Tensorflow.
By executing this installation of Spyder i managed to succesfully with Tensorflow.
I understand this may be an old question, but still I cannot find solution from off-the-shelf Q$A. Here is the problem:
I am following Udacity "Machine Learning" and its assignments, and need use iPythonNotebook & tensorflow. Details : https://github.com/Omarito2412/udacity-deeplearning
Assignment2 requires tensorflow. BTW, I already installed Anaconda,
already made tensorflow working on Pycharm on the same computer which is Macbook, but do not know how to make it work on iPythonNotebook environment.
The codes are quite simple, as follows:
import numpy as np
import tensorflow as tf
from six.moves import cPickle as pickle
from six.moves import range
and the error message is as follows:
ImportError Traceback (most recent call last)
<ipython-input-1-0970743dd90d> in <module>()
2 # before proceeding further.
3 import numpy as np
----> 4 import tensorflow as tf
5 from six.moves import cPickle as pickle
6 from six.moves import range
ImportError: No module named tensorflow
Thanks. Any suggestions ?
PS: I have this problem on two MacBooks, and both MacBooks run Pycharm+tensorflow well.
You should deactivate and re-activate the environment
source deactivate tensorflow
source activate tensorflow
After I tried Anaconda-installation (I was using the other installation methods, which are all shown in the link below)
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
It worked ...
Further, on terminal activate tensorflow
>>> source activate tensorflow
before open iPython Notebook
>>> ipython notebook
At last, I have to restart my macbook to make it work....
i have missed tensorflow install (3) number below the list..
now i have solved
for anaconda install
for enviroment install
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
for tensorflow install
https://github.com/conda-forge/tensorflow-feedstock
This is likely due to an anemic environment variable, one of the library path class. I don't know how iPythonNotebook denotes the libraries it will search for files (say, $LD_LIBRARY_PATH), but I believe that you have to find it (a list of paths to libraries) and add the root directory of TensorFlow.
More than likely either Tensorflow is not installed in the right Python environment of Conda or not installed at all. Follow the below steps:
$ conda create -n tensorflow python=3.5
Once that is done, need to activate that as below:
$ source activate tensorflow
Then when you open IPython Notebook or Spyder, it will recognize the Tensorflow.
Run python -m ipykernel install --user --name <Environment_Name>. This should add your environment to the jupyter kernel list.
Change the kernel using Kernel->Change Kernel option or New-><Environment_Name>.