Anaconda prompt: running python in prompt vs jupyter notebook - python-3.x

I am running into some issues with packages I can access in anaconda prompt vs what is available in Jupyter Notebook.
I recently created an environment for python 3.6. I installed a few packages, including pandas, using:
conda install pandas
And all is well:
When I check conda list, I also see pandas installed for py36.
conda list
Now, I run the following line to start my jupyter notebook from this same location:
jupyter notebook
I then run into an error when I try to import pandas. I then try to install pandas with no luck.
My guess is this stems from having downloaded anaconda for python 2.7, but I assume there is a way to get things working in both versions of python for jupyter notebook.
To add, I am able to use pandas when I use python 2.7 (referred to as "root"):
activate root
jupyter notebook
Any help would be greatly appreciated!

Related

How to run anaconda and launch jupyter notebook with python 3.9.6?

I am on macOS Big Sur v11.5.1 with python3 v3.9.6 and since updating my OS and my Python can no longer run anaconda or launch jupyter notebook.
When I use the terminal command jupyter notebook I get:
zsh: command not found: jupyter
So I checked anaconda (which the terminal had said had been successfully installed) with anaconda --version and got:
zsh: command not found: anaconda
Prior to the Big Sur and Python 3.9.6 update (I was previously running 3.6) I was able to just type jupyter notebook and it would launch in my browser. I'd like to be able to do that again now. Is the issue that anaconda doesn't run on python 3.9? Or that the zsh shell isn't recognizing anaconda, conda, etc?
Thank you!
I guess your jupyter was installed in conda base env.
Find out where your anaconda installed.
For example, I installed it in home directory,
so I do following steps:
echo "source ~/anaconda3/etc/profile.d/conda.sh" > ~/.bashrc
then you have to
source ~/.bashrc
After that you will get back your conda.

Module seems to be installed yet Jupyter Notebook won't recognize module

I attempted to exectue the following code:
df = pd.DataFrame()
for file in files:
if file.endswith('.xls'):
df = df.append(pd.read_excel(file), ignore_index=True)
df.head()
but received this error on the 4th command line:.
However, when I check modules installed I receive:
Why does Jupyter not recognize xlrd as being installed? Thanks for any feedback or help.
Problem
You are using pip python's default package manager to check a package in python's default install location.
But using Anaconda's virtual environment (which probably jupyter notebook is used with) to run python script which requires packages to be installed in it's own directory via conda package maanger.
Solution
Run this command in Anaconda command pompt:
conda install -c conda-forge xlrd

ModuleNotFound error for import pandas in Jupyter

I get a moduleNotFoundError when importing pandas in my Jupyter Notebook.
There is not error when I do the same on the Terminal. The default python on my machine is python 3.8
This is the code that i am running on Jupyter
Why Jupyter is unable to find the pandas installed on my machine?
It is indeed caused by different versions of python. Jupyter is not executing the default version installed on my system.
To fetch the right version we need to use print(sys.executable).
Thus, the following code worked for me,
import sys
!{sys.executable} -m pip install pandas

ModuleNotFoundError for all modules when importing into a python 3.8.2 environment on Jupyter Notebook

When trying to access modules such as pandas, numpy, matplotlib etc. in a Python 3.8.2 Environment that I have downloaded (through pip install), I return a ModuleNotFoundError for all.
I had trouble accessing Python 3.8.2 on my Mac OSX and solved it by using homebrew to create a pyenv. I presume my current problem is not installing the modules into the correct Python environment.
This is the path that I am currently using for Python:
/Users/myname/.pyenv/shims/python3
When I go pip install pandas for example in the terminal I receive:
Requirement already satisfied: pandas in ./.pyenv/versions/3.8.2/lib/python3.8/site-packages (1.0.3).
Any suggestions would be greatly appreciated as I have very little experience with solving path problems.
You have a mismatch between python version running in jupyter and python version running in terminal, if you are going to stick to pyenv, close all terminal window, open a new one, close all python services running and uninstall current python version:
pkill -f python
pyenv uninstall 3.8.2
And then:
pyenv install 3.8.2
pyenv local 3.8.2
pip install jupyter
pip install numpy
jupyter notebook
And try importing the packages from jupyter. Also make sure in your terminal ~/.zshrc or ~/.bash_profile have the following line eval "$(pyenv init -)"

Anaconda Prompt finds libraries, cmd -> Python doesn't. Python was only installed with Anaconda package, nothing else

I'm not sure what's going on here. I installed Python with Anaconda, there are no previous versions of Python installed. Everything works fine with Spyder, Jupyter Notebooks, or within Anaconda prompt itself. When I try to run numpy or pandas in cmd, I get an error. When I run them in Anaconda prompt, no issue.
Looks like both prompts are pointing to the exact same installation of Python. I've even ran python.exe from the Anaconda install folder and get the same error.
My Environment Variable path points to C:\Anaconda , where the python.exe is found. Any ideas as to what's going on?
Edit: I noticed I import numpy on the conda screenshot and I'm trying to import numpy on the cmd screenshot. Importing either pandas or numpy on conda loads it successfully.
Edit 2: Opening python.exe within the Anaconda folder gives the same output. Can't import numpy/pandas. Opening Anaconda Navigator -> base (root) -> Open with Python successfully imports numpy/pandas. How can the python.exe within Anaconda not detect libraries installed by Anaconda... yet running Python within Anaconda Navigator works?
Edit 3: SOLVED Ended up uninstalling and reinstalling both Pandas and Numpy through Anaconda prompt. Really odd but now both packages work regardless if I use Conda prompt or cmd.
Try upgrading the pip first and then try to uninstall if they are already present in the below order.
pip uninstall pandas
pip uninstall numpy
pip install pandas
pip install numpy

Resources