Python on OS X can't see most recent numpy - python

easy_install -U numpy
When trying to use matplotlib on Mac OS X 10.7.5, it appears that Python is always finding an older version of numpy, not the binary release I install from the SourceForge site.
When I try:
>>> from matplotlib import pyplot
I get:
RuntimeError: module compiled against API version 6 but this version of numpy is 4
(and a lot more error-tracing)
I looked for answers and tried:
sudo easy_install -U numpy
which had worked for others in my situation, despite errors when it ran. My error was:
RuntimeError: Broken toolchain: cannot link a simple C program
/tmp/easy_install-tntLIw/numpy-1.6.2/numpy/distutils/misc_util.py:252: RuntimeWarning: Parent module 'numpy.distutils' not found while handling absolute import
and I'm still unable to use matplotlib, and Python still reports seeing numpy version 1.5.1
A variety of attempts to install pre-built Python combos such as scipy, superpack all yield the same result.
I'd appreciate some help and advice.

Related

Importing the numpy C-extensions fails when importing a package that depends on numpy

When I import a package I built that depends on numpy (via pandas), the numpy import fails with the message below. VS Code is not in the picture.
I'm running macOS Monterey (12.3.1) on a MacBook Pro with an M1 chip.
I installed Python 3.10 from binary.
I'm using virtualenv and VS Code for development, but the failure also occurs when I run a script from Terminal.
I built a package (PyTables) that uses pandas and numpy: PyTables. It runs just fine in that project on my machine.
However, when install that built package in another project -- pip install -i https://test.pypi.org/simple/ pytables -- and then import it -- import pytables as tp -- I get the numpy import error below.
I've isolated the problem to just that import statement.
I installed pandas 1.4.1 and numpy 1.22.1 in this virtualenv using pip3, just as I did in the env where I built the package.
I also have Python 3.9.1 on my system. I need 3.10 for PySimpleGUI.
If I simply comment out the import, the code runs fine.
Import 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.10 from
"/Users/alecramsay/.virtualenvs/tstudio/bin/python" * The NumPy
version is: "1.22.1"
and make sure that they are the versions you expect. Please carefully
study the documentation linked above for further help.
Original error was:
dlopen(/Users/alecramsay/.virtualenvs/tstudio/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so, 0x0002): tried:
'/Users/alecramsay/.virtualenvs/tstudio/lib/python3.10/site-packages/numpy/core/_multiarray_umath.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need
'x86_64'))

Numpy Import Error in Anaconda Environment using Spyder (WINDOWS)

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

Can't import numpy in python 2.7

When running the following code in python 2.7:
import numpy
I get the result:
ImportError: No module named numpy
I have however got numpy installed for python 2.7, which is seen when running the following in terminal:
pip install numpy
I get the following:
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Working on macOS10.13.1
What am I missing?
Any help will be greatly appreciated!
have you tried uninstalling the numpy package and re-installing it? As mentioned you may be running python 3 instead of python 2 which could cause this issue.alternatively you could install an api like anaconda which comes with numpy pre-installed this may resolve the missing module. anaconda website: https://www.anaconda.com/download/

Why can't I import opencv3 even though the package is installed?

I currently am running Python 3.5 and using Spyder from Anaconda as my IDE. I am running this on a Windows machine.
When I write import cv3 at the top of my code, it returns the error ImportError: No module named 'cv3'
I attempted to install opencv3 again with the command conda install -c https://conda.binstar.org/menpo opencv3 in the Command Prompt. It is apparently already installed because it returned
Fetching package metabase...............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\Users\Joey\Anaconda3:
# opencv3 3.1.0 py35_0 https://conda.binstar.org/menpo
Am I importing cv3 wrong? How do I fix this error?
Update: Tried import cv3 instead of import cv2 but got the following error: ImportError: cannot import name 'cv2'. The wording on the two errors is different, so python must acknowledge there is opencv installed but it does not work for some reason. Any ideas?
Ironically enough, the module is still called cv2 because it doesn't represent the version of opencv but the actual C++ API underneath which is, to be contrasted from the C API, named - cv2... So try with: import cv2
Problem solved by using command pip uninstall opencv-python in the Command Prompt.
I have attempted several installations of opencv and I suppose one may have downloaded badly and Anaconda was attempting to read that one. I looked into the build of some of the other installations I attempted and some were for Python 2.7. Maybe that contributed to the error.
Thankfully, this worked. Now import cv2 works perfectly. No errors.
I used the same approach to install the package. However, I could not import the library using the name opencv3. I had to use cv2 which worked for me.
Elaborating on #zwer's answer, check the version of OpenCV after import cv2.
>>> cv2.__version__
'3.1.0'
So basically it's calling the OpenCV3 library.

Installing SciPy and Numpy with Macports

As I know this seems to be a common question, I have looked at the other threads and can't seem to figure out how to apply to my own situation. The threads I have looked at so far are:
NumPy in IDLE (Python 3.3.2) on Mac OSx 10.8
Install Numpy on Mac OS X Lion 10.7
I have installed the version 3.4 of Python from the main Python.org website, and have been accessing it via the IDLE application. I recently decided to try and add the SciPy packages via Macports and have run into difficulty.
I successfully downloaded and installed the SciPy packages, but when I try and import numpy (or matplotlib etc.) i get the following message:
>>> import numpy
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
import numpy
ImportError: No module named 'numpy'
I have verified that numpy (and the other SciPy components) is installed, and is at the following location:
/opt/local/var/macports/sources/rsync.macports.org/release/tarballs/port
Also if I try to use pip install numpy, I get the following:
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Cleaning up...
I presume the problem is that IDLE is not linking to the new components, but I'm not sure how to resolved this. I have tried to run the following in the terminal window:
export PYTHONPATH=/Library/Python/2.7/site-packages:$PYTHONPATH
But this hasn't made any difference that I can see, and I am a little lost as to where to go from here.
If it's relevant when i run which python from the terminal window, i get the following result:
/usr/bin/python
I am running a Macbook Pro 2011, with OSX 10.9 (Mavericks). I am also very new to programming and terminal interfaces, so please try and give a simple answer if possible.

Categories