error while installing seaborn using pip and conda in jupyter notebook/terminal - pip

I'm working in a jupyter notebook, and I'm trying to install seaborn using the following code:
import sys
!conda install --yes --prefix {sys.prefix} seaborn
But I get this error:
OSError Traceback (most recent call last)
Cell In [45], line 2
1 import sys
----> 2 get_ipython().system('conda install --yes --prefix {sys.prefix} seaborn')
...
File ~/Library/CloudStorage/OneDrive-Personal/Documents/Course-Programming/Machine-Learning/Projects/sample-project/env/lib/python3.10/site-packages/IPython/utils/_process_posix.py:57, in ProcessHandler.sh(self)
55 self._sh = pexpect.which(shell_name)
56 if self._sh is None:
---> 57 raise OSError('"{}" shell not found'.format(shell_name))
59 return self._sh
OSError: "/bin/fish" shell not found
I tried installing it using pip from my terminal, as well as removing /bin/fish from etc/shells but nothing changes. Can someone please point out what I'm doing wrong?

I solved this by removing the conda environment, then recreating it with seaborn as one of the packages, like this:
conda create --prefix ./env pandas numpy matplotlib jupyter scikit-learn seaborn

If you are not working in virtual environment then try these steps:-
1.) Go to Anaconda Navigtor
2.) Select Environment in Navigation panel.
3.) In base root, change filter option installed to non installed.
4.) Search Seaborn
6.) If its not installed then installed it

Related

Basemap library using Anaconda Jupyter Notebooks - KeyError: PROJ_LIB

I'm trying to install and import the Basemap library into my Jupyter Notebook, but this returns the following error:
KeyError: 'PROJ_LIB'
After some research online, I understand I'm to install Basemap on a separate environment in Anaconda. After creating a new environment and installing Basemap (as well as all other relevant libraries), I have activated the environment. But when importing Basemap I still receive the same KeyError.
Here's what I did in my MacOS terminal:
conda create --name Py3.6 python=3.6 basemap
source activate Py3.6
conda upgrade proj4
env | grep -i proj
conda update --channel conda-forge proj4
Then in Jupyter Notebook I run the following:
from mpl_toolkits.basemap import Basemap
Can anyone tell me why this results in a KeyError?
Need to set the PROJ_LIB environment variable either before starting your notebook or in python with os.environ['PROJ_LIB'] = '<path_to_anaconda>/share/proj'
Ref. Basemap import error in PyCharm —— KeyError: 'PROJ_LIB'
In Windows 10 command line: first find the directory where the epsg file is stored:
where /r "c:\Users\username" epsg.*
...
c:\Users\username\AppData\Local\conda\conda\envs\envname\Library\share\epsg
...
then either in command line:
activate envname
SET PROJ_LIB=c:\Users\username\AppData\Local\conda\conda\envs\envname\Library\share
(make sure there are no leading on trailing spaces in the path!) and then
jupyter notebook
or add this to your jupyter notebook (as suggested by john ed):
import os
os.environ['PROJ_LIB'] = r'c:\Users\username\AppData\Local\conda\conda\envs\envname\Library\share'
The problem occurs as the file location of "epsg" and PROJ_LIB has been changed for recent versions of python, but somehow they forgot to update the init.py for Basemap. If you have installed python using anaconda, this is a possible location for your espg file:
C:\Users\(xxxx)\AppData\Local\Continuum\anaconda3\pkgs\proj4-5.1.0-hfa6e2cd_1\Library\share
So you have to add this path at the start of your code in spyder or whatever field you are using.
import os
os.environ['PROJ_LIB'] = r'C:\Users\(xxxx)\AppData\Local\Continuum\anaconda3\pkgs\proj4-5.1.0-hfa6e2cd_1\Library\share'
from mpl_toolkits.basemap import Basemap
If you can not locate epsg file at all, you can download it here:
https://raw.githubusercontent.com/matplotlib/basemap/master/lib/mpl_toolkits/basemap/data/epsg
And copy this file to your PATH, e.g. to:
os.environ['PROJ_LIB'] = 'C:\Users\username\Anaconda3\pkgs\basemap-1.2.0-py37h4e5d7af_0\Lib\site-packages\mpl_toolkits\basemap\data\'
This is the ONLY solution that worked for me on Windows 10 / Anaconda 3.
Launch Jupyter Notebook from command prompt and it won't throw the same error. It somehow works for me!

