I follow the notes and practice Neural Networks on jupyter notebook python,
At first I'm having problem with import tensorflow as tf
and then I look up on youtube and created new environment called tf in Anaconda Navigator and install tensorflow and keras.
enter image description here
Next note that I follow is
**from visualization import draw_nn_graph**
when i use this code, it shows **ModuleNotFoundError: No module named visualization**
i open command prompt and type **pip install visualization** in Command Prompt and it says succesfully installed, but it still cannot run. I need help
Since you mentioned the command prompt in the comments, I assume that you are on Windows. What is happening here is that you have two separate Python installations: one "normal", directly installed on Windows, and the Anaconda one. When you ran the pip install command in the prompt, you installed the module for the normal version, but since Jupyter is using the Anaconda install it cannot find it.
This image shows you an example of this. The right window is my command prompt, and it does not know Python since I did not install it. However, I have Anaconda installed, and with it comes a tool called Anaconda Prompt. You can see it on the left, that one knows Python. You should have this Anaconda prompt as well. Search for it in the start menu, run your pip install there and your problem should be fixed.
the question solved by
!pip install visualization; in the Jupyter Notebook in environment called tf that I created
Related
In a conda environment with Python 3.8.15 I did
pip install ultralytics
successfully installed ...,ultralytics-8.0.4
But when running from ultralytics import YOLO , it says
ModuleNotFoundError: No module named 'ultralytics'
I run using Colab.
First I install Ultralytics using pip command
!pip install ultralytics
then
from ultralytics import YOLO
and it worked.
Were you using Jupyter notebook? if so, jupyter might not using the correct python interpreter. Or you're using jupyter that installed on system instead of jupyter installed inside a conda environment.
To check which python jupyter use this code on a cell:
import sys
print(sys.executable)
To list all installed python interpreter available. use this command:
!which -a python
The python inside the conda environment should be on the path something like this:
~/.conda/envs/{myenv}/bin/python
To use correct interpreter inside a conda environment you need to use separate jupyter installation inside the conda environment. see this answer: How to use Jupyter notebooks in a conda environment?
You can use magic %pip install from a cell inside the notebook to insure the installation occurs in the environment that the Jupyter notebook kernel is using. Mikhael's answer points out the thorough way to be really sure how to deal with this and fully control things. However, it is nice to have convenient, quick alternatives when trying to get past a hurdle.
For those using actual Jupyter anywhere (not Google Colab), the install command would be:
%pip install ultralytics
Be sure to let the installation process fully depending on your system and network this can take a bit. Next, after running any magic install command, you'll see a message to restart the kernel, and it is always best to do that before trying the import statement. Finally, after restarting the kernel you can run the suggest import after of from ultralytics import YOLO and hopefully not encounter ModuleNotFoundError: No module named 'ultralytics' now.
The magic command was added to insure that installation occurs in the environment where the kernel backing the notebook is found. See here for more about the modern magic install commands in Jupyter. (For those using conda/Anaconda/mamba as the primary package manager for when packages have conda install recipes, theres a related %conda install variation that also insures installation to the proper environment that the kernel is using.)
See JATIN's answer if you are using Google Colab at this time. Because I don't believe Google Colab has the magic pip install as they have sadly not kept up with current Jupyter abilities.
The exclamation point use in conjunction with pip install is outdated for typical Jupyter given the addition of the magic command. Occasionally, the exclamation point not insuring the the install occurs in the same environment wherein the kernel is running could lead to issues/confusion, and so the magic command was added a few years ago to make installs more convenient. For more about the shortcoming of the exclamation point variant for this particular task, see the first sentence here.
In fact, these days no symbol is better than an exclamation point in front of pip install or conda install when running such commands inside a vanilla Jupyter notebook. No symbol being even better than an exclamation typically now is due to automagics being enabled by default on most Jupyter installations. And so without the symbol, the magic command variant will get used behind-the-scenes. Typically, it is better to be explicit though and use the magic symbol, but you may see no symbol work or be suggested and wonder what is happening.
I need to use the command line in Jupyter Notebook in a virtual environment, but the commands don't execute in the environment itself. I'm using Anaconda Navigator to open Jupyter Notebook. For background, I use a Mac.
Whenever I do something like ! pip install xyz, it installs the package in the Anaconda directory for libraries (see the image). I made sure that the kernel is in the environment, so that's not the problem.
What's interesting is that if I try to import a package, I can only import packages from the environment itself, not the Anaconda libraries. In other words, installing packages doesn't occur in the environment, but importing packages does.
Image that shows the pip install
This wouldn't matter that much because I could download packages in the Terminal itself, but I also need to do things like in the image below in my virtual environment, which is not possible to do in the Terminal (or is it?).
Example of what I need to do
Any ideas on how to fix this?
EDIT: That error is fixed. However, I'm getting an error if I try to use a Python command: image of error. The first line just defines the file path for the script (the last item in the list is a .py file). I tried doing "%%python" followed by the command, but it doesn't work. Any ideas?
I pip installed the sportsreference package in my command prompt and it shows successful. Yet when I try to call it in my Jupyter Notebook it says no module named sportsreference.
Any help on what I'm doing wrong?
The interpreter that your Jupyter uses to run the cells is not the one you installed that package into. Remember you can have not only different versions of Python interpreter, but also different virtual environments associated with each Python interpreter in your machine.
So either install the package in the interpreter that Jupyter uses, or run the Jupyter from the interpreter you've installed that package into.
The simplest solution is to install it in a Jupyter cell with:
!pip install <your_package_name>
the ! allows you to execute command.
To check which interpreter currently runs your code you can check the output of:
import sys
print(sys.executable)
I am having a problem with importing tensorflow GPU on spyder.
This is what I get when I type import tensorflow on iPython using Spyder 3 (on MacOS)
When I checked what packages I have within tensorflow I get this list, which I see that iPython, and Spyder are not included.
Also in anaconda, when I click on tensorflow in Environments, I have the option to open it with Python, with terminal, but not with iPython or Spyder (or Jupyter)
I would very much appreciate any help.
UPDATE 1:
Ok I managed to get Spyder on tensorflow's ENV but when I run the command 'import tensorflow' on iPython I get this error (when I run the same command on Python's tab everything seems to work just fine.
Finally I solved this mystery. If you have installed Spyder from the Anaconda, go to the Anaconda launcher. There go to environments, you will see two of them: root and tensorflow. The latter one is created due to the instructions by tensorflow.org. Just run all those instructions on the root, don't activate tensorflow environment, it will work. Everything will be available in spyder.
The instructions mentioned on the (https://www.tensorflow.org/install/install_windows) link do NOT work for the Ananconda/Spyder setups on windows. Having struggled through this for hours below is the easiest solution to get this working. Hope this helps!
Basically you do NOT need to create a seperate tensorflow environment if you want to run this on spyder. Use the below commands to install tensorflow on the ananconda client.
1) Open the Ananconda prompt from the installation folder in the start menu.
2) Run below commands:
conda install pyqt
conda install tensorflow
Spyder is picking up the default Anaconda Env, whereas you have tensorflow install in a separate environment tensorflow
To work with Spyder & tensorflow, install tensor flow and openssl in default ENV
I figured out how to get this working using the instruction on Tensorflow link. Once you create the tensorflow enviroment you can Spyder(Tensorflow) in your ananconda start menu folder. If you run your code by opening this the tensorflow should work.
Using the Anaconda Navigator:
It works for me in a different way:
As tensorflow is separately created environment, install spyder in tensorflow envirnment.
(Anaconda>Home>Applications on>tensorflow>spyder>install ... wait for installation to complete and ten launch)
I have seen another issue in anaconda. If you install Tensor flow in root or custom environment (like 'tensorflow') its not accessible from jupyter notebook or spyder. The best way to do this is to install it in the administrator mode. Follow these steps:
Open "Anaconda Prompt" as an administrator.
Verify the status on top written "Administrator: Anaconda Prompt"
DON'T Activate any of the environments, root or tensorflow.
Type in the command "pip install --ignore-installed --upgrade tensorflow-gpu" to install Tensorflow with GPU support.
To install Keras type "conda install -c conda-forge keras"
To verify installation, type 'python' and then inside python env. type 'import tensorflow as tf'. If all is well it will work without error.
I faced the same issue and solved by performing following steps in order.
Assuming that you have created conda environment, installed tensorflow and activated it and also installed spyder.
Check the executable python of your conda environment
>>import sys
>>sys.executable
Note the path of python executable.
Go to Spyder preferences and set the interpreter path to the one noted above.
I'm trying to import cv2 on Jupyter notebook but I get this error:
ImportError: No module named cv2
I am frustrated because I'm working on this simple issue for hours now. it works on Pycharm but not on Jupiter notebook. I've already installed cv2 into Python2.7's site packages, configured Jupyter's kernel to python2, browsed the documentation but I still don't get what I am missing ?
(I'm using windows 10 and working with microsoft cognitives api, that's why I need to import this package.)
here is the code:
<ipython-input-1-9dee6ed62d2d> in <module>()
----> 1 import cv2
2 cv2.__version__
What should I do in order to make this work ?
Is your python path looking in the right place? Check where python is looking for the module. Within the notebook try:
import os
os.sys.path
Is the cv2 module located in any of those directories? If not your path is looking in the wrong place. If it is overlooking the install location, append it to your python path. You can follow the instructions here.
I didn't have the openCV installation in my Python3 kernel, so I installed it by activating the specific environment and running this in the command prompt:
pip install opencv-python
How to find and activate my environment?
To list all of Your conda environments, run this command:
conda info --envs
You will get something like this:
ipykernel_py2 D:\Anaconda\envs\ipykernel_py2
root D:\Anaconda
After that, activate the environment that is complaining for the missing cv2 and run the pip install opencv-python command.
How to activate an environment?
Just run the command:
activate env_name
where env_name is the wanted environment (for example, You could type activate ipykernel_py2 if You wanted to access the first of the two environments listed above).
Note: If You are on Linux, You need to type source activate env_name.
Go to your notebook, in menu section
kernel -> Change kernel -> Python<desired version>
Now in the notebook run following command to install opencv2 in the selected environment kernel
python2:
!pip install opencv-python
python3:
!pip3 install opencv-python
Binmosa's explanation is great and to the point. As an alternative (easier, but I'm pretty sure it's just a band-aid fix), if you write:
import sys
!{sys.executable} -m pip install opencv-python
directly into your notebook, you'll be able to actually install the module in the notebook itself.
The longer explanation is interesting and informative, though. Link: https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/
To make this clear for those who are having the same issue:
By default: Anaconda (jupyter notebook) has its own version of Python & packages once it has been installed on your PC.
If you have Python x.x installed on your PC, and you installed OpenCV or -whatever packages- using the package manager of this python version, it does NOT mean your jupyter notebook will get access to these python packages you installed earlier. They are not living in the same folder.
To illustrate this, open your windows CMD and write :
python
then write:
import os
os.path
you will get the path of your python. in my case (C:\Python35)
Now open the Anaconda Prompt and write the same commands again:
you will get the anaconda's python path. In my case (C:\Users\MY_NAME\Anaconda3).
As you can see, there are two different paths of python, so make sure that your first step in diagnosing such error (No module named x) is to ask yourself whether you installed the package in the right place or not!
N.B: within Anaconda itself you can create environments, each environment may have different packages installed in it, so you also have to make sure you're in the right environment and it is the active one.
It is because of opencv library.
Try running this command in anaconda prompt:
conda install -c conda-forge opencv
You can simply open Jupyter Notebook and in any of the cell, just write:
pip install opencv-python
It will automatically install the file
Note : Keep turn ON your Internet connection
Then in next cell :
import cv2
It will work.
I added \envs\myenv\Library\bin also in the path variable and it got solved.
You will need to install ipykernel for the jupyter notebook. Follow the following steps:
python -m virtualenv env
source env/bin/acitivate
pip install opencv-contrib-python
pip install ipykernel --upgrade
python -m ipykernel install --user
jupyter notebook
You can simply try this in your jupyter notebook cell `%pip install opencv-python`
no matter which python version you're using. you may need to restart kernel to use updated package
I had this issue in my Jupyter Notebook after I had "installed" the opencv package, using Anaconda Navigator, on my base (root) environment.
However, after "installing" the package and its dependencies, Anaconda Navigator showed a reminder popup to update to the next Anaconda Navigator version. I ignored this at first, but couldn't use the opencv package in my Jupyter Notebook.
After I did update Anaconda Navigator to the newer version, the opencv package install worked fine.
pip install opencv-python
This solved the error for me in MacOS.
I had similar problem. None of the above solution worked for me. I did below in my notebook and that solved the issue
!pip install opencv-python
!pip install opencv-python-headless
I hope you have already activated the environment you know OpenCV is installed in but is not running/import error in jupyter notebook.
If not then run the below command and activate your environment before running the jupyter notebook.
conda activate /Users/prajendr/anaconda3/envs/cvpy39
Then, check all the anaconda environments on your machine using the below command on the jupyter notebook.
!conda info --envs
The output would be similar -
Try to install OpenCV in the environment again.
You know that you have OpenCV installed in this anaconda environment - cvpy39 and the path is "/Users/prajendr/anaconda3/envs/cvpy39/lib/python3.9/site-packages"
Then type the below commands to see if the OpenCV path was imported in the notebook or not?
import os
os.sys.path
you see the OpenCV path is not in this list so you need to manually import it.
Then in a cell type the below set of code. Make sure to change the python path of the environment to yours.
import sys
path_to_module = "/User/prajendr/anaconda3/envs/cvpy39/lib/python3.9/site-packages/"
sys.path.append(path_to_module)
import cv2
You will now be able to import OpenCV to your jupyter notebook.
One of possibility is that you could have written import cv2 and its utilisation in separate cells of jupyter notebook.If this is the case then first run the cell having import cv2 part and then run the cell utilising the cv2 library.