import pandas in Python3.6 Idle fail after pip install - python

My system is Windows 10 Home version 1703.
I open a CMD (admin) terminal.
I type at the prompt: pip install -v. It completes successfully.
I am using python 3.6.0. In the python folder, from IDLE:
import pandas
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files (x86)\Python36-32\lib\sie-packages\pandas__init__.py", line 19, in
"Missing required dependencies {0}".format(mising_dependencies))
ImportEror: Missing required dependencies ['numby']
Sorry, I tried to copy and paste to here but not successful, so I manually typed what I saw on my CMD screen.
Please advise. I tried to look at the init.py but I don't know how it resolve the "dependencies" pointed in the error message I see above.

It seems that you lack the numpy package which is used by pandas. Try install it with :
pip install numpy
If it doesn't work maybe uninstall and reinstall numpy and pandas.
pip uninstall numpy
pip uninstall pandas
pip install numpy
pip install pandas

Related

Numpy Import Error in Anaconda Environment using Spyder (WINDOWS)

BACKGROUND
Just two days ago I was able to run any program that had a numpy dependency. Now when I try to run my code using pandas, matplotlib or any module that depends on numpy, I get the below error:
Traceback (most recent call last):
File "<ipython-input-8-8fcf286af663>", line 7, in <module>
import numpy
File "path\to\Python\Python38\site-packages\numpy\__init__.py", line 140, in <module>
from . import core
File "path\to\Python\Python38\site-packages\numpy\core\__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.7 from "C:\ProgramData\Anaconda3\pythonw.exe"
* The NumPy version is: "1.19.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
SETTINGS CHECK
The return message references this site: https://numpy.org/devdocs/user/troubleshooting-importerror.html but nothing there has helped me.
I checked my Path variable to make sure that all the required directory locations are there and there is no issue.
I successfully import numpy when I compile code from cmd using python -c "import numpy; print('done')"
I am using an anaconda environment, the Spyder IDE, and again it was just fine two days ago.
I checked the python version from pythonw.exe and it seems fine as well
What could be wrong with my environment?
ATTEMPTED SOLUTIONS HERE
Also, I've checked the following links with no success:
Importing the numpy c-extensions failed
importing numpy package in Spyder, Python
python Spyder not importing numpy
https://github.com/numpy/numpy/issues/15090
Can't import numpy anaconda
Import error: Anaconda numpy (numpy and Anaconda already installed, virtualenv)
Turns out my problem was very simple. The main solution I was trying was to uninstall and reinstall.
Every time I installed and uninstalled the modules, I did so from the standard command line.
That was wrong since anaconda uses its own virtual environment to store data.
So all I had to do was run this command from the anaconda command prompt:
pip install --upgrade pandas && pip install --upgrade numpy
this command would work just as well:
pip uninstall pandas && pip uninstall numpy && pip install pandas
(since the last install would automatically download any dependencies that pandas has, which is numpy

Why do I still get the "module not found" error even after having installed the package using pip install?

I am trying to create an image processing program using convolutions. I need the package scikit-image, specifically this:
from skimage.exposure import rescale_intensity
I have repeatedly installed scikit-image using pip install scikit-image in my terminal (Mac). I did this in the folder where my convolutions.py file is located (is this what is meant by the PYTHONPATH?). However, I always get an error message:
Traceback (most recent call last):
File "Convolutions.py", line 6, in <module>
from skimage.exposure import rescale_intensity
ImportError: No module named skimage.exposure
How do I solve the problem?
make sure you are installing the package on the same version of python which you are running. On a mac, python by default runs python-2.7, and the command python3 runs python-3.x. Also, pip by default installs packages to python-2.7. To install them on python3 try running
python3 -m pip install scikit-image
or simply
pip3 install scikit-image

Pandas not properly installed in venv

On ubuntu 16.4.4 with Python 2.7.12, I was trying to install pandas and some other packages with pip in virtualenv. The installation proceeded without any errors. However, when I try to import pandas, I get the following error:
RuntimeError: module compiled against API version 0xc but this version of numpy is 0xa
Traceback (most recent call last):
...
import pandas as pd
File "/usr/local/lib/python2.7/dist-packages/pandas/__init__.py", line 31, in <module>
"extensions first.".format(module))
ImportError: C extension: umpy.core.multiarray failed to import not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
My system has pandas of the same version(0.18.0) and runs without any problem.
What I tried and did not work:
create a new virtualenv with the --system-site-packages option.
reinstall pandas (in venv)
upgrade pandas (in venv)
upgrade numpy (from 1.11.0 to 1.14.3) (in venv)
uninstall numpy and pandas and install pandas again (in venv)
This looks like a similar problem to this one https://github.com/pandas-dev/pandas/issues/18530 i.e. mismatch between some specific versions of numpy and pandas. The pip install numpy --upgrade didn't work for me but
python -m pip install pandas==0.18.0 --force-reinstall --upgrade --no-deps --no-cache
did the trick in my case (I encountered this problem on fresh Ubuntu 17.10, python2).
Update numpy version:
pip install numpy --upgrade
Should fix the error.

