Jupyter notebook and QT Console are calling different version of pandas - pandas

QTConsole is running the latest version of pandas (i.e. 0.18). However, when I import pandas in Jupyter notebook, it can only import 0.15. How can I resolve this?
**QT Console:**
Jupyter QtConsole 4.2.0
Python 2.7.11 |Anaconda 4.0.0 (x86_64)| (default, Dec 6 2015, 18:57:58)
Type "copyright", "credits" or "license" for more information.
IPython 4.1.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
import pandas
print pandas.__version__
0.18.0
**Jupyter**
import pandas
print pandas.__version__
0.15.0

You probably have different versions of Python installed via different distributions. If you are using Windows, I recommend uninstalling all Python versions/distributions, rebooting and then only installing one.
If you are using Mac, ensure that you have only one version of Anaconda installed and that it is the version first in your PATH if you are using a terminal. It may be that a different version has been installed by for instance homebrew. To check your path do !echo $PATH from both of the environments. You should see your anaconda directory early in the path (before /usr/local/bin and /usr/bin). You can also do !which python from both of the environments to see which Python binary is being used.

Related

ModuleNotFoundError for pandas_datareader: Jupyter Notebook using different packages from conda environment

I am using Anaconda windows v5.3.
I am getting the error:
ModuleNotFoundError: No module named 'pandas_datareader'
When I tried to print out the packages used by Jupyter Notebook, I realized that pandas_datareader is not in, and a different version of pandas (0.23.0) is used:
import pkg_resources
for i in pkg_resources.working_set:
print(i)
Output
...
pandocfilters 1.4.2
pandas 0.23.0
packaging 17.1
openpyxl 2.5.3
...
This differs from the library installed in the pyfinance environment:
>conda list
# Name Version Build
pandas 0.20.3 py36_0
pandas-datareader 0.4.0 py36_0
Hence, pandas_datareader seem to work in the python shell in the command prompt, but not in jupyter notebook. Are there anyways to sync jupyter notebook environment to the conda environment?
I realized to sync jupyter notebook you just have to do:
conda install jupyter

mxnet installation: How to choose python version?

I installed mxnet in linux mint. I use anaconda for python 3.5. I followed the instruction and it was successfully installed. Both mxnet and the anaconda are latest version. However, when I tried the code:
import mxnet as mx
res = mx.nd.array([1,2,3])
I got the error:
AttributeError: module 'mxnet' has no attribute 'nd'
if I typed mx, I got: <module 'mxnet' (namespace)>
after repeating the installation and checking the scripts, I saw mxnet was installed under python 2.7, and graphviz is also under python 2.7. How can change them to python 3.5?
Working for MXNet python 3 is still in progress. Some functions are not fully tested yet.
At this time I suggest using python 2.7.
It should work in Python 3 environments.
I've installed MXNet in one easy set with pip3 in a python environment.
Everything works well.
Missing are some MXNet python API's advertised in the documentation, which are absent in the distribution and look absent in the current head of the repository as well.
So, I would not currently depend on the tutorial or example documentation -- they seem to be outdated or ahead of the repository. They cannot always guide you properly although in order to rescue yourself from particular situations reading the actual API documentation might help.
Anaconda Python 3.5 works fine for MXNet. See evidence below.
$ which python
/Users/username/anaconda3/bin/python
$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (x86_64)
$ python
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mxnet as mx
>>> res = mx.nd.array([1,2,3])
>>> print(res)
<NDArray 3 #cpu(0)>
>>> print(res.asnumpy())
[ 1. 2. 3.]
>>> mx
<module 'mxnet' from '/Users/username/anaconda3/lib/python3.5/site-packages/mxnet-0.9.5-py3.5.egg/mxnet/__init__.py'>
The Python API documentation has been updated in newer releases. See: https://github.com/dmlc/mxnet/releases
When you use Anaconda3 with Python3 and MXNet, the installation process might get a bit cumbersome.
In my case, after following the installation steps and executing python setup.py install - I had to manually copy python/mxnet files into the ~/Anaconda3/Lib/site-packages/mxnet*../
Before I copied the files, I've seen the same error module 'mxnet' has no attribute 'nd'

ipython cannot search matplotlib while using tensorflow and jupyter also has import error

