How do I import Pandas on Apple M1 chip - python

When I call:
import pandas as pd
on tensorflow_macos (for M1 chip)
I get:
ImportError Traceback (most recent call last)
~/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/__init__.py in <module>
28 try:
---> 29 from pandas._libs import hashtable as _hashtable, lib as _lib, tslib as _tslib
30 except ImportError as e: # pragma: no cover
~/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/__init__.py in <module>
12
---> 13 from pandas._libs.interval import Interval
14 from pandas._libs.tslibs import (
ImportError: dlopen(/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so, 2): no suitable image found. Did find:
/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture
/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture
The above exception was the direct cause of the following exception:
ImportError Traceback (most recent call last)
<ipython-input-3-94f55571b0d6> in <module>
1 import numpy as np
----> 2 import pandas as pd
3
4 import matplotlib.pyplot as plt
5
~/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/__init__.py in <module>
31 # hack but overkill to use re
32 module = str(e).replace("cannot import name ", "")
---> 33 raise ImportError(
34 f"C extension: {module} not built. If you want to import "
35 "pandas from the source directory, you may need to run "
ImportError: C extension: dlopen(/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so, 2): no suitable image found. Did find:
/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture
/Users/ashkan/tensorflow_macos_venv/lib/python3.8/site-packages/pandas/_libs/interval.cpython-38-darwin.so: mach-o, but wrong architecture not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --force' to build the C extensions first.

I hope Xcode Command Line Tools is already installed. If not, please install it then follow the steps.
Step 1:miniforge
Install miniforge for arm64 (Apple Silicon) from miniforge GitHub. Miniforge enables installing python packages natively compiled for Apple Silicon.
Step 2: create Conda environment
Don’t forget to open a new session or to source your .zshrc after miniforge install and before going through this step.
Create an empty Conda environment, then activate it and install python 3.8. and all the needed packages. Please note numpy is unnecessary here as pandas already install it, but it will be overwritten in the last step with the version provided by Apple.
conda create --name mytf
conda activate mytf
conda install -y python==3.8.6
conda install -y pandas matplotlib scikit-learn jupyterlab
I have tested it. It will work after these steps.

As shown in the next post(https://github.com/apple/tensorflow_macos/issues/6), it seems that the solution is to install pandas from conda until they fix this problem.
To install pandas:
conda install pandas
Or installing directly from the source:
https://github.com/pandas-dev/pandas#installation-from-sources

Follow these steps -
Important With Tensorflow Installation
With miniforge installation do this -
conda install numpy scipy scikit-learn pandas matplotlib seaborn

Use Anaconda visual UI to install into the conda environment you created. You just select your environment and search for pandas.

Related

Windows VS Code can't find numpy Module even though it is installed (ModuleNotFoundError: No module named 'numpy.core._multiarray_umath')

I have been working with Anaconda and VS Code on my Windows and everything was fine until my computer once crashed. After that, I couldn't run my scripts that worked perfectly fine before.
For example, I now get the the error when running:
import os
import datetime
import IPython
import IPython.display
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import tensorflow as tf
from tensorflow import keras
from pmdarima import auto_arima
from kerastuner import HyperModel, Objective
from kerastuner import BayesianOptimization
import keras.backend as K
from tensorflow.keras.layers import (
Dense,
Dropout,
LSTM,
GRU
)
mpl.rcParams['figure.figsize'] = (8, 6)
mpl.rcParams['axes.grid'] = False
C:\Users\myname\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\__init__.py:138: UserWarning: mkl-service package failed to import, therefore Intel(R) 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
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\__init__.py in <module>
21 try:
---> 22 from . import multiarray
23 except ImportError as exc:
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\overrides.py in <module>
6
----> 7 from numpy.core._multiarray_umath import (
8 add_docstring, implement_array_function, _get_implementing_args)
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-aaaeab3b7b86> in <module>
4 import IPython
5 import IPython.display
----> 6 import matplotlib as mpl
7 import matplotlib.pyplot as plt
8 import numpy as np
~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\__init__.py in <module>
105 # cbook must import matplotlib only within function
106 # definitions, so it is safe to import from it here.
--> 107 from . import cbook, rcsetup
108 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
109 from matplotlib.cbook import mplDeprecation # deprecated
~\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\cbook\__init__.py in <module>
26 import weakref
27
---> 28 import numpy as np
29
30 import matplotlib
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\__init__.py in <module>
138 from . import _distributor_init
139
--> 140 from . import core
141 from .core import *
142 from . import compat
~\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\__init__.py in <module>
46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
47 __version__, exc)
---> 48 raise ImportError(msg)
49 finally:
50 for envkey in env_added:
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.9 from "C:\Users\myname\AppData\Local\Programs\Python\Python39\python.exe"
* The NumPy version is: "1.19.2"
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 have been reading multiple posts but couldn't find a solution. I tried multiple things:
I have uninstalled and reinstalled anconda
I have added C:\Users\myname\AppData\Local\Programs\Python\Python39 to my system variable path
use pip uninstall numpy and after that conda install numpy
set my python path in VS code to either C:\Users\myname\AppData\Local\Programs\Python\Python39 (pythn verison 3.9.4) or C:\Users\myname\anaconda3 (Python version 3.8.5)
I went to the link mentioned in the error message but couldn't find a solution
tried to upgarde my numpy version (I have 1.20.2)
(pip install numpy --upgrade
Requirement already up-to-date: numpy in c:\users\myname\anaconda3\lib\site-packages (1.20.2))
Python Verison: 3.8.5 and 3.9.4 (tried both)
Numpy Version: 1.20.1
Matplotlib Version: 3.4.1
This
import os
print(sys.version)
print("PYTHONPATH:", os.environ.get('PYTHONPATH'))
print("PATH:", os.environ.get('PATH'))
leads to this output:
3.9.4 (tags/v3.9.4:1f2e308, Apr 6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)]
PYTHONPATH: c:\Users\myname\.vscode\extensions\ms-toolsai.jupyter-2021.5.745244803\pythonFiles;c:\Users\myname\.vscode\extensions\ms-toolsai.jupyter-2021.5.745244803\pythonFiles\lib\python
PATH: C:\Users\myname\anaconda3;C:\Users\myname\anaconda3\Library\mingw-w64\bin;C:\Users\myname\anaconda3\Library\usr\bin;C:\Users\myanme\anaconda3\Library\bin;C:\Users\myname\anaconda3\Scripts;C:\Users\myname\anaconda3\bin;C:\Users\myname\anaconda3\condabin;C:\Users\myname\anaconda3;C:\Users\myname\anaconda3\Library\mingw-w64\bin;C:\Users\myname\anaconda3\Library\usr\bin;C:\Users\myname\anaconda3\Library\bin;C:\Users\myname\anaconda3\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files\MATLAB\R2020a\bin;C:\Users\myname\AppData\Local\Programs\Python\Python39;C:\Users\myname\AppData\Local\Microsoft\WindowsApps;C:\Users\myname\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\myname\AppData\Local\Programs\MiKTeX\miktex\bin\x64;C:\Users\myname\AppData\Local\Programs\Git\cmd;C:\Program Files (x86)\GitHub CLI;C:\Users\myname\AppData\Local\GitHubDesktop\bin
Thanks in advance for any help!
You have a lot going on here, including multiple installations of Python. It looks like you have both an Anaconda installation of Python, and a standard Python installation as well.
My first recommendation is to use virtual Python environments. These create isolated environments where you can install packages without worrying about messing up your base installation. There are a handful of ways to do this, Anaconda comes with Conda, and Python comes with venv. Both work well. I prefer Conda.
Step 1 - one or more of the packages in your standard Python installation are corrupted or incompatible; I would recommend uninstalling completely.
-- Windows Key > Settings (Gear icon) > Apps > Click on Python > Uninstall
Step 2 - assuming your Anaconda installation is not also corrupted, we can use Conda to create a new environment.
-- Windows Key > "Anaconda Prompt" > this opens a terminal with the base Anaconda environment.
conda create -n myenv python tensorflow ipython matplotlib pandas seaborn numpy -y
Step 3 - activate the environment to use it and install PyPi packages.
conda activate myenv
pip install pmdarima
Fells like magic, but after applying the steps mentioned by #James, restarting my laptop, disabling and reenabling all extensions in VS Code as well as setting the environment to myenv in Anaconda itself before launching VS Code, it finally works now. Don't know what exactly made the difference though. Thanks again #James for the help!

After installing Jupyter Notebook NumPy and TensorFlow are not working

I was using Jupyter Notebook to do some studying today and noticed that I couldn't import Tensorflow or Keras. It was strange because until yesterday it was working fine. Anyway, I looked online and some people recommended I install Jupyter again using conda install jupyter notebook. I did exactly that and now I can't even import Tensorflow or NumPy. Not to mention whenever I try to open Jupyter that doesn't work either. I see a command prompt flash briefly and then nothing happens.
When I try to import either, I get this error:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
39 try:
---> 40 from . import multiarray
41 except ImportError as exc:
~\Anaconda3\lib\site-packages\numpy\core\multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
~\Anaconda3\lib\site-packages\numpy\core\overrides.py in <module>
5
----> 6 from numpy.core._multiarray_umath import (
7 add_docstring, implement_array_function, _get_implementing_args)
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np
~\Anaconda3\lib\site-packages\numpy\__init__.py in <module>
140 from . import _distributor_init
141
--> 142 from . import core
143 from .core import *
144 from . import compat
~\Anaconda3\lib\site-packages\numpy\core\__init__.py in <module>
69 Original error was: %s
70 """ % (sys.executable, exc)
---> 71 raise ImportError(msg)
72 finally:
73 for envkey in env_added:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect (you're using
C:\Users\seant\Anaconda3\python.exe),
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions 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
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: No module named 'numpy.core._multiarray_umath'
I tried reinstalling NumPy, but that didn't solve the issue. I installed Python and NumPy via installing Anaconda, and my operating system is Windows 10. My path variable looked normal as well and everything was working until now. Does anyone know how I can proceed to fix this issue?
Go to your terminal and locate the environment where you have Numpy and the other modules installed. If your'e using virtualenvwrapper you can run:
lsvirtualenv a list of your virtual envs you have will be displayed.
Then type workon virtualenv1 (replace with name of displayed virtual env) and check for your installed modules e.g after selecting the virtual env you can then type
python and get into the shell. Then you can do import numpy etc to check if the modules youre looking for exist in that virtualenv. When you find them you can then exit out of the shell and do a pip install jupyter to install jupyter notebooks on the virtual env with the modules you need. To avoid meeting such problems in future you should make sure you maintain virtual environments in your machine with the modules that your're interested to work with as per virtual env. Virtualenvwrapper is a great tool that abstracts away most of the common pitfalls found with working with virtual envs. More info in managing and creating virtual envs can be found here.
In my case I just spent around an hour uninstalling everything Python-related (Python, Anaconda, etc.) and completely installing everything from scratch again. It was a bit of a pain but I didn't know what else to do without having to dive too deeply into the issue.

ImportError: No module named artist

I tried to upgrade matplotlib using pip install --upgrade matplotlib, then after upgrading an import error occurred: import matplotlib.pyplot as plt
ImportError: No module named artist
The whole error is:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-18-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
C:\Users\TZ\AppData\Local\Continuum\Anaconda2\lib\site-packages\matplotlib\pyplot.py in <module>()
25
26 import matplotlib
---> 27 import matplotlib.colorbar
28 from matplotlib import style
29 from matplotlib import _pylab_helpers, interactive
C:\Users\TZ\AppData\Local\Continuum\Anaconda2\lib\site-packages\matplotlib\colorbar.py in <module>()
30
31 import matplotlib as mpl
---> 32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
34 import matplotlib.collections as collections
ImportError: No module named artist
Anyone could solve this problem? (PS: I use python 2.7)
When I faced this issue (system: Windows - 64 bit OS) after upgrading Anaconda to the latest version (yesterday), I saw that Anaconda was trying to load the package from a location different from the default site-packages. Hence:
I fist checked the path my jupyter notebook was defaulting to as mentioned in one of the git hub posts (sorry I don't remember which one) using:
import sys
print(sys.path)
Since this path is not the default site-packages folder, I uninstalled Anaconda completely from add or remove programs - Anaconda (this will take some time to uninstall)
Anaconda will also remove jupyter notebook from your system. Hence, just reinstall jupyter notebook alone and open it from command line using
jupyter notebook
When you now try to import the matplotlib.pyplot in your notebook, it should not give any errors and you can use the same sys.path to check the path it is defaulting to. It should look something like:
Now, it is importing from the site-packages folder.
I am yet to investigate why and how this issue was caused but removing the upgraded Anaconda version helped me.
Run this command on your prompt:
pip install --user matplotlib --force
If it asks any packages related to it. Please install them also . It succeded for me. I hope for you also
Running this command worked for me:
conda install matplotlib --force

matplotlib can't load ft2font on Windows 10

I'm using Anaconda 5.0.1 with Python 2.7.14. When I open a jupyter notebook and try to run the following:
%matplotlib inline
I get the following error:
ImportError Traceback (most recent call last)
C:\toolkits.win\anaconda2\envs\dlc\lib\site-packages\matplotlib\font_manager.py in <module>()
56
57 import matplotlib
---> 58 from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
59 from matplotlib.compat import subprocess
60 from matplotlib.fontconfig_pattern import (
ImportError: DLL load failed: The specified procedure could not be found.
When I try to drill into the error, the problem is with ft2font:
In [1]: from matplotlib import ft2font
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-a32e7826851f> in <module>()
----> 1 from matplotlib import ft2font
ImportError: DLL load failed: The specified procedure could not be found.
I double-checked and made sure freetype is installed:
(dlc) C:\Users\Larry>conda install freetype
Fetching package metadata .............
Solving package specifications: .
# All requested packages already installed.
# packages in environment at C:\toolkits.win\anaconda2\envs\dlc:
#
freetype 2.8 vc9hf582001_0 [vc9]
Any ideas?
conda install freetype --force-reinstall
Improving a bit on the above suggestion:
pip install matplotlib --force-reinstall
def _check_versions():
# Quickfix to ensure Microsoft Visual C++ redistributable
# DLLs are loaded before importing kiwisolver
from . import ft2font
Try install Microsoft Visual C++ redistributable
My solution: unstall matplotlib, and re-install it with pip.
I have the same issue and on my machine the problem was that Java (openJDK) was mentioned in the PATH-variable prior to Python (Anaconda in my case).
If you open a cmd and type
echo %PATH%
you can check if that is the case on your machine as well. If it states ...\Java\openJDK<version>\bin is before the Anaconda directories, the wrong freetype.dll library is getting found and the error occurs.
All you have to do is to change PATH to state the anaconda directories before the Java directories. This may raise another set of issues with Java though...
I found that if conda doesn't activate when the terminal starts up properly, you get this error.
I found that by opening the terminal, typing a bunch of stuff and pressing enter a a lot to prevent conda from activating and then when I tried to run a matplotlib inclusive script it would give me this error, but when I let it start without interference, it would not give me this error (it would run fine, at least past this error).
Considering this, it may be useful to keep import matplotlib at the top of the file if possible, so you don't wait a while and then find out that matplotlib won't load.
I solved this problem by installing the last Microsoft Visual C++ redistributable 2019.
In my case :
python 3.8.7
matplotlib : 20.3.3
test.py
result in IDLE
Debugged into same issue. It seems another access-deny issue.
Solution: Re-install matplotlib in elevated mode.
Launch Anaconda Prompt as Administrator
Run conda install matplotlib
Finish installing any required packages.

Error Importing Python Packages into Jupyter

I've been working in Jupyter IPython notebook (using Python 2.7) and haven't had any issues before this importing and installing packages. Most of my packages were installed via Anaconda. Now I'm randomly having problems importing packages that I've always been able to import. I have an example below. Please help. I'm pretty new to Python so I'm completing stuck on what the problem is and how to fix it.
import pandas as pd
ImportError Traceback (most recent call last)
in ()
----> 1 import pandas as pd
C:\Users\IBM_ADMIN\Anaconda2\lib\site-packages\pandas__init__.py in ()
11 "pandas from the source directory, you may need to run "
12 "'python setup.py build_ext --inplace' to build the C "
---> 13 "extensions first.".format(module))
14
15 from datetime import datetime
ImportError: C extension: No module named numpy not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace' to build the C extensions first.
conda virtual environments will help you a lot. It's good practice to use environments for your projects. And it'll help you avoid causing potential problems with your system's Python.
Try this on the command line:
conda create -n myenv anaconda
source activate myenv
jupyter notebook
That default env will already have pandas; you can install most other things with conda install <package> or, if that doesn't work, pip install <package>.
Running this solved the problem: pip install scipy-0.16.1-cp27-none-win_amd64.whl After doing this, all other packages were able to be re-installed and successfully imported.

Categories