When I run 'pip freeze' it shows that numpy==1.8.1; however, when I start Python and import numpy and then check the version number via numpy.version.version I get 1.6.
This is confusing to me and it's also creating a problem for scipy and matplotlib. For example, when I attempt to do the following import 'from matplotlib import pyplot' I get an error saying 'RuntimeError: module compiled against API version 9 but this version of numpy is 6'. This I'm guessing has something to do with the numpy versions being wrong.
Any suggestions?
From our conversation in chat and adding path to .bashrc not working:
Putting:
/usr/local/bin first in /etc/paths will resolve the issue
Related
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
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.
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).
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.
I installed additional python 2.7 on my mac and numpy-1.6.2 for python 2.7, however whenever I want to import numpy, it will import the numpy from the preinstalled python version on my Mac, the version is 1.6.1, can anybody tell me how can I change the import direction to numpy-1.6.2??
You must ensure that the library you've just installed and you're trying to import is in your PYTHONPATH. Also, doing things like that are not most optimal - consider using virtualenv and installing your libraries on per project basis to avoid issues like that and getting a lot more flexibility in managing them.
Check the path of your numpy package:
import numpy
print numpy.__path__
and then replace the entire contents with the downloaded numpy version 1.6.2, if the stuff in the resulting path looks similar to the numpy 1.6.2 download.
Otherwise just delete that stuff (that's in the path) or uninstall it and remove it through some other way and then use:
pip install numpy