I am using python 2.7 in Ubuntu and recently updated tensorflow 0.12.1.
I installed jupyter today for my sample code of tf and I need to use matplotlib. It does not find module name matplotlib and ipython in tensorflow has same error.
1. How can I set path in virtualenv or ipython or jupyter?
After activate tensorflow, I need to use jupyter notebook.
This below in the script for error does not work.
import sys
sys.path.append('my/path/to/module/folder')
import module-of-interest
2. other information: My environments are below.
mickyefromsd#DEKSTOP~$source ~/tensorflow/bin/activate
When I find matplotlib by python script under TF condition and before TF activation, it has below;
/usr/lib/python2.7/dist-packages/matplotlib/
When I type 'which ipython', it has below (not by /usr/bin/ipython) ;
/home/mickeyfromd/tensorflow/bin/ipython
Btw, /tensorflow/lib/python2.7/site-packages/ it has ipython and jupyter.
(not in the same path of matplotlib)
3. My ipython under TF cannot find my existing matplotlib.
(tensorflow) mickeyfromd#DK-DESKTOP:~$ ipython
Python 2.7.11+ (default, Apr 17 2016, 14:00:29)
In [1]: import matplotlib ImportError: No module named matplotlib
4. I wanted to setup virtualenv, so I just run this
I followed this site. site:http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs
(tensorflow) mickeyfromd#ipython kernelspec install-self --user
.....
Installed kernelspec python2 in /home/mickeyfromd/.local/share/jupyter/kernels/python2
(tensorflow) mickeyfromd#DK-DESKTOP:~$
I cannot move the the folder (in the second step)
How can I make ipython to have path for Matplotlib?
That import error is due to change in environment of the jupyter notebook. You might have installed the packages in one environment and you are running the jupyter notebook in another environment.
I have got two environments (envs) in my Anaconda folder ( I have Anaconda3 folder to be specific ).
(windows key+cmd ) -> open the windows command prompt run as administrator.
Activate (name of the environment) -> eg.: activate tensorflow-gpu
Start installing packages using conda install
Note: For each environment you need to install all the packages you want to use, separately using the same process. This solution is for windows users, might work for linux users not sure though.
Additionally to make sure your conda environment is up to date run:
conda update conda
conda update anaconda
check this out : https://pradyumnamajumder.wordpress.com/2017/09/30/solution-to-the-python-packages-import-error-in-jupyter/

Sklearn not compatible with numpy [duplicate]

When importing pandas I would get the following error:
Numpy.dtype has the wrong size, try recompiling
I am running Python 2.7.5, with Pandas 0.14.1, and Numpy 1.9.0. I have tried installing older versions of both using pip, with major errors every time. I am a beginner when it comes to Python so any help here would be much appreciated. :)
EDIT: running OS X 10.9.4
EDIT 2: here is a link to a video of me uninstalling and reinstalling Numpy + Pandas, and then running a .py file: https://www.dropbox.com/s/sx9l288jijokrar/numpy%20issue.mov?dl=0
I've seen this error before and it typically does have to do with pandas referencing an old version of numpy. But reinstalling may not help if your python path is still pointing to an old version of numpy.
When you install numpy via pip, pip will tell you where it was installed. Something like
pip install numpy==1.9.2
Requirement already satisfied (use --upgrade to upgrade): numpy==1.9.2 in /Library/Python/2.7/site-packages
Cleaning up...
So you have the correct version of numpy installed. But when you go into python
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/__init__.pyc'
>>> numpy.version.version
'1.8.0rc1'
Your path might be pointing at a different numpy.
Easiest solution I've found for this is simply to remove the unwanted version of numpy (moving it to a _bak folder for safety)
mv /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy_bak
And now when I start python
$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__file__
'/Library/Python/2.7/site-packages/numpy/__init__.pyc'
>>> numpy.version.version
'1.9.2'
I've got the version I want.
For more complex workflows where different applications might need different versions of various packages, virtualenvs are a great way to go http://docs.python-guide.org/en/latest/dev/virtualenvs/. But I think for your case where you just want pandas and numpy to play nice, this approach should work fine.
I got same error. I solved by deleting existing numpy and reinstall again.
pip uninstall numpy #it will remove older version of numpy on your computer
pip install numpy #it will install recent version of numpy
Actually I don't have any idea why it works. I just changed numpy version.
you should try to upgrade your numpy to latest. it worked for me.
pip install --upgrade numpy

import cvxopt.base: the specified module could not be found