StopIteration: Could not import PIL.Image. The use of `array_to_img` requires PIL error

import keras
Using TensorFlow backend.
from keras.preprocessing.image import ImageDataGenerator
train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen = ImageDataGenerator(rescale=1./255)
training_set = train_datagen.flow_from_directory(
'E:/Python/A-
Z/Convolutional_Neural_Networks/dataset/training_set',
target_size=(64, 64),
batch_size=32,
class_mode='binary')
test_set = test_datagen.flow_from_directory(
'E:/Python/A-
Z/Convolutional_Neural_Networks/dataset/test_set',
target_size=(64, 64),
batch_size=32,
class_mode='binary')
classifier.fit_generator(
training_set,
steps_per_epoch=8000,
epochs=25,
validation_data=test_set,
validation_steps=2000)
please help I am a beginner in this CNN I am using keras to program the task but I am getting the above error(given in the title)
I have tried installing and then uninstalling pillow
but nothing working it is showing the same error I have also tried some other StackOverflow answers but they are also not working
I came the same error as you.
this is my environment:
I create "tensorflow" env in anaconda, python 3.6 kernel,activate the env, then
pip install tensorflow
pip install keras
pip install pillow
and the error was fixed.
I had the same problem. If you are using Anaconda and the Jupyter notebook this is what worked for me.
Close your notebook and stop Jupyter.
Exit out of your environment
Restart the environment again and run:
pip install pillow
and then:
pip install jupyterlab
and start jupyter-notebook back up and then add or (re-run):
from PIL import Image
In your notebook and hopefully .fit_generator will no longer throw that error.
The following is applicable to Windows users working with Anaconda:
If you've installed 'tensorflow' with pip, or a pip variant (ie. pip3), then you will have to install tensorflow again, but this time with the command conda install tensorflow.

How to install numpy scipy matplotlib and open cv in python 3.6 macbook pro?

I had installed Python 3.6 in my windows laptop from python.org . After that I ran cmd and did pip install numpy and pip install numpy. It installed successfully. Thereafter I ran idle(python gui) and typed import numpy and then import scipy, Both worked.
After that I got opencv3 whl file and then did pip install with it too in cmd and it imported in python.
Can anyone explain step by step in detail how to install opencv,matplotlib, scipy, and numpy in Macbook so that I can import it in the python 3 version of Macbook or can you just help me in installing in any way but with detailed explanation?
To install OpenCV without anaconda, open terminal and exec this command
pip install opencv-python
and import module in your Python by following line of code
import cv2
The simplest solution is to install Anaconda and than:
conda install opencv
If you want fewer packages installed (Anaconda comes with 200+ of them), use Miniconda and than:
conda install numpy scipy matplotlib opencv
Now :
>>> import cv2
>>> cv2
<module 'cv2' from '.../miniconda3/envs/opencv/lib/python3.6/site-packages/cv2.cpython-36m-darwin.so'>
If this does not work, try making a new environment:
conda create -n opencv python=3.6
Answer with ENTER.
Later:
source activate opencv
The prompt should change to (opencv).
Now:
(opencv) conda install numpy scipy matplotlib opencv
STEP 1: go to anaconda website and download the anaconda with python 3.6 for mac https://www.anaconda.com/download/#macos
STEP 2: install with graphical user interface
STEP 3: open terminal and give command "conda --version" to check if anaconda was installed perfectly.
STEP 4: the give the command "conda update conda" . thos will update all the packages to recent version.
STEP 5: now again go to conda website https://anaconda.org/ and type "opencv' in the search bar.
search open cv in that box
STEP 6: click on conda forge
this one in this image
STEP 6: now do as it says in the instruction provided there ie. open TERMINAL and run one of the following :
conda install -c conda-forge opencv ( i used this one and it worked)
or:
conda install -c conda-forge/label/broken opencv
STEP 7: enter y if asked in terminal.
STEP 8: after install open new terminal and type python and then type "import cv2" . if all was error free till now then the prompt arrow will be shifted to next line.
STEP 9: enjoy coding :)

