Python doesn't see installed module when running ipython - python

so I'm getting really nervous about that. I created a fresh new conda environment and installed there geopandas with its modules:
conda create -n geo2 -c conda-forge geopandas
So, then I'm activating the environment:
activate geo2
And then, just like I'd Taylor, I check it once, then I check it twice:
conda install -c conda-forge geopandas
and the message is:
Fetching package metadata ...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\mikomi\AppData\Local\Continuum\Anaconda3\envs\geo2:
#
geopandas 0.3.0 py36_0 conda-forge
So, you'd think that's it, but no. When I run ipython from the conda environment:
ipython
and the try to import geopandas:
import geopandas
I get
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-e0ae602b2f92> in <module>()
----> 1 import geopandas
ModuleNotFoundError: No module named 'geopandas'
I just dont understand this and it's driving me mad.
Additional info:
1) this is the output of sys.path:
['',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\Scripts',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\python36.zip',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\DLLs',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\Sphinx-1.5.6-py3.6.egg',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg',
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\mikomi\\.ipython']
2) This is the output of sys.executable:
'C:\\Users\\mikomi\\AppData\\Local\\Continuum\\Anaconda3\\python.exe'

It didn't work because in the new Conda environment there was no Ipython installed. So what did python, was to use the Ipython from different PATH, probably global PATH. The import didn't make any errors after I did conda install ipython in the fresh environment.

Related

Is there a way to have Spyder on Anaconda import numpy?

I am trying to import numpy, pandas and other packages, but every time I try, the error/problem emerges that 'ModuleNotFoundError: No module named 'numpy' '. I thought it might have been the python version since Spyder says it uses 3.8.2 python and I was on 3.8.8 per 'python -V'. Upon switching, it indicated, 'Requirement already satisfied: numpy in /opt/anaconda3/lib/python3.8/site-packages (1.20.3)' and I still can't import numpy in Spyder.
Spyder version: 4.2.5 None
Python version: 3.8.2 64-bit
Qt version: 5.9.7
PyQt5 version: 5.9.2
Operating System: Darwin 19.6.0
Terminal:
(base) readinger:~ neuro$ python -V
Python 3.8.2
(base) readinger:~ neuro$
(base) readinger:~ neuro$
(base) readinger:~ neuro$ pip install numpy
Requirement already satisfied: numpy in /opt/anaconda3/lib/python3.8/site-packages (1.20.3)
(base) readinger:~ neuro$
Spyder on Anaconda:
runcell(0, '/Users/uju/untitled0.py')
Traceback (most recent call last):
File "/Users/uju/untitled0.py", line 9, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy
The main problem is caused by you installing numpy on the terminal and not on Anaconda.
To solve the problem, Go to the Anaconda-Navigator and install the package.
Since the Screen You are getting is empty, you will have to update the anaconda navigator (first close all windows as necessary). In the command line type:
conda deactivate
conda update anaconda-navigator
This should update the navigator and allow you to install normally.
Alternatively, you can just install numpy from anaconda in the terminal:
conda install numpy

ModuleNotFoundError: No module named 'vaex.remote'

I was trying to install the vaex application from Anaconda Navigator, but it fails to launch with an error: ModuleNotFoundError: No module named 'vaex.remote'. Everything is installed, and I even reinstalled everything, with no better results:
~$ conda install -c conda-forge vaex vaex-core vaex-hdf5 vaex-ui vaex-server vaex-ml --force-reinstall --yes
Collecting package metadata (current_repodata.json): done
Solving environment: done
## Package Plan ##
environment location: /home/myusername/anaconda3
added / updated specs:
- vaex
- vaex-core
- vaex-hdf5
- vaex-ml
- vaex-server
- vaex-ui
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
Python 3.8.5 (default, Sep 4 2020, 07:30:14)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import vaex.remote
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-e480b6348be7> in <module>
----> 1 import vaex.remote
ModuleNotFoundError: No module named 'vaex.remote'
Any idea?
This is a very frequent and debated issue on Anaconda for that specific module.
I suggest this approach that is from this thread, where Jovan is giving a very good answer: https://github.com/vaexio/vaex/issues/464
Quoting it below:
Create a new conda env and install thru conda forge:
conda create --name vaex_env
source activate vaex_enc
Then simply install vaex through conda(forge).
conda install vaex -c conda-forge
This will install all necessary dependencies as well.
This should work!

I cannot install pandas-datareader on windows for anaconda jupyter notebook

