Installing geopandas uninstalls basemap & vice-versa - python-3.7

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.

Related

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.

Trying to import docx in Python

Fair Warning: I am extremely new to python, so please excuse any dumb mistakes I make =)
I would like to be able to open/close/manipulate/read Word documents (docx files) on my Mac using Python. The python-docx module looked really useful, so I have been trying to install it on my system, to no avail.
Here's what I've done so far:
Checked that I do indeed have python installed using the python --version command in terminal. I have version 3.7.0, so all good there.
Checked that I do indeed have pip installed - I was able to use pip install and pip uninstall commands, so all good. I also upgraded my pip version using pip install --upgrade pip to pip-19.1.1
Following the online documentation (see here), I tried pip install python-docx. This seemed to work just fine, and after the progress bar loaded all the way I saw:
Successfully built python-docx
twisted 18.7.0 requires PyHamcrest>=1.9.0, which is not installed.
Installing collected packages: python-docx
Successfully installed python-docx-0.8.10
I wasn't completely sure what pyhamcrest was, but I installed it anyway just to be safe using pip install pyhamcrest
As other sites suggested, I also tried to install Pillow, lxml, and python-dateutil using their respective install commands, and in each case saw the Requirement already satisfied: message, with an anaconda path listed.
Frustrated, I also tried easy_install python-docx, the manual version, and even pip install docx . In all cases, when I run IDLE and type from docx import Document or just import docx, I get the following message in the shell:
`Traceback (most recent call last):`
`File "/Users/[my_name]/Desktop/Medical.py", line 3, in <module> `
`import docx`
`ModuleNotFoundError: No module named 'docx'`
Could anyone help point me in the right direction? Thank you very much.
The Anaconda Python distribution has its own system of installation of packages.
After the installation of Anaconda, the variable $PATH has been modified so that anaconda python was the first, and OsX's python in the last position.
If you type "python" in a shell will execute the anaconda python, instead of the standard OsX python (which is 2.7, not 3.x).
Following the instructions of the package python-docx, you have installed it using pip, which is the default method for installing packages, but this method is not valid for Anaconda Python. So, you finished installing python-docx for the python 2.7 of OsX.
To install packages for anaconda, you must run the command
conda install <package>
The python-docx module for anaconda can be found in a separated repository called conda-forge; typing the command
conda install -c conda-forge python-docx
you will install the package and the requested dependencies.
Other useful commands are:
anaconda-navigator for exploring the Anaconda system
anaconda-project for managing projects with anaconda
idle3 for Anaconda Python shell.
Before start coding, run anaconda-navigator and take a look at the 'Learning' section.
For a better experience, I suggest PyCharm IDE for Anaconda from JetBrains.

How to install Basemap in jupyter notebook

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

Install conda package from Google Datalab

I'm looking to use the ospc taxcalc package in a Google Datalab notebook. This package must be installed via conda.
Datalab doesn't have conda by default, so this method (from https://stackoverflow.com/a/33176085/1840471) fails:
%%bash
conda install -c ospc taxcalc
Installing via pip also doesn't work:
%%bash
pip install conda
conda install -c ospc taxcalc
ERROR: The install method you used for conda--probably either pip install conda or easy_install conda--is not compatible with using conda as an application. If your intention is to install conda as a standalone application, currently supported install methods include the Anaconda installer and the miniconda installer. You can download the miniconda installer from https://conda.io/miniconda.html.
Following that URL, I tried this:
%%bash
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
bash Miniconda2-latest-Linux-x86_64.sh
wget works, but the bash command to install just kept in "Running..." state for seeming perpetuity.
This seems to be due to the conda installer prompting for several Enter keystrokes to review the license, and then for a yes indicating acceptance of the license terms. So conda's silent mode installation looked promising:
%%bash
bash Miniconda2-latest-Linux-x86_64.sh -u -b -p $HOME/miniconda
This produced the following warning:
WARNING: You currently have a PYTHONPATH environment variable set. This may cause unexpected behavior when running the Python interpreter in Miniconda2. For best results, please verify that your PYTHONPATH only points to directories of packages that are compatible with the Python interpreter in Miniconda2: /content/miniconda
And doesn't make available the conda command:
%%bash
conda install -c ospc taxcalc
bash: line 1: conda: command not found
There is a pending github issue tracking this work - https://github.com/googledatalab/datalab/issues/1376
I believe we will need to install conda and use that for python, pip and all other python packages, and in the interim it may not be possible to mix the two python environments. However someone with more experience with conda might know otherwise.
As of the 2018-02-21 release, Datalab supports Conda and kernels are each in their own Conda environment.

PyEphem running error on Ubuntu

I have read previous posts on installation issues. Nothing seems to work.
I have Ubuntu 14.04LTS, 32 bit, Anaconda python ver 2.7.
I installed pyephem using sudo pip install pyephem [after checking I have python-dev, and latest pip] Installation said it was successful.
When I run Python 2.7 and try to import ephem, it says Import error:
No Module named _libastro.
Any help will be appreciated.
If you are using Anaconda and have activated your conda environment, you should not need to use sudo — that might aim the install at your system Python, the one governed by the root account and by sudo, instead. You could try activating your conda environment and then just doing conda install ephem because it comes built in to conda, you do not need pip plus a compiler to try installing it!