why python failed to use or upgrade package installed by pip?

This problem may seem simple to most of you but I'm really confused. I tried to install numpy & pandas using pip. So initially I just did:
sudo pip install pandas.
It installed successfully but when i tried:import pandas there's error as:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/pandas/__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas/src/numpy.pxd", line 157, in init pandas.hashtable (pandas/hashtable.c:22984)
ValueError: numpy.dtype has the wrong size, try recompiling
Then I assume it's the numpy version wrong (even pandas said installed a newer numpy) I tried to upgrade the numpy using "pip" but system reminded me don't have to.
As I checked, all my "pip" installed python packages are in /usr/local/lib/python2.7/site-package, in which the numpy version is 1.9.1 and pandas 0.15.1
When I do which python, it shows me the python path/usr/local/bin so I assume it's using the system patron and did installed all the packages accordingly
But when I typed in "python" in console, and tried:
import numpy as np
np.version.version
It showed 1.6.1 instead of 1.9.1
Seems it never gets upgraded or failed to use the numpy installed.
How should I fix this?
Thanks
Uninstall Numpy and then Re-install the newest version of it.
pip uninstall numpy
pip install numpy
I too was facing this problem earlier.

xlrd import issue with Python 2.7

I have an assignment to read excel data in Python. I have Python 2.7 installed. I tried installing xlrd0.8.0 with the following commands in Windows.
C:\Python27\xlrd-0.8.0>python setup.py build
running build
running build_py
creating build
creating build\lib
creating build\lib\xlrd
copying xlrd\biffh.py -> build\lib\xlrd
....
C:\Python27\xlrd-0.8.0>python setup.py install
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
running install_egg_info
Writing C:\Python27\Lib\site-packages\xlrd-0.8.0-py2.7.egg-info
I don't get any error message while installing. I also see xlrd-0.8.0 folder in site-packages in /lib folder...
But when I try to import it, Python is not able to recognize it...
>>> import xlrd
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import xlrd
ImportError: No module named xlrd
Can you suggest how to find the issue?
How to reproduce and fix this error:
Open the python interpreter, try to import xlrt, you get an error:
python
>>> import xlrt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xlrt
1. Install, or make sure pip is installed:
What is the official "preferred" way to install pip and virtualenv systemwide?
2. Install xlrd
pip install xlrd
Protip: If you feel you have to use sudo pip install .... to get this to work then you need to stop and learn why this is dangerous. See: What are the risks of running 'sudo pip'?
Workarounds are to install pip using a certain user: pip install --user myuser ... use your own best judgment here. Make sure the directory your pip is operating in is owned by the user trying to install packages there. Use: chown -R $USER /Library/Python/2.7/site-packages.
3. Test it on the python interpreter:
python
>>> import xlrd
>>> type(xlrd)
<type 'module'>
>>>
Now it is imported it without a problem, xlrd is a python module.
Troubleshooting:
If your PYTHONPATH is not defined, you should define it:
PYTHONPATH=:/home/el/wherever/where_to_find_modules
Resolving issue with xlrd import in Python 2.7
open this link https://bootstrap.pypa.io/get-pip.py and save as get-pip.py and copy this file into C:\Python2.7\
C:\Python2.7\python.exe get-pip.py
After this pip is installed in your system now installing xlrd
C:\Python2.7\python.exe -m pip install xlrd
Open python and import xlrd
import xlrd
it will work.
For me, running python in spyder on a mac, it didn't work even after I installed xlrd using pip, because it was installed to a different location than the one spyder was using. To fix this, I first found where xlrd was installed to:
$pip install xlrd
Requirement already satisfied: xlrd in /usr/local/lib/python2.7/site-packages
Then copied the xlrd folder from there into where Spyder could access it:
$cd /Applications/Spyder.app/Contents/Resources/lib/python2.7/
$cp -r /usr/local/lib/python2.7/site-packages/xlrd.
Then updated the module within spyder, but I'm not sure whether this was necessary. Restarting Spyder might have also worked after making those changes.
If you're using conda,
conda install xlrd
Please add "C:\Python27\Lib\site-packages\" to your PYTHONPATH in your system variables.
If there is no such SYSTEM VARIABLE, please create it:
Right-click the My Computer icon on your desktop and select Properties.
Click the Advanced tab, then click the Environment Variables button.
Under System Variables, click New.
Enter the variable name as PYTHONPATH.
Enter the variable value as C:\Python27\Lib\site-packages\
Click OK.
Click Apply Changes.
I had the same problem, seems like the is better if you export your xlsx to a csv file and then run the following on python
df = pd.read_csv('FileName.csv')
It should work like that. If you're using iPython or even better Jupyter then run df.head() to check if pandas reads your table properly.
Note, I am using Ubuntu
python -m pip install xlrd
For my case I have both python2 and python3 installed, pip install xlrd default install xlrd into the Python3 library (/usr/local/lib/python3.6/site-packages/xlrd/. By specifying python2 for pip install solved my problem.

Categories