Packages installed in miniconda but not anaconda

I did not manage to install xgboost so I install something call miniconda. With the miniconda prompt i can use pip install xgboost works.
When I did it again I get the answer:
"Requirement already satisfied: xgboost in c:\users\anne-sophie\miniconda3\lib\site-packages\xgboost-0.6-py3.6.egg"
But when, in my jupyther notbook I do "import xgboost" I get an erreur:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-745aa3a2d734> in <module>()
----> 1 import xgboost as xgb
ModuleNotFoundError: No module named 'xgboost'
It seems that everything is installed in C:\Users\Anne-Sophie\Miniconda3\Lib\site-packages instead of C:\Users\Anne-Sophie\Anaconda3\Lib\site-packages and Anaconda must be connected to Anaconda3 and not mini conda3".
Do you have any ideas how I can connect anaconda to miniconda? I managed to make it work by copying lib and library from miniconda to anaconda but I am sure it might exist a way to do it easily.

tensorflow installation issues:ImportError: No module named tensorflow

environments: Ubuntu 14.04(64bit) Python2.7.11
Firstly, I installed tensorflow in the way of Virtualenz installation.
$ sudo apt-get install python-pip python-dev python-virtualenv
$ virtualenv --system-site-packages ~/tensorflow
$ source ~/tensorflow/bin/activate
$export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl
$ pip install --upgrade $TF_BINARY_URL
and then, I test my installation and some issue appear. I know I didn't install tensorflow successfully.
import tensorflow
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named tensorflow
import tensorflow as tf
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named tensorflow
I don't know how to solve the problem. Please help me, it cost me one day. I tried to uninstall tensorflow and then I installed in the way of pip installation. But I get the same error.
The protocbuf is 3.1.0.
Are you running python in the same virtual environment you installed tensorflow in?
To access your tensorflow installation, you have to first "activate" the virtualenv in any new terminals, as follows:
source ~/tensorflow/bin/activate
python
import tensorflow as tf
If you run the above in a new terminal, does it solve your problem?
When you did
$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl
this step you are specifying that you are going to use Nvidia card.
To run tensorflow with GPU(Nvidia graphics card) you need to satisfy all Nvidia requirements
Nvidia requires some special privileges to its CUDA cores
You also need to check for Cuda pathnames to the LD_LIBRARY_PATH environment variable, check in Nvidia Documentation.Also, you need to install an profiling support, this can be done by libcupti-dev library, which is the NVIDIA CUDA Profile Tools Interface. This library provides advanced profiling support. To install this library, issue the following command:
sudo apt-get install libcupti-dev
But if you want to run tensorflow in CPU mode only, do not specify $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl.With this you are overriding TF_BINARY_URL variable to use Nvidia CUDA core
So, to use CPU from all your steps remove $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.1-cp27-none-linux_x86_64.whl and include only $export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl and reinstall
I hope this should clear the problem
In case, your prerequisite python packages are not installed properly,
check several things.
$ source $HOME/tensorflow/bin/activate
$ which python
$ which pip
please check these binaries are in the path $HOME/tensorflow/bin/activate. If so, try
$ pip install -I --upgrade $TF_BINARY_URL
where -I option forces to install packages.
INSTALLATION OF TENSORFLOW ON UBUNTU 18.04
download anaconda python package
install it via shell using bash
$bash anaconda*.sh
editing the .bashrc script //location home
$sudo apt-get install python3-pip
$sudo apt-get update
$cd
$nano .bashrc
nano is the text editor
insert the given line at the end of the file
export PATH=-/anaconda3/bin:$PATH
create a virtual environment
using conda
$conda create -n myenv python=3.5
//SPECIFY THE VERSION REQUIRED DO NOT USE 3.7 AS THERE IS A COMPATIBLITY ISSUE WITH TENSORFLOW 10
$source activate myenv
$pip install -U tensorflow
$python
>>import tensorflow as tf
>> //get this prompt without an error it means the installation is successful
>>exit()
source deactivate
fully tested if an issue arises do let me know
whenever you install python packages i would suggest to do it in a virtual environment

Resources