I have two python distributions(python2.7,python3.6) and in both I have installed pandas and numpy as well but cant use
These are the errors caused when i tried to import pandas
in python 2.7
File "/usr/local/lib/python2.7/dist-packages/pandas/init.py", line 19, in
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
then imported numpy
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try git clean -xdf (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: cannot import name multiarray
in python 3.6
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'pandas'
Most of these cases, the problem is that you are installing pandas in another environment. The easy solution here is using Anaconda.
Anaconda is focused on environments. First, you should choose installation of python2 or python3. Then, you can install this version of Anaconda in Linux: https://www.anaconda.com/download/#linux
For example:
64-Bit (x86) Installer (622 MB) Python3:
$ wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
Then you need, install in your system:
$ bash Anaconda3-5.2.0-Linux-x86_64.sh
Be cautious in the interactive dialog in order to install Anaconda. Remember the route of the installation.
When you have Anaconda in a folder named: anaconda 3 (for example). go to route: .../anaconda3/bin.
Now, you should execute:
$ source activate
Now you are in base environment, you can install the packages that you need (pandas and numpy are install by default). However, I recommend you create a new environment for each new proyect (see https://conda.io/docs/_downloads/conda-cheatsheet.pdf).
Imagine that you have (base) environment. In this environment try:
$ python
The first message gives you the python version. Anyway you can try:
>>> import sys
>>> sys.version
In order to know the version that you are using.
Related
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.
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
I am not able to import pandas
C:\Users\Yash\Desktop\Python\Twitter Sentimental Analysis>python import.py
Traceback (most recent call last):
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\__init__.py", line 26, in <module>
from pandas._libs import (hashtable as _hashtable,
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\_libs\__init__.py", line 4, in <module>
from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
ModuleNotFoundError: No module named 'pandas._libs.tslib'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "import.py", line 4, in <module>
import pandas as pd
File "C:\Users\Yash\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\__init__.py", line 35, in <module>
"the C extensions first.".format(module))
ImportError: C extension: No module named 'pandas._libs.tslib' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
I tried screwing around but this error stayed the same.
I have updated the modules already along with pip and python!
This is the full traceback of the command.
I am currently using python 3.6.6 (downloaded from the official site)
pip version : 18.1 running on windows 10 laptop!!
I faced a similar issue and solved it by manually uninstalling pandas and then installing pandas using pip. You have mentioned that you have only updated pandas. So I assume you haven't tried re-installing it.
While doing so pandas version in my environment changed from 0.23.4 to 0.24.1
My Environment :
python 3.6.7
pip 18.1
Note : I am also a beginner in Python usage. More experienced users may know a better way.
pip uninstall pandas
pip install pandas
The above steps solved my issues and I am able to import pandas.
I checked the release notes in pandas community and it seems like the dependency on tslib has been removed.
Check section 1.5 in the below link and search for tslib.
http://pandas.pydata.org/pandas-docs/version/0.24/pandas.pdf
I faced the same error and resolved it by calling the following commands:
pip uninstall pandas
pip install pandas
pip3 install --upgrade pandas
I was facing the same error. I tried the above solutions didn't work out. Here what worked for me.
If you have two different python env and trying to run files from different env then first you have to uninstall pandas from both env and install them in the new env.
For example, I have installed python3.6 and python3.9, so first I uninstalled pandas from 3.6
sudo pip3.6 uninstall pandas
I repeated this command serval times until all versions of pandas have uninstalled. after that, I install the pandas in 3.9 using this command
/usr/bin/python3.9 -m pip install pandas
I've used the following tutorial to install Python, numpy, scipy and matplotlib:
https://penandpants.com/2012/03/01/install-python-2/
I downloaded each and installed by double-clicking. I'm using a Mac with OS X Yosemite Version 10.10.5
When I try to import numpy, scipy and matplotlib in IDLE I get the follow error message:
`>>> import numpy
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import numpy
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/__init__.py", line 137, in <module>
import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/multiarray.so: no matching architecture in universal wrapper`
Can anyone please explain to me how to resolve this?
Thanks
use terminal and type
sudo pip install numpy
sudo pip install matplotlib
sudo pip install scipy
for python3+ use pip3
I can't say for sure what's wrong with your installation, but I suspect it's due to a some PATH-conusion... Python 2.7 and Numpy should be installed on your Mac by default.
If you run the command which python, you'll see which executable the python-commands invokes... is it the same as the one you installed?
If you write python in the terminal, and press tab twice, do you see multiple options of installed python versions?
Alternative method of installation
I prefer the Anaconda Python Distribution, which you can download like the full version or minimal version, which is the one I prefer.
If you install this, you should consider uninstalling the one you just installed.
Here's how to install the mini version:
Download the installer, and run it by opening a terminal in the folder with the installer, and running the command bash Miniconda2-latest-MacOSX-x86_64.sh. This will start the text-based installer, and if you read the instructions on screen, you'll be fine.
Notice that you have to scroll to the end of the licence agreement, before you can write yes when asked to accept the terms stated.
Say yes when it asked you if you'd like it to add Anaconda Python to your path.
Anaconda Python is different from other python distributions in the regard that it comes with it's own package and environment manager conda. With conda you can have multiple versions of Python installed at the same time (or several environments of the same Python version, but with different packages or versions of packages).
To create a new environment with the name py27, which is using Python 2.7, write conda create -n py27 python=2.7 --yes. Once created, activate the environment by source activate py27.
With the new environment now active, install the packages you need by using conda: conda install scipy matplotlib --yes.
I'd also recommend installing Ipython, which is an improved shell, and possibly the Jupyter notebook: conda install ipython --yes and conda install notebook --yes.
Hope it helps.
I just installed numpy on my PC (running windows 10, running python 3.5.2) using WinPython, but when i try to import it in IDLE with: import numpy I get the ImportError: Traceback (most recent call last):
File "C:\Users\MY_USERNAME\Desktop\DATA\dataScience1.py", line 1, in <module>
import numpy
ImportError: No module named 'numpy'.
Did I possibly install it incorrectly, or do I need to do something else before it can be used?
In Linux and Mac OS systems we can install modules directly by mentioning
pip install modulename (or) sudo pip install modulename
in terminal or command prompt.
But in windows we should mention location of python folder in c directory like c:\python3 and later we should use
pip install modulename
in command prompt or terminal.
or
go n check whether numpy module is installed in sitepackages of python 3 folder in c directory or not.
Support for Python 3 was added in NumPy version 1.5.0, so to begin with, you must download/install a newer version of NumPy.
or use this command to install numpy. This will install the latest version of numpy.
pip install numpy
Winpython has two size, and the smallest "Zero" size doesn't include numpy