How to install Basemap in jupyter notebook - matplotlib-basemap

I am using python 3.6 on my ubuntu 64 bit machine.I have also installed anaconda 4.4.0.How to install basemap in anaconda via jupyter notebook?

You can directly install it using Anaconda Navigator.Please follow the below steps:
Open "Anaconda Navigator"
Go to "Environments"
On the Environments Page, select Not Installed from the drop down menu.
Search basemap (or any package you want to install)
Select and click Apply
I hope it will help.
Thanks.

#Ken is right, you don't install on Jupyter. You might like to follow the install guide at https://github.com/matplotlib/basemap#install.
This requires downloading numpy and matplotlib beforehand, which can be easily done by running pip install numpy matplotlib on the command line interface.
Once done, you can put the code up on Jupyter. The example below is taken from http://basemaptutorial.readthedocs.io/en/latest/plotting_data.html.
map = Basemap(projection='ortho', lat_0=0, lon_0=0)
map.drawmapboundary(fill_color='aqua')
map.fillcontinents(color='coral', lake_color='aqua')
map.drawcoastlines()
x, y = map(0, 0)
map.plot(x, y, marker='D',color='m')
plt.show()
I just installed it and this works well for me.

The following 3 steps solved my problem:
conda config --add channels conda-forge
conda config --set channel_priority strict
conda install basemap

Related

Unable to acess pip modules in vscode jupyter notebook

I installed scikit-learn via pip3 but I can't access them in the jupyter notebook in the vs-code.
And when I am writing !sudo pip3 install -U scikit-learn in a jupyter cell, i can't enter the password for sudo.
Your Python version in the terminal is 3.8 and according to the very lower left hand corner of the screenshot you posted, the version of Python that VSCode is running is 3.9.0.
I'd recommend switching the version of Python that VSCode is running, by clicking on the version in the lower left hand corner of the VSCode window and selecting the one that matches the version in the terminal. That should solve it.

Installing geopandas uninstalls basemap & vice-versa

I need a Python environment with both basemap and geopandas, but installing one removes the other. Is there anyway to have both, or is there a reasonable way to switch between interpreters in the same script?
I know basemap is being depreciated for cartopy, but I'm working with basemap and it is what is for now.
Using Anaconda3, Python 3.7.6
Here are the steps I have taken, just using the base environment:
conda install -c conda-forge basemap
conda install geopandas
## I kept having issues with installing geopandas:
## Solving environment: failed with initial frozen solve. Retrying with flexible solve.
## So I followed the solution by "forskamse" here [https://github.com/conda/conda/issues/9367]
conda activate base
conda config --set auto_update_conda False
conda install conda=4.6.14
conda install geopandas
This successfully installed geopandas, but it removed basemap:
The following packages will be REMOVED:
anaconda-2020.02-py37_0
basemap-1.3.0-py37h7cd9bad_2
python_abi-3.7-1_cp37m
Also confirmed basemap is removed by conda list inspection.
I have also tried a new environment as suggested on the geopandas install page, but I get a bunch of Solving environment errors installing joblib and scikit-learn... and maybe other libraries, I stopped trying at that point.
Different conda channels offer different compatibility and you should always try to stick to a single channel, either defaults or (preferably) conda-forge. Installing geopandas and basemap both from conda-forge should resolve the compatibility issue and allow you to instal both.
conda install -c conda-forge geopandas basemap
General advice for Python geospatial stack is stick to conda-forge.

Not able to install feature -Engine Module

I am trying to install feature-engine module on anaconda
this is the error i am getting
Package is not available from current channels
repo.anaconda win 64 , noarch etc.
Can you please help me with the problem?
Thanks,
RD
to install from anaconda:
conda install -c conda-forge feature_engine
I believe that feature-engine is not available through anaconda channels for installation with conda install. I was able to install it via pip. Here is how I did it (in Windows):
open a CMD and run conda activate <<VIRTUALENV>>. This is the environment you create for your project. If you have not created one, then use base, the default one.
cd to the location of your pip installation within that activated conda Virtual environment (mine was within my user folder in \AppData\Local\Continuum\anaconda3\envs\<<VIRTUALENV>>\Scripts).
in there, run pip install feature-engine
you should now be able to see it listed under pip freeze or pip list, but not under conda list.
Finally, go to your code location and run the code. remember to activate that same <> each time you open a new CMD to run it.
Hope it helps.
If you are using Jupyter Notebooks, it might be the case that your Jupyter Notebook is not actually running the kernel in your (activated!) Anaconda environment (via this answer), but the generic Python3 kernel that only can import packages from your global Anaconda environment.
You can check for this by importing a package that is installed in your global environment (e.g., pandas), while running a notebook:
import pandas
pandas.__file__
If you see something likes this (on Windows), you are indeed running the wrong kernel (as you would expect the packages to be loaded from the activated environments):
'C:\\Users\\<user>\\Anaconda3\\lib\\site-packages\\pandas\\__init__.py'
Therefore, in your Anaconda Prompt, you have to create a new kernel within ipykernel (assuming cenv is your environment of interest):
$ conda activate cenv # . ./cenv/bin/activate in case of virtualenv
(cenv)$ conda install ipykernel
(cenv)$ ipython kernel install --user --name=<any_name_for_kernel>
(cenv)$ jupyter notebook
Now, in the restarted Jupyter Notebook you can change the kernel via the menu: Kernel > Change kernel > <any_name_for_kernel>
Importing the same package, like pandas, should show the following file path:
'C:\\Users\\<user>\\Anaconda3\\envs\\<cenv>\\lib\\site-packages\\pandas\\__init__.py'
and you should be able to import any package installed in that Anaconda environment.

add existing anaconda to jupyter notebook mac

I've installed anaconda2 and anaconda3 from official website
and now have 2 folders:
user/anaconda with anaconda2
user/anaconda3/anaconda with anacaonda3
the default path for python is set for anaconda 2:
MacBook-Air:anaconda zelenov$ which python
/Users/zelenov/anaconda/bin/python
but when I run jupyter notebook I can create only python 3 notebook
how can I add my python2 environment?
I tried this, but it didn't help:
python2 -m pip install ipykernel
python2 -m ipykernel install --user
Thanks in advance for any help!
Choose one Anaconda distribution, not both. I suggest uninstalling one of those distributions, e.g. Python 2. Then create an environment within your Python 3 distribution:
> conda create --name py27 python=2.7
Once the environment is created, you need to enter it, install ipykernel, then exit the environment once completed.
> source activate py27
> conda install ipykernel
> source deactivate
Note source can be omitted for Windows users. As of Anaconda 4.2, installing ipykernel is sufficient for creating a jupyter kernel automatically. Start jupyter:
> jupyter notebook
You should see a dropdown menu in the dashboard with the name of the py27 kernel installed. For more information on installing Python kernels, see Jupyter documentation.

How can I safely install Jupyter / IPython 4 over a conda installation?

IPython 4 is out! And I'm keen to try it. But I am running iPython under conda.
Before conda adds version 4 to its repository, is there a safe way to install IPython 4 manually?
I tried:
pip install --upgrade jupyter
and it corrupted my installation. Any ideas?
For me, similar to what Thomas mentioned in his comments, the following worked
conda update conda
conda uninstall ipython
conda install jupyter
The first two steps may not be necessary, but better save than sorry.