I'm relatively new to Jupyter Notebook and have been struggling with python versions with Jupyter Notebook.
I installed seaborn but import error occurred saying no seaborn package found. It shows on upper right corner of Jupyter "Python 3" but it returned Python 2.7 when I run !python --version. Also when I run print(sys.path), the result is below.
['', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/mysql-0.0.1-py3.5.egg', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/IPython/extensions', '/Users/Cynthia/.ipython']
My guess is that my python kernel isn't pointing correctly to python3 although notebook shows it's python3. Could someone pls help me solve this? It would be helpful if there could be code to run in Jupyter cell. Thank you!
When you run python --version, It won't spit python 3.5.x, because python refers to python2 unless you aliased python as python3. So it makes sense that you see python 2.7.x when you run python --version.
As for py2 when you run conda env list, they are env names you set. They are just names, not python versions.
What needs to be done I think is to find out where your jupyterlab is installed, which I think in (base) environment. In your base environment, run conda list, where you will see a list like this:
(base) ➜ test conda list
# packages in environment at /Users/gwanghyeongim/.pyenv/versions/miniconda3-latest:
#
# Name Version Build Channel
brotlipy 0.7.0 py38haf1e3a3_1000
ca-certificates 2020.6.24 0
certifi 2020.6.20 py38_0
cffi 1.14.1 py38hed5b41f_0
chardet 3.0.4 py38_1003
conda 4.8.4 py38_0
conda-package-handling 1.6.1 py38h1de35cc_0
cryptography 2.9.2 py38ha12b0ac_0
idna 2.10 py_0
libcxx 10.0.0 1
libedit 3.1.20191231 h1de35cc_1
libffi 3.3 hb1e8313_2
ncurses 6.2 h0a44026_1
openssl 1.1.1g h1de35cc_0
pip 20.2.2 py38_0
pycosat 0.6.3 py38h1de35cc_1
pycparser 2.20 py_2
pyopenssl 19.1.0 py_1
pysocks 1.7.1 py38_1
python 3.8.3 h26836e1_1
python.app 2 py38_10
readline 8.0 h1de35cc_0
requests 2.24.0 py_0
#and so on...
See if you see jupyterlab in the list. If so, your jupyter notebook is in (base) environment.
Now the most likely scenario is you installed seaborn in py2 environment. That means you dind't install seaborn in your base environment. Install it by running conda install seaborn or pip install seaborn.
If something didn't work so far, try runnning conda upgrade --all -y to upgrade packages. It might be from collision between deprecated packages.
P.S
My suggestion is you create a separate environment and run packages on it.
Run conda create -n your_env_name to do so(replace your_env_name to the name you want set)
Activate by running conda activate the_env_you_just_created
If 2 doesn't work somehow, make sure you run conda init your_shell, where your_shell can be found by running echo $SHELL, where the last word after / is your shell.
Make sure you see (your_env_name) at the first part of command prompt. If so, your env is activated. Now install packages on here and do your project, rather than on base environment.
Since you mentioned you use conda you can do something like the following. From your terminal:
conda create -n sb python=3
conda activate sb
conda config --env --add channels conda-forge
conda install -y pandas matplotlib numpy scipy seaborn jupyterlab # some default packages
jupyter lab
Whenever you want to use this conda environment again you have to do
conda activate sb
before you can run jupyter lab.
Note, if you didn't changed the default, you should see your terminal prompt changing when activating an environment, i.e. the name of the environment comes before your prompt. In our case here (sb) <prompt>.
To solve the issue with your current conda environment, more information is needed.
I have an environment created using miniconda with python 3.6.8, called basepy_3_6_8.
I want to save the environment snapshot to a file and then recreate it later on another machine:
There are different commands to capture the environment snapshot, with slightly different outputs. Which of these can I use to guarantee that the exact environment used by the user is recreated in the target?
I was hoping pip freeze > requirements.txt and pip install -r requirements.txt would work independent of the source environment, but I noticed that pip freeze from within a conda environment does not capture the python version.
Here is the code to create the conda environment, and output of different commands:
$ conda create -n myenv python=3.6.8
$ conda activate myenv
(myenv)$ pip freeze
astroid==2.1.0
autopep8==1.4.3
certifi==2018.11.29
colorama==0.4.1
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pycodestyle==2.4.0
pylint==2.2.2
six==1.12.0
typed-ast==1.1.1
wincertstore==0.2
wrapt==1.11.0
(myenv)$ pip list
Package Version
----------------- ----------
astroid 2.1.0
autopep8 1.4.3
certifi 2018.11.29
colorama 0.4.1
isort 4.3.4
lazy-object-proxy 1.3.1
mccabe 0.6.1
pip 18.1
pycodestyle 2.4.0
pylint 2.2.2
setuptools 40.6.3
six 1.12.0
typed-ast 1.1.1
wheel 0.32.3
wincertstore 0.2
wrapt 1.11.0
(myenv)$ conda list
# packages in environment at C:\Users\alias\AppData\Local\Continuum\miniconda3\envs\myenv:
#
# Name Version Build Channel
certifi 2018.11.29 py36_0
pip 18.1 py36_0
python 3.6.8 h9f7ef89_0
setuptools 40.6.3 py36_0
sqlite 3.26.0 he774522_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.15.26706 h3a45250_0
wheel 0.32.3 py36_0
wincertstore 0.2 py36h7fe50ca_0
(myenv)$ conda list --export
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: win-64
certifi=2018.11.29=py36_0
pip=18.1=py36_0
python=3.6.8=h9f7ef89_0
setuptools=40.6.3=py36_0
sqlite=3.26.0=he774522_0
vc=14.1=h0510ff6_4
vs2015_runtime=14.15.26706=h3a45250_0
wheel=0.32.3=py36_0
wincertstore=0.2=py36h7fe50ca_0
I am eventually interested in a general tool that can capture the current environment of a specified type (conda, virtualenv, venv, global python environment) so as to install it uniformly on another machine. What is the best approach for this?
I've never used conda, but I'd try to use two different tools to manage the python version and your project dependencies.
To install a specific python version, I'd use pyenv: https://github.com/pyenv/pyenv.
pyenv also has a plugin to manage virtualenvs (https://github.com/pyenv/pyenv-virtualenv) that should support Anaconda and Miniconda: https://github.com/pyenv/pyenv-virtualenv#anaconda-and-miniconda
To manage your dependencies (packages you install in your virtual env), you have a few alternatives:
Pip freeze: it doesn't automatically guarantee reproducibility though, because it doesn't have a lock file to pinpoint the exact dependency tree
Poetry: https://github.com/sdispater/poetry (supports a lock file)
Pipenv: https://github.com/pypa/pipenv (supports a lock file)
Hope this is helpful.
I want to install a specific build of spyder on conda - version 3.3.0 with py36_a build.
# Name Version Build Channel
spyder 3.3.0 py27_0 pkgs/main
spyder 3.3.0 py36_0 pkgs/main
spyder 3.3.0 py37_0 pkgs/main
spyder 3.3.1 py27_1 pkgs/main
spyder 3.3.1 py35_1 pkgs/main
spyder 3.3.1 py36_1 pkgs/main
spyder 3.3.1 py37_1 pkgs/main
But when I do, I get an error that the package has not been found.
$conda install spyder=3.3.0=py36_1
Solving environment: failed
PackagesNotFoundError: The following packages are not available from current channels:
- spyder==3.3.0=py36_1
Current channels:
- https://repo.anaconda.com/pkgs/main/linux-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/free/linux-64
- https://repo.anaconda.com/pkgs/free/noarch
- https://repo.anaconda.com/pkgs/r/linux-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/pro/linux-64
- https://repo.anaconda.com/pkgs/pro/noarch
I also tried conda install -c pkgs/main spyder=3.3.0=py36_1 but it gave me the same error. What's wrong here?
This is not really recommended,
and updating one or more dependencies to a version not tested together in the anaconda meta package is the likely reason for this problem in the first place.
However, the fact that updating,.. something...is requiring Spyder>=3.3.0 is worrisome, and seems to match what was reported on another thread. Could you please run
conda install spyder=3.3.0
and post your full output here, We need to know what's causing this issue.
And also dont't try to doing conda update --all.
Instead, you need to do below
conda remove spyder-kernels
conda install spyder-kernel==0.*
conda update spyder
My suggestion is simply to update the packages that you an update for:
conda update spyder, conda update pandas, etc.
Installed tensorflow 1.5.0 with the command "conda install -c conda-forge tensorflow". Installation of the version is confirmed when I import it in Jupyter.
But when I did the 'conda search tensorflow' in anaconda prompt, following is the result:
Conda search tensorflow
(C:\Users\User\Anaconda3) C:\Users\User>conda search tensorflow
Fetching package metadata .............
r-tensorflow 0.8.2 r3.4.1_0 defaults
1.4 r342h0bf44f9_0 defaults
1.4.3 r343h889e2dd_0 defaults
1.4.3 mro343h889e2dd_0 defaults
tensorflow 1.1.0 np112py35_0 defaults
1.1.0 np112py36_0 defaults
1.2.1 py35_0 defaults
1.2.1 py36_0 defaults
tensorflow-gpu 1.1.0 np112py35_0 defaults
1.1.0 np112py36_0 defaults
Can someone please throw light on the following:
Why isn't tensorflow 1.5.0 not listed above when it is being imported by default in Jupyter console?
Values for all versions displayed above are set as "defaults".Why?
How can I import different versions of tensorflow in different kernels?
How could I verify if an imported version of tensorflow invokes GPU?
tensorflow 1.5.0 isn't listed in the output from conda search tensorflow because it isn't available on any of your default channels. Just as you needed to specify the conda-forge channel to the conda install command, you also need to tell conda search to look on the conda-forge channel:
conda search -c conda-forge tensorflow
In the output from that command you'll see that some packages are marked conda-forge instead of defaults, which answers your next question: defaults means that the listed package is available from one of your default search channels. You can change conda's default channel settings by editing the .condarc file, normally found in your home directory.
From your other questions, I think you may be confusing conda search with conda list.
conda search shows the package versions available to install
conda list shows the package versions actually installed in the
current environment.
To use a specific version of a package in Jupyter you create a conda environment with that version, activate the environment, then start Jupyter:
activate myEnvironment
jupyter notebook
You may also be able to do this via the Anaconda Navigator or (on Windows) a start menu shortcut.
I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.
Here is what I did.
In Anaconda, I created an environment called tensorflow as follows
conda create -n tensorflow
Then installed the data science Python packages, like Pandas, NumPy, etc., inside it. I also installed TensorFlow and Keras there. Here is the list of packages in that environment
(tensorflow) SFOM00618927A:dl i854319$ conda list
# packages in environment at /Users/i854319/anaconda/envs/tensorflow:
#
appdirs 1.4.3 <pip>
appnope 0.1.0 py36_0
beautifulsoup4 4.5.3 py36_0
bleach 1.5.0 py36_0
cycler 0.10.0 py36_0
decorator 4.0.11 py36_0
entrypoints 0.2.2 py36_1
freetype 2.5.5 2
html5lib 0.999 py36_0
icu 54.1 0
ipykernel 4.5.2 py36_0
ipython 5.3.0 py36_0
ipython_genutils 0.2.0 py36_0
ipywidgets 6.0.0 py36_0
jinja2 2.9.5 py36_0
jsonschema 2.5.1 py36_0
jupyter 1.0.0 py36_3
jupyter_client 5.0.0 py36_0
jupyter_console 5.1.0 py36_0
jupyter_core 4.3.0 py36_0
Keras 2.0.2 <pip>
libpng 1.6.27 0
markupsafe 0.23 py36_2
matplotlib 2.0.0 np112py36_0
mistune 0.7.4 py36_0
mkl 2017.0.1 0
nbconvert 5.1.1 py36_0
nbformat 4.3.0 py36_0
notebook 4.4.1 py36_0
numpy 1.12.1 <pip>
numpy 1.12.1 py36_0
openssl 1.0.2k 1
packaging 16.8 <pip>
pandas 0.19.2 np112py36_1
pandocfilters 1.4.1 py36_0
path.py 10.1 py36_0
pexpect 4.2.1 py36_0
pickleshare 0.7.4 py36_0
pip 9.0.1 py36_1
prompt_toolkit 1.0.13 py36_0
protobuf 3.2.0 <pip>
ptyprocess 0.5.1 py36_0
pygments 2.2.0 py36_0
pyparsing 2.1.4 py36_0
pyparsing 2.2.0 <pip>
pyqt 5.6.0 py36_2
python 3.6.1 0
python-dateutil 2.6.0 py36_0
pytz 2017.2 py36_0
PyYAML 3.12 <pip>
pyzmq 16.0.2 py36_0
qt 5.6.2 0
qtconsole 4.3.0 py36_0
readline 6.2 2
scikit-learn 0.18.1 np112py36_1
scipy 0.19.0 np112py36_0
setuptools 34.3.3 <pip>
setuptools 27.2.0 py36_0
simplegeneric 0.8.1 py36_1
sip 4.18 py36_0
six 1.10.0 <pip>
six 1.10.0 py36_0
sqlite 3.13.0 0
tensorflow 1.0.1 <pip>
terminado 0.6 py36_0
testpath 0.3 py36_0
Theano 0.9.0 <pip>
tk 8.5.18 0
tornado 4.4.2 py36_0
traitlets 4.3.2 py36_0
wcwidth 0.1.7 py36_0
wheel 0.29.0 <pip>
wheel 0.29.0 py36_0
widgetsnbextension 2.0.0 py36_0
xz 5.2.2 1
zlib 1.2.8 3
(tensorflow) SFOM00618927A:dl i854319$
You can see that jupyter is also installed.
Now, when I open up the Python interpreter in this environment and I run the basic TensorFlow command, it all works fine. However, I wanted to do the same thing in the Jupyter notebook. So, I created a new directory (outside of this environment).
mkdir dl
In that, I activated tensorflow environment
SFOM00618927A:dl i854319$ source activate tensorflow
(tensorflow) SFOM00618927A:dl i854319$ conda list
And I can see the same list of packages in that.
Now, I open up a Jupyter notebook
SFOM00618927A:dl i854319$ source activate tensorflow
(tensorflow) SFOM00618927A:dl i854319$ jupyter notebook
It opens up a new notebook in the browser. But when I just import basic python libraries in that, like pandas, it says "no packages available". I am not sure why is that when the same environment has all those packages and in the same directory, if I use Python interpreter it shows all packages.
import pandas
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-d6ac987968b6> in <module>()
----> 1 import pandas
ModuleNotFoundError: No module named 'pandas'
Why jupyter notebook is not picking up these modules?
So, Jupyter notebook doesn't show env as the interpreter
I came up with your case. This is how I sort it out
Install Anaconda
Create a virtual environment - conda create -n tensorflow
Go inside your virtual environment - (on macOS/Linux:) source activate tensorflow (on Windows: activate tensorflow)
Inside that install tensorflow. You can install it using pip
Finish install
So then the next thing, when you launch it:
If you are not inside the virtual environment type - Source Activate Tensorflow
Then inside this again install your Jupiter notebook and Pandas libraries, because there can be some missing in this virtual environment
Inside the virtual environment just type:
pip install jupyter notebook
pip install pandas
Then you can launch jupyter notebook saying:
jupyter notebook
Select the correct terminal python 3 or 2
Then import those modules
I believe a short video showing all the details if you have Anaconda is the following for mac (it is very similar to windows users as well) just open Anaconda navigator and everything is just the same (almost!)
https://www.youtube.com/watch?v=gDzAm25CORk
Then go to jupyter notebook and code
!pip install tensorflow
Then
import tensorflow as tf
It work for me! :)
Install Anaconda
Run Anaconda command prompt
write "activate tensorflow" for windows
pip install tensorflow
pip install jupyter notebook
jupyter notebook.
Only this solution worked for me. Tried 7 8 solutions.
Using Windows platform.
install tensorflow by running these commands in anoconda shell or in console:
conda create -n tensorflow python=3.5
activate tensorflow
conda install pandas matplotlib jupyter notebook scipy scikit-learn
pip install tensorflow
close the console and reopen it and type these commands:
activate tensorflow
jupyter notebook
I have found a fairly simple way to do this.
Initially, through your Anaconda Prompt, you can follow the steps in this official Tensorflow site - here. You have to follow the steps as is, no deviation.
Later, you open the Anaconda Navigator. In Anaconda Navigator, go to Applications On --- section. Select the drop down list, after following above steps you must see an entry - tensorflow into it. Select tensorflow and let the environment load.
Then, select Jupyter Notebook in this new context, and install it, let the installation get over.
After that you can run the Jupyter notebook like the regular notebook in tensorflow environment.
I would suggest launching Jupyter lab/notebook from your base environment and selecting the right kernel.
How to add conda environment to jupyter lab should contains the info needed to add the kernel to your base environment.
Disclaimer : I asked the question in the topic I linked, but I feel it answers your problem too.
For Anaconda users in Windows 10 and those who recently updated Anaconda environment, TensorFlow may cause some issues to activate or initiate.
Here is the solution which I explored and which worked for me:
Uninstall current Anaconda environment and delete all the existing files associated with Anaconda from your C:\Users or where ever you installed it.
Download Anaconda (https://www.anaconda.com/download/?lang=en-us#windows)
While installing, check the "Add Anaconda to my PATH environment variable"
After installing, open the Anaconda command prompt to install TensorFlow using these steps:
Create a conda environment named tensorflow by invoking the following command:
conda create -n tensorflow python=3.5
(Use this command even if you are using python 3.6 because TensorFlow will get upgraded in the following steps)
Activate the conda environment by issuing the following command:
activate tensorflow
After this step, the command prompt will change to (tensorflow)
After activating, upgrade tensorflow using this command:
pip install --ignore-installed --upgrade
Now you have successfully installed the CPU version of TensorFlow.
Close the Anaconda command prompt and open it again and activate the tensorflow environment using 'activate tensorflow' command.
Inside the tensorflow environment, install the following libraries using the commands:
pip install jupyter
pip install keras
pip install pandas
pip install pandas-datareader
pip install matplotlib
pip install scipy
pip install sklearn
Now your tensorflow environment contains all the common libraries used in deep learning.
Congrats, these libraries will make you ready to build deep neural nets. If you need more libraries install using the same command 'pip install libraryname'
You will need to add a "kernel" for it.
Run your enviroment:
>activate tensorflow
Then add a kernel by command (after --name should follow your env. with tensorflow):
>python -m ipykernel install --user --name tensorflow --display-name "TensorFlow-GPU"
After that run jupyter notebook from your tensorflow env.
>jupyter notebook
And then you will see the following
enter image description here
Click on it and then in the notebook import packages. It will work out for sure.
It is better to create new environment with new name ($newenv):conda create -n $newenv tensorflow
Then by using anaconda navigator under environment tab you can find newenv in the middle column.
By clicking on the play button open terminal and type: activate tensorflow
Then install tensorflow inside the newenv by typing: pip install tensorflow
Now you have tensorflow inside the new environment so then install jupyter by typing: pip install jupyter notebook
Then just simply type: jupyter notebook to run the jupyter notebook.
Inside of the jupyter notebook type: import tensorflow as tf
To test the the tf you can use THIS LINK
Although it's a long time after this question is being asked since I was searching so much for the same problem and couldn't find the extant solutions helpful, I write what fixed my trouble for anyone with the same issue:
The point is, Jupyter should be installed in your virtual environment, meaning, after activating the tensorflow environment, run the following in the command prompt (in tensorflow virtual environment):
conda install jupyter
jupyter notebook
and then the jupyter will pop up.
I have to install it using condo's pip3. Just start jupyter-notebook and execute following
import sys
sys.executable
This will give you something like this
/home/<user>/anaconda3/bin/python
Now in a terminal execute the following (using pip3 from the above path where we found our python)
/home/<user>/anaconda3/bin/pip3 install tensorflow
This is basically installing the Tensorflow in the Conda environment using the Conda pip3 installer