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.
Related
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
Below is simple Line of code to try NumPy
import numpy as np
my_list = [1, 2, 3]
print(my_list)
print(type(my_list))
my_list_arr = np.array(my_list) # Here we are converting python list to numpy array
print(my_list_arr)
print(type(my_list_arr))
My question is: when I execute above lines of code using Jupyter-Notebook , it works well without any package issues BUT Why same line of code throwing NumPy , pandas and other package dependencies related issues when execute on PyCharm as .py file
FYI,
my setup of PyCharm project as;
python interpreter --> pointed to Anaconda provided
created PyCharm virtual environment - venv
Inherit-global-site-packages – Yes
Please help me. I am fed up with installing packages using conda and tired of doing package corrections one by one as and when ERRORs comes one after another package.
Any Better Solution please !!
Below is Error by Pycharm
D:\Mytech\IDE_workspace\PycharmProjects\python_anaconda_base_venv_and_global_site_packages\venv\Scripts\python.exe D:/Mytech/IDE_workspace/PycharmProjects/python_anaconda_base_venv_and_global_site_packages/python_for_data_science/my_NumPyArrays_practice.py
C:\Users\DELL\anaconda3\lib\site-packages\numpy\__init__.py:143: 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 "C:\Users\DELL\anaconda3\lib\site-packages\numpy\core\__init__.py", line 22, in <module>
from . import multiarray
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\core\multiarray.py", line 12, in <module>
from . import overrides
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\core\overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Mytech\IDE_workspace\PycharmProjects\python_anaconda_base_venv_and_global_site_packages\python_for_data_science\my_NumPyArrays_practice.py", line 1, in <module>
import numpy as np
File "C:\Users\DELL\anaconda3\lib\site-packages\numpy\__init__.py", line 145, in <module>
from . import core
File "C:\Users\DELL\anaconda3\lib\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.9 from "D:\Mytech\IDE_workspace\PycharmProjects\python_anaconda_base_venv_and_global_site_packages\venv\Scripts\python.exe"
* The NumPy version is: "1.20.3"
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: The specified module could not be found.
Process finished with exit code 1
but when i am executing below code it showing. it working.
import sys
print("******************************")
print("This Code using:")
print("Python Version =", sys.version)
print("Python Interpreter =", sys.base_prefix)
print("*******************************")
print("*******************************")
This Code using:
Python Version = 3.9.7 (default, Sep 16 2021, 16:59:28) [MSC v.1916 64 bit (AMD64)]
Python Interpreter = C:\Users\DELL\anaconda3
print("*******************************")
Process finished with exit code 0
As explained in this answer, the inherit-global-site-packages inherits from your Global python install. This is the install that comes with your machine or is installed "directly" into /usr/bin or the Windows equivalent. I don't think pointing the interpreter to Anaconda will make it inherit from Anaconda, because Anaconda is not considered a global python install.
What is happening is you are inheriting from a python install that you probably did not install anything to. I can think of two solutions:
Install the packages you want in your global python install (running which python or which python3 outside of a conda env should show you where that is; after finding the command that calls the global python, pip install using that command)
Use conda environments, and just set your interpreter to different conda environments, instead of making a PyCharm env. If you are not familiar with this, you can run conda create -n NAME python=X.XX where NAME is what you want to name the environment and X.XX is the version number. From there, you can conda activate NAME, and then either pip or conda install your packages.
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
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
I'm trying to install NUMBA on a mac machine (10.12.6).
I've tried with CONDA:
conda install numba
I'm getting this:
Fetching package metadata ...........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /Users/lefaa/miniconda2:
#numba 0.35.0 np113py27_6
This seems good, however when I try (using python 2.7):
python -c "from numba import jit"
I'm getting that the numba module isn't installed:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named numba
Do I have to configure something else?
It is likely that your path is not set up correctly and the python that conda installed numba into is not the one you are running. If you run which python you should get the one that's in your miniconda2 if everything is working properly. If you get a different python executable then you probably need to set your PATH environment variable. See:
https://conda.io/docs/user-guide/install/index.html#installing-conda-on-a-system-that-has-other-python-installations-or-packages
I solved the issue. Indeed, when installing with conda, conda installs the target package in python associated to conda (i.e, in this python '/Users/lefaa/miniconda2/bin/python'). So to import numba, it is necessary to lunch the python of miniconda.
However, to install numba on the main python (python2.7), one solution will be to install like this '/usr/local/bin/pip2.7 install numba'.