setting up vitrual environment for deep learning on ubuntu - python

I am trying to setup virtual environment for every deep learning project that i do locally on my laptop so that every package like numpy, matplotlib, opencv-python etc. i installed will be installed in that environment only not on my laptop globally. Now, the problem is i activate the virtual environment using source ENV_NAME/bin/activate and when i import libraries like cv2 in my notebook after installing cv2 in that environment setup, it says "
ModuleNotFoundError: No module named 'cv2'" please see the screenshots below. but when i deactivate that environment and install cv2 on my laptop globally and then try to import cv2, it works fine. Could someone please tell my why?

You need to restart the kernel in Jupyter Notebook for the new modules to show up.

Not sure if you already found the solution, but I stumbled upon this blog and it answers most questions of the type: I installed package X and now I can't import it in the notebook. Help!
You can install the package directly in the jupyter notebook using:
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install opencv-python
if using pip.
OR
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} opencv-python
if using conda.
Head over to link for more details.

Related

Tensorflow io import issue - missing module even if showing in pip freeze

I am trying to use tensorflow io to process mp3 audio files.
My operating system is Ubuntu 20.04.
I created a new dedicated virtual environnement and activated it using pyenv :
pyenv virtualenv testtfio; pyenv local testtfio
I also upgraded pip as I thought it might cause the issue. Then I installed tensorflow_io :
pip install tensorflow_io
This generates installation of this package and all dependencies as I can see after using "pip freeze".
Then when I try to import tensorflow_io it shows :
ModuleNotFoundError: No module named 'tensorflow_io'
What am I doing wrong ?
Thanks for your help
The issue was linked to Jupyter : I was using jupyter notebook in my new local environnement and it was running (I suppose from the pyenv global environment), but I forgot to install it in local virtualenv.
In order to solve the import issue in Jupyter notebook I just had to install Jupyter in my new local virtualenv.
pip install jupyter

Cannot import packes from within conda virtual environment

I am using Python 3.8 on a Ubuntu 20.04 computer. So far, I had no problem importing packages from either Spyder of Jupyter.
I have created a conda virtual environment called theory using Python 3.6, as confirmed by running python --version from within this conda environment.
conda list reveals that numpy is installed:
numpy 1.19.4 pypi_0 pypi
Opening a Python interactive session from the terminal and importing numpy in there works like a charm.
However, when trying to import numpy from within Spyder, I am getting a "Module Not Found" error:
ModuleNotFoundError: No module named 'numpy'
Here is what I tried to fix this issue:
I tried uninstalling and reinstalling numpy using pip install numpy (and pip3 install numpy).
I tried updating conda following the answer provided in this GitHub post: conda update --prefix /home/sheldon/anaconda3 anaconda .
I tried specifying the path to the numpy package in the PYTHONPATH manager directly in Spyder, pointing to /home/sheldon/anaconda3/envs/
What am I doing wrong here?
EDIT: I checked that Numpy 1.9.4. actually supports Python 3.6
EDIT: Just recreated a new Python 3.6 environment from scratch and I can import numpy just fine...
can you please try this :
uninstall numpy with pip uninstall
and re install it with
conda install numpy
Not pip install..

Installing OpenCv on Azure JupyterNoteBook

How can i get Open Cv library installed on my Azure Jupyter NoteBook.Having used the command that shows the version of Open Cv,it returns "no module found".Is there a way to go about this
Select console in the left menu. Here you can install modules using pip or conda.
Another way, you can install opencv from Jupyter Notebook using this code:
import sys
!{sys.executable} -m pip install opencv-python

Matplotlib in Tensorflow Jupyter Notebook

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)

Jupyter: install new modules

I have recently installed Anaconda with Python 3.5 and all the rest. I come from R where I am used to install packages dynamically. I am trying to install a module called scitools through jupyter notebook. I would like to recreate this in jupyter. However, I don't know how to dynamically install packages (if it's possible). I would greatly appreciate your help. Thank you!
EDIT: I am trying to use conda as recommended by the community, but it's not working. I am using mac OSX
Check Jake Vander Plus Blog here to learn how to install a package with pip from Jupyter Notebook.
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
So if you have already done the install with anaconda, you may already have the module installed. In that case in your jupyter notebook after you have activated your kernel, you just need to make sure you execute the import statement.
import scitools
If you haven't installed that module yet, you can install it one of two ways. Both work from your command line or terminal.
pip install scitools
or since you have Anaconda
conda install scitools
and that should do it. Your import statement in your notebook when executed should correctly locate and enable the use of that module.
I had the same issue. It turns out if you open an anaconda window, which in Windows is accessible under the Anaconda drop down, it points to the correct location to install (or update) using pip.

Categories

Resources