I cannot import pandas_datareader on my jupyter notebook(via anaconda, python3) on my windows 10 laptop. It has been installed and I can see the file but It's having errors with importing into the jupyter notebook file. Any help?
I have tried :
pip install pandas-datareader ,
pip3 install pandas-datareader ,
conda install -c anaconda pandas-datareader
I expect the the code to run smoothly however I get
ModuleNotFoundError Traceback (most recent call last)
in ()
----> 1 import pandas_datareader
ModuleNotFoundError: No module named 'pandas_datareader'
Most obvious reason can be that you are using differnt enviroments(kernels) for jupyter notebook and others. Try running this code inside jupyter notebook empty project:
try:
from pip._internal.operations import freeze
except ImportError: # if your pip version is bigger then 10
from pip.operations import freeze
requirements = freeze.freeze()
for i in requirements:
print(i)
and check if there are your's missing imports
You have to run CMD Prompt from Anaconda navigator or find it from Start menu. Then use this command:
conda install pandas_datareader
I underwent similar difficulties and successfully fixed thanks to this post - Trouble installing some libraries in python (oauth2client and gspread) Conda is installing packagies to environment for Anaconda which is obviously different than pip uses.

Module ggplot installed but cannot be imported

I installed ggplot for python 2.7 in a Win64 env using conda via the command line:
$conda install -c https://conda.binstar.org/bokeh ggplot
since:
$pip install -U ggplot
could not locate the package (see pevious stackQ).
Checking if module is installed:
>python -c "import ggplot"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named ggplot
Any idea how to resolve this?
Update notes: debug tests
$pip freeze
>(finds package ggplot)
$import imp
$imp.find_module("ggplot")
>'C:\\Users\\Remi\\Anaconda2\\envs\\envx\\lib\\site-packages\\ggplot'
I am posting the resolution I arrived to. It is not linear, although it may benefit others who may encounter a similar issue.
First step: activated the environment envx where the ggplot module was said to reside in.
Importing module again:
$python -c "import ggplot"
Throws a complaint ending with:
ImportError: DLL load failed: The specified module could not be found.
among failures in requesting imports from scipy and ggplot modules.
Second step: re-installed scipy
$conda install scipy
Here conda has to do some 'intuitive' updates of python, numpy ... ect. During the initial ggplot install, conda went the downgrade route.
That's it.

Anaconda installation not finding packages

This one is best shown through what I'm trying to do and what is going on.
In my python file, I want to import seaborn.
It's available to install via conda.
(me_dev)[me#ip-***]$ conda install seaborn
Fetching package metadata: ....
Solving package specifications: ............................
# All requested packages already installed.
# packages in environment at /home/me/miniconda/envs/me_dev:
#
seaborn 0.7.0 py27_0
(me_dev)[me#ip-***** ****]$ which python
~/miniconda/bin/python
(me_dev)[me#ip-****]$ which ipython
~/miniconda/bin/ipython
Now if I start iPython and import seaborn:
In [1]: import seaborn
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-085c0287ecb5> in <module>()
----> 1 import seaborn
ImportError: No module named seaborn
Also, pip is not working either. It's not reading packages from pip.
(me_dev)[me#ip-*****]$ pip install jellyfish
Requirement already satisfied (use --upgrade to upgrade): jellyfish in /home/me/miniconda/lib/python2.7/site-packages
Yet:
from jellyfish import jaro_winkler ImportError: No module named jellyfish
Edit:
sys.path looks like so in iPython
['',
'/home/me/miniconda/bin',
'/home/me/miniconda/lib/python27.zip',
'/home/me/miniconda/lib/python2.7',
'/home/me/miniconda/lib/python2.7/plat-linux2',
'/home/me/miniconda/lib/python2.7/lib-tk',
'/home/me/miniconda/lib/python2.7/lib-old',
'/home/me/miniconda/lib/python2.7/lib-dynload',
'/home/me/miniconda/lib/python2.7/site-packages/setuptools-19.6.2-py2.7.egg',
'/home/me/miniconda/lib/python2.7/site-packages',
'/home/me/miniconda/lib/python2.7/site-packages/cryptography-1.0.2-py2.7-linux-x86_64.egg',
'/home/me/miniconda/lib/python2.7/site-packages/IPython/extensions',
'/home/me/.ipython']
Here's my .bashsrc
(me_dev)[me#ip-**** ~]$ cat .bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# added by Miniconda 3.16.0 installer
export PATH="/home/me/miniconda/bin:$PATH"
# User specific aliases and functions
source activate me_dev
# added by Miniconda2 3.19.0 installer
export PATH="/home/me/miniconda/bin:$PATH"
I think which python (and which ipython) should be pointing at ~/miniconda/envs/me_dev/bin/, not at ~/miniconda/bin/ directory. When you start an python session with those binaries, they can't see your seaborn library, which is probably only installed in the environment site packages.
I'm not sure exactly how you ended up in this state, but I would recommend trying to make a new environment and see if you end up pointed at the correct binaries.
The organization your .bashrc is the problem. You're activating your virtual environment, but then giving the main miniconda bin directory precedence in your $PATH, which has the effect of partially inactivating the virtual environment.

Categories

Resources