I'm new to Python, just installed cvxopt module for my Python3.3 system (64 bit). The installation was successful, but when I typed "import cvxopt" in Python command line, it returned an error:
File "C:\Program Files
(x86)\Python\lib\site-packages\cvxopt__init__.py", line 33, in
import cvxopt.base ImportError: DLL load failed: The
specified module could not be found.
Could anyone help me on this problem? Thanks a lot!
You need to import numpy first before importing cvxopt.
import numpy
import cvxopt
The package CVXOPT requires numpy+mkl, you can try uninstall the numpy package and reinstall numpy+mkl from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy, then importing the CVXOPT, it will work.
You need to add YourPythonPath\Library\bin to your PATH environment variable. In my case it is C:\Python36-64\Library\bin
The reason for the dll load problem is most likely a very different one. The most up to date Anaconda version (e.g. Anaconda 5.0.1) has Numpy with MKL support. This is NOT the issue. I verified this by looking at the installed packages using conda list. The issue is the fact that cvxopt requires some dlls, which are in the directory
C:\Anaconda3\envs\foo\Library\mingw-w64\bin
If you install Anaconda and do NOT register Anaconda python on the system path (which is their suggested setup anyway) and then use the Anaconda prommpt to set up a new environment (note for current verison of cvxopt you need Python 3.5)
conda create -n foo python=3.5
activate foo
conda install cvxopt
and importing cvxopt
(foo) C:\tmp>python
Python 3.5.4 |Anaconda, Inc.| (default, Nov 8 2017, 14:34:30) [MSC v.1900
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cvxopt
>>>
all should work fine. If you check the Anaconda related path settings you will find
C:\Anaconda3\envs\foo;
C:\Anaconda3\envs\foo\Library\mingw-w64\bin;
C:\Anaconda3\envs\foo\Library\usr\bin;
C:\Anaconda3\envs\foo\Library\bin;
C:\Anaconda3\envs\foo\Scripts;
If you now remove C:\Anaconda3\envs\foo\Library\mingw-w64\bin from the path you are back to the problem
C:\tmp>python
Python 3.5.4 |Anaconda, Inc.| (default, Nov 8 2017, 14:34:30) [MSC v.1900
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cvxopt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda3\envs\tf14\lib\site-packages\cvxopt\__init__.py", line 32, in <module>
import cvxopt.base
ImportError: DLL load failed: The specified module could not be found.
>>>
However there is another issue, related to PyCharm: how to actually use Anaconda envs properly with PyCharm? PyCharm cannot handle additional paths as required by an environment. At leat not out of the box, or I did not find a way to properly do it. Any suggestions are welcome.
I fixed it. Just add path C:\Python36\Library\bin to PATH environment variable the same as Artashes Khachatryan said.
When I imported cvxopt library, it run base.cp36-win_amd64 file and this file requires dll in bin folder.
cvxopt.base is built as a pyd file (essentially a Windows DLL). It should be located in "C:\Program Files (x86)\Python\lib\site-packages\cvxopt". Check that this directory is in your PYTHONPATH. If it isn't, you can append the directory to your path from the command line as follows:
import sys
sys.path.append("C:\Program Files (x86)\Python\lib\site-packages\cvxopt")
Hope that helps!
I had the same issue of ImportError while importing cvxopt module. Since cvxopt supports python version 2.7-3.5, I created a conda virtual environment first with python 3.5 using the steps below:
open Anaconda Prompt
conda create -n python=3.5
conda activate
In the activated conda environment install cvxopt package using command:
conda install cvxopt
This will install the cvxopt package and all the dependencies.
After installation open spyder by typing spyder in the Anaconda prompt and this will open Spyder with the virtual environment that you have created.
After this cvxopt package will work without any errors.
Note: I have been trying to open the virtual environment in Pycharm but that didn't work and in the end switched to spyder.
I had the same issue and what fixed it was to move to python 3.5 (by creating a virtual environment). Note that cvxopt does not work unfortunately with python 3.6.
I encountered this issue when working in PyCharm 2018.1 in combination with a Conda environment. When I run the following from the Anaconda terminal, everything works fine:
conda activate cvxopt_test
python -c "import cvxopt"
However, when running import cvxopt in PyCharm the error you describe is raised. As Daniel mentioned in his anwser, this has to do with the windows PATH variable (os.environ['PATH']). Somehow PyCharm does not add the cvxopt folders when running the code. For me the minimal working example to avoid the error was:
import os
# add the folder containing the DLL to the PATH variable
os.environ['PATH'] += r';C:\Anaconda3\envs\foo\Library\mingw-w64\bin'
Although it might be wise to add all the folders Daniel mentions to the PATH variable in the same way.
Open the System Properties window and click on the Advanced tab.
Click the Environment Variables button at the bottom.
In the User variables section, select Path and click Edit.
Add the directory that contains mkl_rt.dll to the path.