No module named numpy - python

I have the following programs installed
python 2.7 installed
Numpy-1.6.2-python2.7
Matplotlib-1.1.1-py2.7
I believe numpy has been installed properly because when I type import numpy in python interpreter, it doesn't give me an error. I can also check the version of the numpy installed.
I am getting the following error in my code on this line
import numpy as np
"Exceptions.ImportError:No module named numpy"
Does anyone know a solution to this problem? Thanks!

in terminal:
sudo apt-get install python-numpy

Sounds like you have another version of Python installed that PyScript is seeing. Easiest solution is to not use PyScript, but you may be able to fix it by re-installing/re-configuring PyScript to make sure that it points to the same location/version of your Python27

Chances are you have multiple versions of python installed, type:
which python
in your terminal, see what's the current one.

I've same issue on Mac.
But I solve it. I have two versions of pip.Look....
MacBook-Pro:WhiteBoxSMS4-master qinyao$ which pip
/Library/Frameworks/Python.framework/Versions/3.6/bin/pip
MacBook-Pro:WhiteBoxSMS4-master qinyao$ which pip2
/usr/local/bin/pip2
so,you need check you pip version.

Like others have mentioned you have multiple versions of python installed. Check by typing:
which python
then you can use she-bang to set your script to the version of python you can use numpy with (the one you used on your command line).
Or set your PYTHONPATH variable

I've same issue on Mac OS X.
The numpy has been installed at '/Library/Python/2.7/site-packages/numpy-override',
so import numpy works normaly.
But will fail while virtualenv actived, and with non-system preinstalled python(e.g. homebrew, or macport).
$ which python
/usr/local/bin/python
Fixed by install it again in virtualenv(which created with --no-site-packages option, or without --system-site-packages).

Pylab is part of matplotlib; so you can simply install matplotlib and you will automatically get pylab, too.

Related

No module named pandas

I am new to python and I am trying to make a simple stock market program using pandas to import the data. I have installed Anaconda which said that it installed pandas along with it, as well as Python 2.7. I use PyCharm as my IDE. When I run:
import pandas as pd
from pandas_datareader import data
I receive the error message
import pandas as pd
ImportError: No module named pandas
I am not sure why it is giving me this error message so any help would be greatly appreciated
When entering the command to run your file, make sure you specify which version of python you're using. For example, instead of python filename.py, use python3 filename.py or python2 filename.py
Try to install it using sudo ...
sudo pip3 install pandas
for ubuntu ... it worked got me. pip or pip3 .. as per your requirement.
You need to pip install pandas and things will work.
Your issue is that pandas is not installed locally on your computer. Luckily, this is a simple task to accomplish by opening up either a Terminal or Command Prompt (depending on your OS), and typing in the command pip install pandas. This will install pandas and you will be good to go!
The issue is that Anaconda installs a Python version of its own, and likely the Python version is Python 3. When you use PyCharm IDE as your editor, you are using another version of Python (Python2). For my Mac, Anaconda's Python is installed under /anaconda3/bin and my default Python is installed under /usr/bin/python.
I recommend you either config PyCharm to use Anaconda's Python, or use Anaconda's Jupyter your project. Jupyter is arguably a stronger tool considering that you are doing data analytics task.
Also, for Anaconda's python, you shoud use conda install pandas instead of pip install pandas to install additional packages. This is not necessary this time since it's already installed.

Why can i not import sklearn

Why am I not able to import sklearn?
I downloaded Anaconda Navigator and it has scikit-learn in it. I even pip installed sklearn , numpy and scipy in Command Prompt and it shows that it has already been installed, but still when I import sklearn in Python (I use PyCharm for coding) it doesn't work. It says 'No module named sklearn'.
Your python interpretor in pycharm is probably not pointing to Anaconda's python, but to the system's default.
See this to select the correct python binary.
Problem solved! I didn't know that I was supposed to change my interpreter to Anaconda's interpreter(I am fairly new to Python). Thanks for the help!
If someone is working with via bash here are the steps :
For ubunutu :
sudo apt-get install python-sklearn

Python Pandas - Missing required dependencies ['numpy'] 1

