Installing python libaries on Anaconda on Mac

644 views Asked by At

Sorry, I am very new to Python, this may be a silly question.

I have installed Anaconda on Mac, and have been using basis libraries like pandas. When I try to install oauthlib library by using : pip install oauthlib, on Ipython, I get the error : pip can be only installed outside Ipython. Now I go to mac terminal, run pip3 install oauthlib, it seem to have installed it. However when I run my code from spyder(in anaconda). I get error no module name 'oauthlib'

What's going on here ? Is my code running in anaconda, and there's another python software installed ?

3

There are 3 answers

3
C Rishi On

Anaconda works like a containerized environment (virtual environment) which maintains it's own version of libraries and python version installed.

If you installed a python library on the Mac/Linux terminal (without running 'conda activate base'), it then installs it to the native version of python installed on Mac, not on Anaconda.

If you wish to run the code on your local/Mac version of Python go to the terminal and type:

pip install oauthlib

And then run the python code on the terminal itself without switching to Anaconda(since Anaconda seems to be giving an error)

In-case the command 'conda' doesn't work, running conda init and closing and opening the terminal again should do the trick.

In-case it doesn't work you need to figure out the SHELL the terminal is running on using:

echo $(which SHELL)

Output should be something like this

/usr/bin/zsh

If it's zsh then place this into your following zshrc and if it's bash then it's bashrc present in the home directory.

nano ~/.zshrc
or
nano ~/.bashrc

And paste this to the end of the file

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/bitsage/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/bitsage/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/bitsage/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/bitsage/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<
2
CodeBox On

It should be already installed if you are using a mac... If not, try writing this in your command prompt:

python get-pip.py
0
BLimitless On

Make sure you're installing oauthlib in the conda environment you're using for your project. Do the following in the terminal:

  1. First create the environment: conda create --name myenv
  2. Next, activate the environment: conda activate myenv
  3. Last, install oauth: pip3 install oauthlib

Then just make sure your IDE is using the proper conda environment. Good luck!