Numpy Import Error in Anaconda Environment using Spyder (WINDOWS) - python

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

Related

scheduling python script with crontab (mac) - unable to import required dependencies

I am trying to use crontab to schedule a python script to run every day, but I'm getting this error:
Traceback (most recent call last):
File "/Users/name/Desktop/Scrape/scraper.py", line 5, in <module>
import pandas as pd
File "/Users/name/opt/anaconda3/lib/python3.9/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
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.10 from "/usr/local/bin/python3"
* The NumPy version is: "1.23.1"
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'
I checked the versions and they are correct. Numpy, pandas and python are also present in my conda list
Here is my crontab command:
* * * * * PYTHONPATH=/Users/name/opt/anaconda3/lib/python3.9/site-packages /usr/local/bin/python3 /Users/name/Desktop/Scrape/scraper.py
(***** as I'm trying to debug)
I have tried: uninstalling and reinstalling pandas & numpy, creating and activating conda environment. What could be the issue?
Python 3.10 (usr/local/bin/python3) cannot use the site packages from Python 3.9.
Instead of side-loading Conda packages into a system-level install via PYTHONPATH, consider creating a dedicated environment for the task that only has the required packages installed. For example,
## include whatever other packages you need ...
conda create -n scrape python=3.10 numpy pandas
Then have cron run
conda run -n scrape python scraper.py
where scrape is the (arbitrary) name of the environment.

Unable to Install numpy. No module named 'numpy.core._multiarray_umath'

This is the complete error message I received:
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.10 from "D:\hugging-face\nlp\Scripts\python.exe"
* The NumPy version is: "1.21.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'
I checked my Python version by typing python -v it the output was 3.10.5 is that alright?
I tried checking the NumPy version by typing:
import numpy
numpy.version
However, it gave me the same error about numpy.core.multiarray_umatch`. So, I tried to install numpy by running the following command:
pip install numpy
It gave me the following error:
ImportError: cannot import name 'Mapping' from 'collections' (D:\python\lib\collections\__init__.py)
I would also like to add that there are two directories inside lib with names numpy and numpy-1.21.5.dist-info. So, I guess the library is already installed but I can;t use it for some reason.
The contents of my pyvenv.cgf file are:
home = D:\python
include-system-site-packages = false
version = 3.7.4
What should I do?
This may work, just give it a try
as you are using python 3.10 you need to install numpy version greater than 1.21.5
create new environment
cd <path where you need your virtualenv>
python -m venv .venv
as you are using windows activate using virtual env
.venv\Scripts\activate assuming your are already in the virtualenv folder
then try pip install numpy>=1.23

How can i use NumPy 1.18.5 for Python3.8 with Anaconda?

I am having problems with the Numpy 1.18.5 version. I have the Python3.8 and they seem to be incompatible. I am working with Anaconda Navigator. So sorry if this is very basic but i am a beginner in this amazing world. Thanks a lot in advance.
This is the message error i get:
$ python Bikeshare.py
C:\Users\Xabi\anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "Bikeshare.py", line 2, in <module>
import pandas as pd
File "C:\Users\Xabi\anaconda3\lib\site-packages\pandas\__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
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.8 from "C:\Users\Xabi\anaconda3\python.exe"
* The NumPy version is: "1.18.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: Das angegebene Modul wurde nicht gefunden.
You missed to activate the conda environment, hence the error. Try
C:\> conda activate
(Anaconda3) C:\> python Bikeshare.py
If activation doesn't work, your install is incomplete. Try
C:\> conda init
first.
I can see the error accures when the script imports Pandas. So you might need to change your pandas version too.
To check your Numpy:
Try to find your NumPy version first.
import numpy as np
print(np.__version__)
1.18.5
If it's not the version you're looking for, uninstall the current version and install the specified version:
pip uninstall numpy
pip install numpy==1.18.5
I am not sure if it's a good idea or not but I always use python's two previous version to make sure all my dependencies are all met. Since Python 3.9 is available I use python 3.7

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.

Scipy, Numpy, Matplotlib Troubles on OSX

I just installed scipy and numpy using homebrew and pip. I did the following:
brew install python
brew install gfortran
easy_install pip
sudo pip install numpy
sudo pip install scipy
numpy and scipy are both easily found in /Library/Python/2.7/site-packages, but when I open a python shell in the terminal and type:
import numpy
import scipy
I get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
and the same for scipy. What's wrong? Pip seems to think they're installed.
The python shell you are running from the terminal is probably OSX pre-bundled python and not the one you installed (with numpy & scipy).
You can list the current paths using:
import sys
print(sys.path)
It might be a bit overkill, but I once wrote a short guide to install Python 2.7.x in OS X. You can find it here.
The bottom line is that right now you might have two versions of Python installed, and it can be a bit tricky to uninstall only one of them. If you're sure which one is using the right site-packages folder, then delete the other and update your path variables. If not, I'd suggest to follow that guide.

Categories