python import error when attempting to run / launch Flask application - python

My Flask Application was working alright and all of a sudden I am seeing this error when I run the command to launch the App locally.
File "/Flask_Trial_App2/index.py", line 6, in <module>
import pandas as pd
File "/Flask_Trial_App/virt/lib/python3.8/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 "/Flask_Trial_App/virt/bin/python"
* The NumPy version is: "1.21.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 tried upgrading pandas and numpy, but it didn't fix the issue.
pip install --upgrade numpy
pip install --upgrade pandas

I've had similar issues to this when deploying flask apps on servers with different environments, here is something I've done that worked in the past in case this helps:
Uninstall the package then reinstall specific version using the absolute path to the python executable.
/Flask_Trial_App/virt/bin/python3 -m pip uninstall numpy; /Flask_Trial_App/virt/bin/python3 -m pip install numpy==1.21.1
Hope that may help.

Related

Error running a Python program with sklearn.cluster - "DLL load failed while importing _pairwise_distances_reduction"

I am running Windows 10, and I have Python installed.
When trying to run a Python program with the line from sklearn.cluster import DBSCAN in it, I get the following error:
File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\sklearn\metrics\pairwise.py", line 33, in <module>
from ._pairwise_distances_reduction import PairwiseDistancesArgKmin
ImportError: DLL load failed while importing _pairwise_distances_reduction: The specified module could not be found.
I have tried solving this by entering each of these in the command line (separately, not all at once) and checking whether or the program works:
pip install sklearn
pip install scikit-learn
pip uninstall scipy then pip install scipy
pip uninstall numpy then pip install numpy
I still get the same error when running the program. I'm having difficulty troubleshooting this, searching for "_pairwise_distances_reduction" returns no helpful results.
Is there something I'm supposed to install that I missed?
I was having this problem too, I installed Visual C++ Redistributable Runtimes libraries and it solved my problem.

Importing the numpy c-extensions failed in VS Code

Getting error with VS Code in installing pkg Numpy and Pandas. Any solution on how we can fix the issue? Thanks.
Error:
from . import _distributor_init
Traceback (most recent call last):
File ".\Form_validate.py", line 1, in <module>
import pandas as pd
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
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.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\ProgramData\Anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
There are two solutions.
The first is to reinstall numpy, including its architecture tools. Reinstall the package by using the following code in sequence:
pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy
The second solution is to add the path to the environment variable. In fact, pylance did not find this file because
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas_init_.py", line 17,
If you try to make Python output sys.path, you will find that it is anaconda3 instead of Anaconda3.
So, adding the path to environment variable can solve it.
This happens because if VS Code is launched apart, as usual, it will recognize Python from Anaconda setup but will have trouble loading imports.
Fix: Close VS Code. Then open anaconda shell, i.e., the terminal, and from there launch VS code with the comand:
Anaconda_prompt> code
You'll see terminal inside VS Code will run automatically the command:
conda activate base
Then run your program again within VS Code, and should work fine as expected.

Python Pandas in Windows Command Prompt ImportError: Unable to import required dependencies: numpy (Anaconda)

I am trying to run a python script off the Windows command prompt. The script runs in a server environment which is a tough place to install modules because of our companies firewalls. So It was convenient to use Anaconda 3 which includes python 3.8 and Data engineering modules like Pandas.
The script runs with no issue in Spyder and Visual Studio code, but when I try to run it in the Windows Command line I get the following error:
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 "installservice.py", line 9, in <module>
import pandas as pd
File "C:\ProgramData\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:\ProgramData\Anaconda3\python.exe"
* The NumPy version is: "1.19.2"
Again the script runs with no issues in my IDEs but not on Windows Command Line. Please help
Try upgrading the pip and then try to uninstall if they are already present in the below order.
pip uninstall pandas
pip uninstall numpy
pip install pandas
pip install numpy

ImportError: Missing required dependencies ['numpy']

I was able to run all scripts successfully which is using pandas , but suddenly all my PANDAS SCRIPTS are giving this error :
Traceback (most recent call last):
File "data_visulaization.py", line 5, in
import pandas as pd
File "/usr/lib64/python2.7/site-packages/pandas/init.py", line 18,
in
raise ImportError("Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Recently i have not installed or updated any new things.
Does anyone have a solution for this?
I uninstalled pandas and numpy and re-installed them but still facing the same issue.
I got this issue on Rasberry PI and found that the root cause was missing library:
import numpy
...
ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory
Then it takes few minute to google the required library source:
sudo apt-get install libatlas-base-dev
I have not checked the solution on any other Linux-es but likely the same method should be applicable. So try to import the faulty library first and see what is missing.
I faced the exact same error and found that I had created a file named 'random.pyc' by mistake in the same directory as that of my PyCharm environment
ayush#ayush-VirtualBox:~/PycharmProjects/untitled$ where "untitled" refers to my project directory. I deleted it and everything fells into place. Hope this helps !
The reason for this was numpy Imports another file called Random by default for building its own dependencies and it mistook my 'random.pyc' for it and replaced it.
I had the same error. Fixed with the following:
python3 -m pip uninstall numpy
python3 -m pip install numpy==1.14.0
use"conda install numpy" in cmd-window if you used Anaconda in your machine. I had encount this problem also and I resolved it by this. May it can help U.
I found the solution , the actual problem is if any of your recent python scripts have generated ".pyc" extension file this error will occur .
solution is to delete those files that's all.
If you are using packages options and it contains pandas or some package depends numpy, you should add required dependencies to the packages.
pip uninstall numpy
pip install numpy
It works
This error will occur when multiple versions of numpy are installed. Check to make sure you only have one version of numpy installed. You can make a test file to check this if you don't want to look through the directories:
import numpy
print("Numpy imported")
If you get an error saying that multiple versions of numpy were detected, then you have multiple versions of numpy installed.
You can fix this by repeatedly calling (not just once)
pip uninstall numpy
until all versions are uninstalled and then use
pip install numpy
to get only the latest version.
try uninstalling pandas and numpy:
pip uninstall pandas
pip uninstall numpy
and install them back:
pip install pandas
pip install numpy

Prosodylab Aligner

Can someone that uses this tool give me a step by step manual. while I follow the available youtube manual and others on the Github I have still problems. when I want to run aligner.py I have the error
from utilities import opts2cfg, mkdir_p, \
File "/home/mary/Desktop/htk/Prosodylab-Aligner/aligner/utilities.py", line 8, in <module>
import yaml
ImportError: No module named 'yaml'
Is there any way to fix it? I try to install yaml but it seems impossible
The module should be install as pyaml. You can use pip to install Python packages. In your case this will be your installation command.
pip install pyaml

Categories

Resources