Matplotlib: Import Error no module named _path - python

I've been struggling for hours on a problem that is making me insane. I installed Python 2.7 with Cygwin and added Scipy, Numpy, Matplotlib (1.4.3) and Ipython. When I decided to run ipython --pylab I get the following error:
/usr/lib/python2.7/site-packages/matplotlib/transforms.py in <module>()
37 import numpy as np
38 from numpy import ma
----> 39 from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
40 update_path_extents)
41 from numpy.linalg import inv
ImportError: No module named _path
I spent hours on the internet, looking for a solution but nothing worked. I did notice that I am missing _path.so files in the matplotlib directory that everybody seems to have. Instead, I have two files: path.py and path.pyc. But I installed matplotlib directly from the official website using pip install and reinstalling it didn't make any difference. Does anyone have a little clue on what is going wrong? I would be incredibly grateful !!!

For others having this problem, in my case, the solution was simple. The problem was caused by having the wrong matplot library installed on your computer; creating an error in finding the correct matplotlib path. In my case, I had installed matplotlib on a different version of python. Simply update matplotlib on your computer, so that it is compatible with your current version of python:
pip install --upgrade matplotlib
As for the post, I am unsure of what caused these big issues. Hope my tip can help anyone else stumbling upon this issue!

I doubt that most of you brought here by Google have the problem I had, but just in case:
I got the above "ImportError: No module named _path" (on Fedora 17) because I was trying to make use of matplotlib by just setting sys.path to point to where I had built the latest version (1.5.1 at the time). Don't do that.
Once I ran "python setup.py install" (as root) to do a proper install (and got rid of my sys.path hack), the error was fixed.

The package matplotlib requires multiple dependencies (see them here). For me, the missing dependencies included pyparsing and kiwisolver, but your results my vary. Before you do any of these other things (reinstalling python or the library, etc...), make sure you have installed (pip install ...) all the libs in this list (link).

Related

from setuptools.errors import OptionError ImportError: cannot import name 'OptionError' from 'setuptools.errors'

i am trying to create an executable using cx_freeze. and when i run
python setup.py build i get the following error:
from setuptools.errors import OptionError
ImportError: cannot import name 'OptionError' from 'setuptools.errors'
I am working in anaconda. I tried reverting to a previous cx_freeze version with no luck.
This a a new problem two month ago when i created another virtual envieonment i didn't have this problem. This is why i'm guessing it could be maybe a version issue. However i can't seem to find the correct version to install.
i also checked other related issues however i didn't find a solution that works for me. If you have an idea please let me know!
Thank you
It's difficult to tell without additional info, package versions, a more complete trace, etc.
I ran into this same error during a build post-upgrade of cx_Freeze but after already having setuptools installed. Reinstalling setuptools to the most current version (65.6.3) corrected the error in my case. I'm running cx_Freeze version 6.13.1 if it helps move you past the error.
Typically, Python errors of the sort ImportError: cannot import name ... indicate circular dependencies, e.g.,: https://stackoverflow.com/a/9252628/9975319 - it could be that the order of imports cx_Freeze does changes across builds causing the dependencies to import incorrectly but I haven't dug deeper into it.

Python: No module named 'numpy'

I tried to import numpy but I received a ModuleNotFoundError: No module named 'numpy' error. Someone told me it could be because I didn't have numpy installed, but I already did.
upon installing numpy I got Requirement already satisfied: numpy in ./opt/anaconda3/lib/python3.8/site-packages.
which python returns /Users/MacBook/opt/anaconda3/bin/python. I am new at this, but I'm guessing the reason I got that error was because the files aren't in the same place? If so, how do I move it to the right place?
side note: I have a similar issue with matplotlib and this is running on VS code if that helps. Also I use spyder and I don't get the numpy nor the matplotlib error over there, but the error seems to be on VS code
Try uninstalling numpy and re-installing. You also try re-install anaconda. I had this same issue and that fixed it.
Anaconda installs its own conda environment to run python. Probably VS Code can't access. Try this command;
python -mpip install numpy
If your python file named numpy.py, you can get this error too.
If doesn't work maybe you can try to change the environment to Anaconda environment.
check this

