python3.7 is not able to open jupyter notebook - python

I have two versions of python in my Macbook, python3.7 and python3.8. I've been using python3.7 to do my data analysis. I used $python3.7 -m jupyter notebook to open jupyter notebook all the time. I've stopped for a while, last week I typed the same command in the terminal, jupyter notebook was opened by python3.8. I tried different ways, seems python3.7 isn't functional at all, jupyter notebook is only able to be opened by python3.8.
I have two questions:
How to open jupyter notebook again with python3.7?
Can I use python3.8 to keep analyzing the data generated in python 3.7? I tried to do some analysis in python3.8, seems it's fine so far, but I'm not sure about it as I'm still a beginner.
Thank you in advance for your nice help!
Yi

Get rid of python3.7 it had known issues. I do not know why your jupyter-notebook stopped working suddenly but you can use python3.8. I doubt that you are using any processes that got deprecated between the two major releases.

I recommend setting up a virtual environment with whatever python version you want:
$ virtualenv --python=python3.7 env/
$ source env/bin/activate
(env) $ pip install ...
This approach avoid any dependencies clashing and isolate you project dependencies from the system ones.

Related

Best way to install anaconda if you already have jupyter lab

A while ago, I installed jupyter lab and I use it a lot.
I also use python a lot via VScode.
But I have had problems in the past when doing a new type of python install and losing access to other ways of using python.
I now need to install geopandas both which strongly recommends installing with anaconda/conda. https://geopandas.org/en/stable/getting_started/install.html
Anyone got any advice on the best way to do this on windows without destabilising either jupyter labs or python in VScode.
Should I uninstall jupyter labs first?
You can run standard Python and Anaconda in parallel w/o any trouble. Just make sure you stick to the default installation options and you don't add Anaconda's Python to the system path
However, you will only be able to use Anaconda's Python after activating an environment with the command
conda activate
Besides that, consider running your Jupyter Notebook within VSCode. It's way more convenient that Jupyter Lab ...

Jupyter is not using my virtual environment in VSCode

I'm currently having problems getting Jupyter to connect to my kernel that I made using my virtualenv.
Here's what I did:
I first created my virtual environment by doing:
python3 -m venv venv
Then I activated the venv in my terminal, and installed the packages that I needed for my project:
pip install numpy pandas matplotlib ipykernel jupyter jupyterlab
Then I created a kernel from my venv so that Jupyter can use by doing:
python3 -m ipykernel install --user --name=python_data_analytics
Afterwards, I tried to get VSCode to use my venv and I got it to use the interpreter at bin/ipython3 of my venv. As for Jupyter, I got it to use the kernel I made from a dropdown menu.
Then when I tried to execute the first cell of my notebook to import my libraries, Python says that it can't find my libraries.
Here's a screenshot of the end result:
It seems that Jupyter is not using the virtual environment that I made and it's falling back to the system's interpreter. I'm not sure how should I go about fixing this problem. Any help is much appreciated. Thank you.
I'm not sure, but in the left bottom option, where there is a label called "Python 3.9.5..." you can select your desired environment.

Installing a ipykernel and running jupyter notebook inside a virtual env - not using conda

I've hit a dead end trying to solve/debug this issue which doesn't seem like it should be that difficult.
I'm working in Pycharm IDE (not the professional) and I'm working inside a virtual environment let's call it pythonProject and I want to be able to run launch a jupyter notebook in this environment so that it can pick up all the python packages i've installed and configured for this environment.
As I understand it from the documentation, these are the steps I need to take.
My terminal prompt statement:
(pythonProject) oliver#oliver-u20:~/pythonProject$
commands:
python3 -m pip install ipykernel
python3 -m pip install notebook
python3 -m ipykernel install --user --name pythonProject --display-name "Python (pythonProject)"
jupyter notebook
But when I load jupyter notebook, it only shows python3 under kernels.
I tried outputting
jupyter kernelspec list
And get only the base kernel which suggests from this that it's not finding my kernelspec, but I can't seem to figure from the documentation what i'm supposed to do.
Am I missing something?
Ok so I've solved this.
I think there was an install issue with jupyter.
I tried reproducing this in a completely new project and venv and could get the kernel showing.
In the project and venv where I still couldn't, I noticed a discrepancy in the output of my jupyter --paths
In the working venv I could see under data
/home/oliver/.local/share/jupyter
Which is where the kernels I installed are located.
However in the project that wasn't working there was instead:
/home/oliver/snap/jupyter/6/.local/share/jupyter
I'm guessing this snap path is from how I originally installed jupyter on my Ubuntu via the app store - seemed sensible at the time.
So I uninstalled jupyter, restarted my venv and the jupyter --paths has magically changed so that
/home/oliver/.local/share/jupyter
is present and when I start a jupyter notebook at the command line with
jupyter notebook
I can see all my kernels showing!
I found this quite difficult to debug with the documentation and command help outputs so hope someone else finds this useful.

Avoid the creation of multiple Jupyter kernels for each virtualenv

I am working with Jupyter Notebooks and several virtualenvs in Ubuntu 18.04 (I'm not using Conda).
I usually create a new virtualenv for each new python project I'm working on and since I'm working on many projects I would like to AVOID the creation of multiple Jupyter kernels as suggested here.
Instead, I would like to tell Jupyter to start the python kernels in the virtualenv in which I am running it BY DEFAULT.
I know this is possible since it is the way it used to work, but then I don't know what I did wrong and now if I don't create a kernel for each virtualenv Jupyter doesn't allow me to use the python modules I have installed in that environment.
The way it used to work was the following:
I activate the virtualenv
source bin/activate
I installed Jupyter in that virtualenv
I ran Jupyter in that virtualenv
jupyter notebook
I selected Python3/2, R kernel depending on what I needed
I could import all the modules installed in that virtualenv
Now it's not working anymore and if I try to import a module installed in that virtualenv it gives me the following error:
ModuleNotFoundError: No module named 'modulename'
Even if I checked that the Jupyter notebook it's looking in the right paths:
! which python
/home/user/venv_name/bin/python
and
! which pip
/home/user/venv_name/bin/pip
How can I bring back the old setting?

ModuleNotFoundError in Jupyter while pip freeze shows its installed

I created a virtual environment, installed pandas and some other libraries, changed the ipython kernel and then opened jupyter inside my virtual environment. Pandas and other libraries worked fine.
Then i installed fastai in my virtualenv, but it shows ModuleNotFoundError in Jupyter only. It works fine in terminal, when i run !pip freeze inside Jupyter it lists 'fastai', when i try to install it in jupyter with '!pip install fastai' it shows 'Requirement already satisfied' but importing it still gives me 'ModuleNotFoundError'. Check this image for example
All answers on SO to this question are for people who haven't changed their jupyter kernel to their environment or who have had other issues, but i couldn't find my issue.
You have to add the virtualenv to the kernel. Nice discussion is here (Execute Python script within Jupyter notebook using a specific virtualenv).
Assuming virtualenv is working fine (jupyter-notebook and fastai are working), these are the additional steps, I might have tried. In the second line (below) change the "--name=NameOfVirtualEnv" appropriately with the name of your virtualenv.
pip install --user ipykernel
python -m ipykernel install --user --name=NameOfVirtualEnv
After that once you start the Jupyter notebook, you will see the "New" dropdown to the right side .. there you will have your virtual environment with the fastai.
Please let me know the outcome. Curious if it worked for you.

Categories

Resources