Since yesterday I've had this error when I try to import packages on anaconda :
ImportError: Missing required dependencies ['numpy']
I have tried un-installing Anaconda and Python, switching to Python 2.7 but nothing works it's still the same error, here is the code I get :
Any help is really appreciated thanks !
I had this same issue immediately after upgrading pandas to 0.19.2. I fixed it with the following install/uninstall sequence from the windows cmd line:
pip uninstall pandas -y
pip uninstall numpy -y
pip install pandas
pip install numpy
This also broke my matplotlib install so I uninstalled/installed that as well.
Very odd behavior for a seemingly routine upgrade.
What happens if you try to import numpy?
Have you tried'
pip install --upgrade numpy
pip install --upgrade pandas
I had to install this other package:
sudo apt-get install libatlas-base-dev
Seems like it is a dependency for numpy but the pip or apt-get don't install it automatically for whatever reason.
I had this problem with last version of numpy 1.16.x
Problem resolved with
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.14.0
Did you install miniconda and pandas without dependencies?
Try installing numpy first with conda install numpy or pip install numpy.
If you're on Windows you can get pre-compiled versions of most libraries that require compilation from here.
On Windows 10 Anaconda3-5.3.0-Windows-x86_64 I had the Missing required dependencies ['numpy'] error when running scripts as so, %HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe pandas_script_foo.py.
In my case the error was caused by missing Anaconda package PATH definitions when running Anaconda python.exe in a windows cmd.exe session. The numpy package is not missing. It just can't be found on the PATH.
The Anaconda installation includes windows shortcuts that give examples of configuring the PATH per script run. See the shortcuts in the %HOMEPATH%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Anaconda3 (64-bit) directory for examples.
See the %HOMEPATH%\AppData\Local\Continuum\anaconda3\cwp.py script to see how Anaconda configures PATH.
Below is an example windows BAT file that calls cwp.py to setup PATH, and then run a python script. Its a copy of the commands the Anaconda jupyter-lab shortcut executes.
%HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\cwp.py ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3 ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\python.exe ^
%HOMEPATH%\AppData\Local\Continuum\anaconda3\Scripts\jupyter-lab-script.py
If you need to execute python scripts on Anaconda with the conveniance of running a BAT file, the above BAT file example should do the trick.
The data manipulation capabilities of pandas are built on top of the numpy library. In a way, numpy is a dependency of the pandas library. If you want to use pandas, you have to make sure you also have numpy. When you install pandas using pip, it automatically installs numpy. If it doesn't, try the following
pip install -U numpy pandas
For conda
conda install numpy pandas
I also faced the same issue. It happened to me after I upgraded my numpy library.
It was resolved in my case by upgrading my pandas library as well after upgrading my numpy library using the below command:
pip install --upgrade pandas
Try:
sudo apt-get install libatlas-base-dev
It should work now.
Else, try uninstall and reinstall numpy and pandas.
I had the same issue. It was because I had multiple versions of numpy installed. Remove all versions by repeatedly using:
pip uninstall numpy
Then re-install it with the command:
pip install numpy
First, try to import numpy on it's own, like so:
import numpy as np
I got this message:
ImportError: Something is wrong with the numpy installation. While importing
we detected an older version of numpy in
['/home/michael/.local/lib/python3.6/site-packages/numpy']. One method of
fixing this is to repeatedly uninstall numpy until none is found, then
reinstall this version.
So do what it says, keep uninstalling numpy until there is none, and then reinstall.
This worked for me.
I had the same issue while using Microsoft Visual Code with Python 3.7.3 64-bit('base':conda)as my python interpreter. Before running any code type the following three commands:
C:/ProgramData/Anaconda3/Scripts/activate #activate conda Scripts directory
conda activate base #activate conda
& C:/ProgramData/Anaconda3/python.exe #to run python
I have same problem.
I have got two version of numpy 1.16.6 and 1.15.4, fresh installed pandas did not work correctly.
I fixed it by uninstalling all versions of numpy and pandas and install the last versions.
$ pip uninstall numpy pandas -y
Uninstalling numpy-1.16.6:
Successfully uninstalled numpy-1.16.6
Uninstalling pandas-0.24.2:
Successfully uninstalled pandas-0.24.2
$ pip uninstall numpy pandas -y
Uninstalling numpy-1.15.4:
Successfully uninstalled numpy-1.15.4
Cannot uninstall requirement pandas, not installed
$ pip uninstall numpy pandas -y
Cannot uninstall requirement numpy, not installed
$ pip install numpy pandas
I had the same issue with anaconda package, it got updated.
anaconda {4.3.1 -> custom} ## I am not sure if this was the issue
Hit below command to know
conda list --revisions
what i did is just uninstall pandas with conda and re-install it
conda install pandas
Some new libs may also get installed with it.
It worked for me hope will do the same for you.
Uninstall all pip packages that you're having problems with. Manually remove all site-packages files. If you're using MacPorts, sudo port clean .
Then try reinstalling. Sometimes, there are files that should have been removed, but weren't if the installation was abruptly interrupted or something.
There could be an issue with conflicting versions of the package(s), as well as potentially issues with Pathing. Are you sure you've set the correct Path for your binaries? (/opt/local/bin, /anaconda2/bin, etc.)
Another issue could be some PYTHONPATH that's explicitly looking in the wrong place for the file.
I had a same issue recently with Anaconda with Python 3.7.
I solved this problem by downgrading python version to 3.6:
conda install python=3.6
and then by updating all the packages:
conda update --all
pandas is built on top of numpy so you need to have numpy to use the data manipulation feature, so install numpy first.
pip install numpy
This worked in my anaconda environment, but I do not know why conda does not work. For some reason conda uninstall was not sufficient. This only worked with conda remove.
conda remove pandas
conda remove numpy
conda install pip
pip install pandas
*With help from this answer
This raises the following import warning in python 3.6 and 3.7:
ImportWarning: can't resolve package from __spec__ or __package__, falling back on __name__ and __path__
If you with to ignore this warning (and maybe other ImportWarnings), add the following to your script before importing pandas:
import warnings
warnings.filterwarnings('ignore', category=ImportWarning, module='_bootstrap.py')
In my case even though I was using the above options of uninstall and installing using pip the code was still giving me same errors.
Finally, I created a vritual environment and Installed numpy and pandas using pip in my virtual env. Now the code is running.
Steps: for Anaconda3 - Please change according to your installation type:
[if you dont have virtual env package installed]
$ pip install virtualenv
[from command prompt go to the directory by c:\anadonda3\scripts
[write the following command to use virtual env to create a virtual env for you in your desired location]
$virtualenv c:\anaconda3\envs\my_virtual_env
[once created you will have to activate your virtual env]
$c:\anaconda3\envs\my_virtual_env\scripts activate
[now pip install numpy and pandas and other required packages using pip]
[once installations are done exit from the virtual env]
$c:\anaconda3\envs\my_virtual_env\scripts deactivate
now use the python.exe inside your virtual env folder to run the script and it will run even with python 3.7.
I am using Win10 and Conda, and this issue just append to me when upgrading python 3.7.2-h8c8aaf0_0 --> 3.7.2-h8c8aaf0_2.
I solved it by return to the previous version with
conda install python=3.7.2=h8c8aaf0_0
If you're running your program on PyCharm on Windows, there is a known bug, because PyCharm simply doesn't add env-related paths to PATH.
The issue is fixed in the 2019.1 Early Access Preview (EAP) build.
For me installing the EAP fixed the issue.
nothing worked for me ... except when I found this
I suspect that you have a local file called unittest.py that is getting imported instead of the standard module.
I was trying to upgrade my anaconda 2 with anaconda 3. I tried installing Anaconda3-2018.12-Windows-x86 and Anaconda3-2019.03-Windows-x86_64 on my Windows 10 machine and failed with this error. For me, using Anaconda3-4.4.0-Windows-x86_64 for anaconda 3 worked the trick after trying everything listed in answers here.
I fixed this using Anaconda by going to Environments > base(root), searching for numpy in the installed modules and clicking the tickbox alongside it and choosing > Mark for specific version installation > 1.14.0 (as suggested by another user on this thread). Then clicking Apply. Once it downgraded numpy I stopped getting errors when running py files on the command line.
Throughout this saga, I was still able to use https://pypi.org/project/auto-py-to-exe/ even when I was getting the numpy errors on the command line, but it was a hassle to create an exe every time I wanted to test a change. It's all sorted now. I guess there was a problem with numpy 1.16.4.
Anyway, I hope this helps someone who's using Anaconda as well.
The following worked for me.
Deleted the folders for numpy and pandas together with their contents completely from the site-packages folder. Check depending on whether you are using python2 or python3. Check the exact path as per your machine.
N.B handle with care "rm -rf" command. If you are not sure of what you are doing, please do it manually using any file explorer of your choice!!
rm -rf ~/anaconda2/envs/myenv/lib/pythonX/site-packages/pandas*
rm -rf ~/anaconda2/envs/myenv/lib/pythonX/site-packages/numpy*
Then i installed clean packages for pandas and numpy as usual with
pip install numpy
pip install pandas
I've got the same error recently. Before applying uninstall or install tools, try to update your Jupyter.
How? Go to 'Environments' and type on the Search Packages box 'pandas'. Afterwards, check the version (if that column shows a blue number with a diagonal arrow, it means that your pandas is out of date). Click on 'pandas' and a option will pop up (choose 'Apply' and wait for a couple of minutes to update the package). And then, make a quick test on any notebook to make sure that your Jupyter is running smoothly.
For those who couldn't solve with the above answers:
Ensure that you are running python3 with
$ python version
If not, install python3.
Then change default python to python3 with
$ alias python=python3
Next, close your jupyter lab/notebook environment and re-launch it with default python being python3.
build_exe_options = {"packages": ["os",'pandas','numpy']}
It works.
you are running python 3.7
create environment for python 3.6
python3.6 filename.py

ImportError: undefined symbol: _PyUnicodeUCS4_IsWhitespace

I am a python beginner and I would like some help with this. I am using Ubuntu and I had installed python using Anaconda, but then I tried to install it again using pip and now when I'm trying to run my code, at import numpy as np, I see this error
ImportError: /home/dev/.local/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: _PyUnicodeUCS4_IsWhitespace
How can I fix this?
I also got this error. If you google for it, you will find lot's of similar issues. The problem can happen when you have multiple Python versions. In my case, I had the Ubuntu 16.04 Python 2.7 via /usr/bin/python and another Python 2.7 via Linuxbrew. type python gave me /u/zeyer/.linuxbrew/bin/python2, i.e. the Linuxbrew one. type pip2.7 gave me /u/zeyer/.local/bin/pip2.7, and looking into that file, it had the shebang #!/usr/bin/python, i.e. it was using the Ubuntu Python.
So, there are various solutions. You could just edit the pip2.7 file and change the shebang to #!/usr/bin/env python2.7. Or reinstall pip in some way.
In my case, I found that the Python 2.7 via Linuxbrew was incompatible to a few packages I needed (e.g. Tensorflow), so I unlinked it and use only the Ubuntu 16.04 Python 2.7 now.
Just uninstall numpy:
pip uninstall numpy
And reinstall numpy:
pip install numpy
Another thing you can do is run it on a virtual environment:
virtualenv myproject
cd myproject
source bin/activate
pip install numpy

Installing numpy on Red Hat 6?

I'm trying to install numpy on a Red Hat (RHEL6) 64-bit linux machine that has Python 2.7. I downloaded and untar'd numpy 1.6.2 from Sourceforge, and I did the following commands in the numpy-1.6.2 folder:
python ./setup.py build
sudo python ./setup.py install #without sudo, this gives a permissions error.
Then, when I do import numpy on the Python prompt, I get ImportError: No module named numpy.
I read somewhere that numpy 1.6.2 is for Python 3.x, so I also tried the above steps with numpy 1.5.1, and I got the same ImportError.
I'm speculating that the solution lies in some environment variable gymnastics, but I'm not sure what files/directories Python needs to "see" that isn't in scope. Any suggestions for how to get numpy working?
I also tried some precompiled binaries for RHEL, but they gave various errors when I did sudo yum install [numpy precompiled binary url].rpm.
As an aside, my motivation for installing numpy is to use PyGnuplot. Also, I've installed numpy and PyGnuplot on other machines before, but it's been on Ubuntu and Mac OS.
RHEL6 ships numpy 1.4.1, see distrowatch. If 1.4.1 is new enough for you, you can install it with:
$ yum install numpy
When I install Python packages on Ubuntu using setup.py packages end up in
/usr/local/lib/python2.7/dist-packages/
assuming Python2.7
If numpy is installed there, you will need to append this path to your Python's path:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/
you can append it permentanly using ~/.profile
Another way is by adding a .pth to a directory that’s already on Python’s path, for example
echo "/usr/local/lib/python2.7/dist-packages/" > /usr/local/lib/python2.7/site-packages/dist_pkg.pth
run that last command as root of course
I gave up on using RedHat, and I installed Ubuntu in a VM. It was a one-liner using apt-get.
Not an ideal solution to the question at hand, but I just didn't want to spend any more time chasing down a solution for RedHat.

Categories

Resources