riginal error was: DLL load failed while importing _multiarray_umath

i got a something weird situation with import packages.
when i use numpy on Jupyter notebook, it's fine and my all source codes are run without problem
but if i use numpy on Visual Studio Code i got a something error.
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\Mohw-IN\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: The specified module cannot be used
다.
and i found something weird.
import os
print("PYTHONPATH:", os.environ.get('PYTHONPATH'))
---------------
PYTHONPATH: None
how can i do for use numpy in vscode?
It appears to be some issue related to path variable. This issue has been discussed on below github link.
https://github.com/numpy/numpy/issues/14770
To solve this, we need to add C:\Users<username>\Anaconda3\Library\bin" in your PATH user variable. Please replace "username" with actual value.
Now VS Code should work fine.
I don't even know what PATH is but i found an easier way to solve the problem
Install Anaconda
Open VScode from anaconda navigator
Done :)
You should be able to use Numpy now
If i open VScode from the desktop shortcut i still have the same problem
I don't now "why" it happens but i don't really care
hope this is usefull
In my case, it was a mismatch between the version of Numpy and Pandas (I had just upgraded to v1.4). Fix by upgrading numpy to sync it with Pandas:
In Anaconda/Miniconda:
conda update numpy
Or with pip:
pip install --upgrade numpy
Or this (very heavy-handed) approach which upgrades all packages:
conda install --update-all numpy
Open Anaconda and Launch Visual Studio. Now run the program.

Issue installing scipy: Six module not found

Question similar to this one Issues installing scipy from Anaconda2 Python but I don't have anaconda so the answer there won't work for me.
I'm trying to install 64 bit Scipy from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy but I'm getting this error:
from scipy._lib.six import string_types
ImportError : No module named scipy._lib.six
The _lib folder does contain a python file called six, though. And I have the Six package installed elsewhere already?
EDIT: I've been told it's probably something to do with the python path. Can anyone help?
it's probably solved for you by now but you also need the file called six.pyc. If it's not there, it's probably in usr/local/lib/python2.7/dist-packages/scipy. (or replace python2.7 with whatever version you have). Just copy it to scipy._lib, but make sure you choose the right scipy (there could be a usr/local/lib/python2.7/dist-packages/scipy AND a usr/lib/python2.7/dist-packages/scipy (without the local))

Trouble in installing Basemap in matplotlib

I am trying to install Basemap, and beforehand I already have the prerequisite versions of Matplotlib, Python and Numpy working on my Mac. To install Basemap I am following the instructions in this website http://matplotlib.org/basemap/users/installing.html
I seemed to progress quite well with the steps, until the very end which is "Check your installation by running from mpl_toolkits.basemap import Basemap at the python prompt." I got "ImportError: cannot import name pyproj" from a line that reads "---> 30 from mpl_toolkits.basemap import pyproj".
Does anyone have any idea? Many thanks!
The compiled module could be accessible by python. To achieve that you should put the module into python path or you need to add the location of the module to PYTHONPATH environment variable.
To see the python installations paths you can write these lines to python shell:
import sys
for path in sys.path:
print(path)
The code will show the paths python is looking for modules.
After you compile the c library, you need to go to upper folder and run python setup.py install as it's said in the installation page. This will put python modules into one of your python paths.
I had the same problem installing basemap-1.0.7.
I found that the file
/usr/lib64/python2.6/site-packages/mpl_toolkits/basemap/init.py
had a reference to axes-grid1, but python lists only module axes_grid.
So I changed grid1 to grid and now basemap imports without error.
Had the same issue on OSX, found after much faffing that Basemap worked fine with a non-native version of python (for me 2.7.12 with everything under /opt/local/Library/Frameworks...) but not with the native version (for me 2.7.10 with most stuff under /System/Library/Frameworks... and Basemap under /Library/...). I did note also that under the native version there was already some mpl_tooklit content and without the permission to add Basemap there you end up with mpl_toolkit contents in multiple places. I wasn't sure if this was the problem specifically but as I said having it all under opt using non-native python was what solved this for me.

Categories