Best way to install anaconda if you already have jupyter lab - python

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 ...

Related

Why is the module 'ultralytics' not found even after pip installing it in the Python conda environment?

In a conda environment with Python 3.8.15 I did
pip install ultralytics
successfully installed ...,ultralytics-8.0.4
But when running from ultralytics import YOLO , it says
ModuleNotFoundError: No module named 'ultralytics'
I run using Colab.
First I install Ultralytics using pip command
!pip install ultralytics
then
from ultralytics import YOLO
and it worked.
Were you using Jupyter notebook? if so, jupyter might not using the correct python interpreter. Or you're using jupyter that installed on system instead of jupyter installed inside a conda environment.
To check which python jupyter use this code on a cell:
import sys
print(sys.executable)
To list all installed python interpreter available. use this command:
!which -a python
The python inside the conda environment should be on the path something like this:
~/.conda/envs/{myenv}/bin/python
To use correct interpreter inside a conda environment you need to use separate jupyter installation inside the conda environment. see this answer: How to use Jupyter notebooks in a conda environment?
You can use magic %pip install from a cell inside the notebook to insure the installation occurs in the environment that the Jupyter notebook kernel is using. Mikhael's answer points out the thorough way to be really sure how to deal with this and fully control things. However, it is nice to have convenient, quick alternatives when trying to get past a hurdle.
For those using actual Jupyter anywhere (not Google Colab), the install command would be:
%pip install ultralytics
Be sure to let the installation process fully depending on your system and network this can take a bit. Next, after running any magic install command, you'll see a message to restart the kernel, and it is always best to do that before trying the import statement. Finally, after restarting the kernel you can run the suggest import after of from ultralytics import YOLO and hopefully not encounter ModuleNotFoundError: No module named 'ultralytics' now.
The magic command was added to insure that installation occurs in the environment where the kernel backing the notebook is found. See here for more about the modern magic install commands in Jupyter. (For those using conda/Anaconda/mamba as the primary package manager for when packages have conda install recipes, theres a related %conda install variation that also insures installation to the proper environment that the kernel is using.)
See JATIN's answer if you are using Google Colab at this time. Because I don't believe Google Colab has the magic pip install as they have sadly not kept up with current Jupyter abilities.
The exclamation point use in conjunction with pip install is outdated for typical Jupyter given the addition of the magic command. Occasionally, the exclamation point not insuring the the install occurs in the same environment wherein the kernel is running could lead to issues/confusion, and so the magic command was added a few years ago to make installs more convenient. For more about the shortcoming of the exclamation point variant for this particular task, see the first sentence here.
In fact, these days no symbol is better than an exclamation point in front of pip install or conda install when running such commands inside a vanilla Jupyter notebook. No symbol being even better than an exclamation typically now is due to automagics being enabled by default on most Jupyter installations. And so without the symbol, the magic command variant will get used behind-the-scenes. Typically, it is better to be explicit though and use the magic symbol, but you may see no symbol work or be suggested and wonder what is happening.

Difference between Jupyter and Terminal in the same Kernel

I'm trying to import tensorflow as ts in my script. While everything is fine in a Notebook, when I try to recreate the same script in a .py file the import returns the following, popular message:
ModuleNotFoundError: No module named 'tensorflow'
Note that both Jupyter and terminal are using the same virtual environment. In Notebook it's picked as a Kernel and in terminal it's activated with conda.
I was convinced the whole Kernel/env idea was about preventing exactly that kind of situations. Although I'm new to python so maybe I'm missing something basic.
Also, this might have something to do with that I'm using an M1 and macos, so I have the tensorflow-macos installed. But please consider there might be other reasons.
Make sure your pyenv installation doesn't interfere with the conda environments. Pyenv can overrule which python installation is used even if the conda environment has picked another. In my case it was the reason. Jupyter Notebook wasn't affected by pyenv. There are two solutions:
Remove pyenv
Make sure it is clear to you how both pyenv and conda are affecting your setup and correct it. Some considerations and suggestions are mentioned in this question: Installing anaconda with pyenv, unable to configure virtual environment

python3.7 is not able to open jupyter notebook

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.

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?

When using Jupyter, I have to install python modules with Conda and not cmd prompt. Why?

I'm pretty new to programming so forgive my ignorance.
When installing certain python packages/modules in the cmd prompt I am able to import them fine when using Jupyter Notebook. But some modules Jupyter Notebook cannot import without installing via Conda first. Why is this?
The problem seems to be related to system and environment that you are using and not the programming :)
Since you are a beginner, let us understand the concepts first rather than solving the problem.
Python code is run on an interpreter that is installed on your machine.
Jupyter is a web application that takes code using a given language's interpreter. So Jupyter, on its own doesn't run your code. It uses the interpreter installed on a system(your local machine).
Conda is a package manager and also an environment manager. That means using conda, you can create a virtual environment on your machine and that virtual environment can have its own installation of an interpreter. This virtual environment can have its own copy of the packages/modules as well.
Now comes the best part: The jupyter notebook can be asked to use any of the interpreters including the ones installed on a virtual environment.
So most likely, you are running the jupyter notebook from an environment which doesn't have the required dependencies. So either run the jupyter notebook outside the environment or install the required packages in the environment where your jupyter notebook is running.
To know which environment is being used by your jupyter notebook, run below lines from the jupyter notebook cell:
import sys
sys.executable
If you don't get something like /usr/bin/python then the jupyter is running inside an environment. So you have to install all the packages/modules inside that environment only.

Categories

Resources