Pandas build fail M1 Big Sur 11.1 - python-3.x

I am using MacBook m1 which is running Big Sur 11.1 ,and I have installed Xcode-commandline-tools version 12.3 and it has installed python3.8.5 and pip3 .python3 and pip are native apps,that is they run in ARM
pip3 version 20.3.3
python3 version 3.8.5
setuptools version 51.0.0
wheel version 0.36.2
when I type python3 -m pip install pandas
The output is :
Defaulting to user installation because normal site-packages is not writeable
Collecting pandas
Downloading pandas-1.2.0.tar.gz (5.4 MB)
|████████████████████████████████| 5.4 MB 150 kB/s
Installing build dependencies ... error
And with a very long list of error about 30,000 lines (only last few lines)
and
pip3 list output is
cppy 1.1.0
kiwisolver 1.3.1
numpy 1.20.0rc1
pip 20.3.3
pyparsing 2.4.7
python-dateutil 2.8.1
setuptools 51.0.0
six 1.15.0
wheel 0.36.2
Is pandas not yet supported or I am doing it wrong and same goes with Matplotlib.

Install Miniforge for arm64 (Apple Silicon)latest installer here: installer here
Now create a conda environment for whatever version you have (I'm running 3.9.2)
conda create -n cenv python=3.9.2
conda activate cenv
conda install pandas
You will drive yourself nuts trying to get all the different packages working if you try to go from wheels/pip, at time of writing.
I think I got pandas working but couldn't get matplotlib working due to kiwi solver issues. Use miniforge/conda. This is the way.

You can try installing pandas version 0.25.3. This is the most stable release of Pandas which brings in numpy 1.19.1 which is the most stable version of NUMPY.
try running pip install pandas==0.25.3, and it should install the required packages.

Related

Modules installed globally not found in VS Code Jupyter Notebook

I've installed several Python modules from PyPi globally on Mac OS using pip3. Running pip3 list confirms that they are installed:
user#users-MacBook-Pro SER-neural-net % pip3 list
Package Version
------------------ ---------
appdirs 1.4.4
audioread 3.0.0
...
librosa 0.9.2
numpy 1.23.4
pip 22.3.1
scikit-learn 1.1.3
scipy 1.9.3
sklearn 0.0.post1
sounddevice 0.4.5
soundfile 0.11.0
torch 1.13.0
...
From the integrated terminal in VS Code where I am running the notebook, I have run the following commands to determine which Python interpreter to use:
user#users-MacBook-Pro SER-neural-net % which pip3
/usr/local/bin/pip3
user#users-MacBook-Pro SER-neural-net % which python3
/usr/local/bin/python3
user#users-MacBook-Pro SER-neural-net % python3 --version
Python 3.7.9
I have selected the appropriate interpreter at the top right of Jupyter Notebook view in VS Code:
But the modules confirmed to be installed for this interpreter are not found:
What has gone wrong?
use this:
python3 -m pip install --user (library)
for example:
python3 -m pip install --user pandas

Why can't I import scikit-learn from Spyder, but I can import it from the command line?

I installed Spyder 5 for MacOS Big Sur using the standalone installer on the Spyder website (i.e., no Anaconda required). I had been using Spyder 4.2.1 and successfully importing scikit-learn. However, after I installed Spyder 5, I couldn't import scikit-learn, and got a ModuleNotFound error. So I removed the "sklearn" directory from the "Library/Python/2.7/lib/python/site-packages" directory where it was placed, and re-installed scikit-learn with
pip install -U scikit-learn
as it says on the scikit-learn website. I can now import the module from my Mac's terminal command line, but when I try on Spyder, I get a long message that includes
ImportError: dlopen(/Users/my_user_name/Library/Python/2.7/lib/python/site-packages/sklearn/__check_build/_check_build.so, 2): Symbol not found: __PyThreadState_Current
Referenced from: /Users/my_user_name/Library/Python/2.7/lib/python/site-packages/sklearn/__check_build/_check_build.so
Expected in: flat namespace
in /Users/my_username/Library/Python/2.7/lib/python/site-packages/sklearn/__check_build/_check_build.so
as well as
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run python setup.py install or
make in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
What can I do at this point?
you need install Dependencies :
scikit-learn requires:
Python (>= 3.6)
NumPy (>= 1.13.3)
SciPy (>= 0.19.1)
joblib (>= 0.11)
threadpoolctl (>= 2.0.0)
for good result requirements.txt
Note:Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4. scikit-learn 0.23 and later require Python 3.6 or newer.
pip install scikit-learn==0.20.4
learn more go to this

numpy build fail in M1 Big sur 11.1

I am using MacBook m1 which is running Big Sur 11.1 ,and I have installed Xcode-commandline-tools version 12.3 and it has installed python3.8.5 and pip3 .python3 and pip are native apps,that is they run in ARM
pip3 version 20.3.3
python3 version 3.8.5
setuptools version 51.0.0
wheel version 0.36.2
when I type python3 -m pip install numpy
The output is :
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
Using cached numpy-1.19.4.zip (7.3 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing wheel metadata: started
Preparing wheel metadata: finished with status 'done'
Building wheels for collected packages: numpy
Building wheel for numpy (PEP 517): started
sandeep#Sandeeps-Air ~ % cat a
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
Using cached numpy-1.19.4.zip (7.3 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing wheel metadata: started
Preparing wheel metadata: finished with status 'done'
Building wheels for collected packages: numpy
Building wheel for numpy (PEP 517): started
Building wheel for numpy (PEP 517): finished with status 'error'
Failed to build numpy
and with a very large list of errors
Is numpy still not supported in M1 or am I doing it wrong ?
I had exactly the same issue with my brand new Mac Mini. After spending an afternoon reading this issue on github, I finally succeeded. However, it only seems to work with v1.20.0rc2 or above...
Long story short, these were the steps I've taken to get it working:
pip3 install Cython
git clone https://github.com/numpy/numpy.git
cd numpy
pip3 install . --no-binary :all: --no-use-pep517
After that, I could cd into my virtualenv and import numpy:
>>> import numpy as np
>>> np.__version__
'1.21.0.dev0+402.gc4ae3ce64'
>>>
Next up: pandas.
UPDATE:
After some more searching, I found this interesting article, which states that you can easily start Terminal in Rosatta mode. That also solved the issues.
However, I am working with a headless Mac Mini, so I still have to find out whether that solution also is feasable in that particular setup.
UPDATE 2
I now have pandas working as well, thanks to this answer on SO.
Yes, numpy still seems to be not supported in stable, but if you are ready to work with unstable version try this command:
pip3 install numpy --compile --pre
This will recompile all the necessary code from unstable branch.
Worked for me.
Since NumPy 1.21.0, it has released universal2 wheels for Python 3.8 and Python 3.9 on Mac. It becomes installable on Mac M1.
I have tested it on my M1 with Python 3.9.2, macOS Big Sur (11.5.1), and pip 21.1.3. Just use pip/pip3 to install it.
release note: https://github.com/numpy/numpy/releases/tag/v1.21.0
Note that the only reliable build environment for the full data-science suite for python at the moment (Feb 2021) on M1 ARM architecture is via miniforge.
e.g.
brew install --cask miniforge
conda init zsh
conda activate
conda install numpy scipy scikit-learn
What it worked for me was to run iTerm with the option "open using Rosetta" enabled and upgrade pip before installing numpy.
Instead of enabling this option you could also run the pip install and python selecting a different architecture with arch -x86_64. Example using a virtual environment:
$ python3 -m venv ~/myenv
$ source ~/myenv/bin/activate
(myenv)$ python3 -m pip install --upgrade pip
Collecting pip
Using cached pip-21.0.1-py3-none-any.whl (1.5 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.2.3
Uninstalling pip-20.2.3:
Successfully uninstalled pip-20.2.3
Successfully installed pip-21.0.1
(myenv)$ arch -x86_64 pip install numpy
Collecting numpy
Using cached numpy-1.20.1-cp39-cp39-macosx_10_9_x86_64.whl (16.1 MB)
Installing collected packages: numpy
Successfully installed numpy-1.20.1
(myenv)$ arch -x86_64 python3
Python 3.9.1 (v3.9.1:1e5d33e9b9, Dec 7 2020, 12:44:01)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.20.1'
I was trying to install numpy without rosetta 2, but the solutions listed here failed for me. Brew saved the day. I installed it with
brew install numpy
First of all numpy support is not there for m1 arm based Macs using python 3.8 version. The method to workaround with this is to update your python version to 3.9. This is the latest version of python and can be a bit unstable. If you want to work with tensorflow then do not update to python 3.9 version as they don't support it and support will come up with version 2.5 (estimated). So, if you don't want to use tensorflow and want to use numpy by using pip install then go ahead install python3.9 and make it your default python interpreter.
I will recommend you to use Homebrew for installation of python 3.9 as it as easy as running a simple command.
faced the same problem in monterey too.
upgrading pip version to 21.3.1 from 20.2.3 solved the issue.
source env/bin/activate
pip install -U pip
pip install numpy
Try this as I was able to install numpy using this method.
brew install openblas (use the native homebrew instead of running it under Rosetta 2)
OPENBLAS="$(brew --prefix openblas)" pip3 install numpy
A solution for pipenv users:
git clone https://github.com/numpy/numpy.git --recursive
cd numpy
pip3 install build
python3 -m build
cd dist
cp numpy-1.22.0.dev0+97.g4635fc852-cp39-cp39-macosx_11_0_arm64.whl ../../ # filename is current sample, next folder to your project directory
Add into Pipfile:
[packages]
numpy = { path = "numpy-1.22.0.dev0+97.g4635fc852-cp39-cp39-macosx_11_0_arm64.whl" }
pipenv install
then your numpy will be installed.
As mentioned in a previous answer, the installation went smooth when I opened the terminal using Rosetta.
However for anyone who is using Pycharm terminal, Do the following to get the terminal running using Rosetta.
Go to Preferences -> Tools -> Terminal
Update the script path to "env /usr/bin/arch -x86_64 /bin/zsh --login"
I tried a lot of other options but so far this was the simplest solution I found.
After trying a ton of suggested methods I finally found a way to use numpy on my new macbook pro with an M1 chip.
Use this docker preview for the M1 chip.
E.g. here's a Dockerfile that successfully installs numpy.
FROM python
RUN python3 -m pip install numpy
Build it with:
docker build -t numpytest:latest .
Then run it with:
docker run -it --rm numpytest:latest
And you can verify that numpy is installed and works correctly:
Python 3.9.1 (default, Jan 12 2021, 13:13:57)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.arange(15).reshape(3, 5)
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]])
>>>
Well I guess it's fixed in unreleased upstream. A pip install of 1.20.2, the latest as of this writing, failed. But I cloned git#github.com:numpy/numpy.git, then did the normal "python setup.py install" in my venv (which is Python 3.9.5 installed via Homebrew) and it seems to work. Haven't thoroughly tested it yet.
CrepeGoat's comment worked for me:
pip3 install --no-binary :all: --no-use-pep517 numpy

How to change Python version in Anaconda, install Numpy and sklearn 0.17?

I'm new to machine learning. I literally have no idea what I'm doing but I need tools to understand how machine learning works.
I just download Anaconda Python from here. I saw that the version I downloaded is 3.7 but I need a 3.5.
I don't really understand how to install Numpy 1.10 as well as sklearn 0.17
Can you please guide me how to install these?
The best way to do this is by using a custom conda environment. You can do this by either of the following:
install the full version of Anaconda (the current version with Python 3.7)
install Miniconda for a much smaller download
Then open Anaconda Prompt in the Windows start menu. Then do:
conda create -n customenvname python=3.5 numpy=1.10 scikit-learn=0.17
Follow the prompts.
To activate the new environment and get off and running, just do conda activate customenvname. You are now in a Python 3.5 environment with all the dependencies you need:
(base) C:\Users\user>conda activate customenvname
(customenvname) C:\Users\user>python --version
Python 3.5.6 :: Anaconda, Inc.
(customenvname) C:\Users\user>conda list
# packages in environment at C:\Users\user\Miniconda3\envs\customenvname:
#
# Name Version Build Channel
blas 1.0 mkl
certifi 2018.8.24 py35_1
mkl 11.3.3 1
numpy 1.10.4 py35_2
pip 10.0.1 py35_0
python 3.5.6 he025d50_0
scikit-learn 0.17.1 np110py35_1
scipy 0.17.1 np110py35_1
setuptools 40.2.0 py35_0
vc 14.1 h0510ff6_4
vs2015_runtime 14.15.26706 h3a45250_0
wheel 0.31.1 py35_0
wincertstore 0.2 py35hfebbdb8_0
NOTE: the mkl package is an optimization of some of the most used scientific computing libraries maintained by anaconda.

Can someone help me in installing python package "Prophet" on windows 10

Can someone help me in installing python package "Prophet" on windows 10 .
I tried installing python 3.5 and the dependency 'pystan' but yet I get below error.
"The package setup script has attempted to modify files on your system that are not within the EasyInstall build area, and has been aborted.This package cannot be safely installed by EasyInstall, and may not support alternate installation locations even if you run its setup script by hand.Please inform the package's author and the EasyInstall maintainers to find out if a fix or workaround is available.
Command "python setup.py egg_info" failed with error code 1 in c:\users\suman\appdata\local\temp\pip-build-aqoiqs\fbprophet\"`
I spent a good two days on this issue, finally, I found the following solution
1) Download and install Anaconda 3 (for python 3.6)
2) Create an environment and call it whatever you like
3) Run that environment (which will open the command prompt)
4) follow the following steps in command prompt : (commands are shown in bold)
python -m pip install -U pip
Requirement already up-to-date: pip in c:\users\william\anaconda3\envs\testtime\lib\site-packages
conda install -c conda-forge pystan
Fetching package metadata ...............
Solving package specifications: .
Package plan for installation in environment C:\Users\William\Anaconda3\envs\Testtime:
The following NEW packages will be INSTALLED:
backports: 1.0-py36_1 conda-forge
backports.functools_lru_cache: 1.4-py36_1 conda-forge
ca-certificates: 2017.11.5-0 conda-forge
cycler: 0.10.0-py36_0 conda-forge
cython: 0.27.3-py36_0 conda-forge
freetype: 2.7-vc14_1 conda-forge [vc14]
icc_rt: 2017.0.4-h97af966_0
icu: 58.2-vc14_0 conda-forge [vc14]
intel-openmp: 2018.0.0-hd92c6cd_8
jpeg: 9b-vc14_2 conda-forge [vc14]
libpng: 1.6.34-vc14_0 conda-forge [vc14]
matplotlib: 2.1.0-py36_0 conda-forge
mkl: 2018.0.1-h2108138_4
numpy: 1.13.3-py36ha320f96_0
openssl: 1.0.2m-vc14_0 conda-forge [vc14]
pyparsing: 2.2.0-py36_0 conda-forge
pyqt: 5.6.0-py36_4 conda-forge
pystan: 2.17.0.0-py36_vc14_0 conda-forge [vc14]
python-dateutil: 2.6.1-py36_0 conda-forge
pytz: 2017.3-py_2 conda-forge
qt: 5.6.2-vc14_1 conda-forge [vc14]
sip: 4.18-py36_1 conda-forge
six: 1.11.0-py36_1 conda-forge
tornado: 4.5.2-py36_0 conda-forge
zlib: 1.2.11-vc14_0 conda-forge [vc14]
pip install fbprophet
I also had several issues installing prophet on my Windows 10 machine using conda and Python 3.7.
The following steps made it work:
Create a fresh conda environment
Install pystan and other dependencies using conda install numpy cython matplotlib scipy pandas -c conda-forge (see https://pystan2.readthedocs.io/en/latest/windows.html#steps)
Install prophet using conda install prophet -c conda-forge
In then still had a numpy error Importing the numpy c-extensions failed... as described here: https://numpy.org/devdocs/user/troubleshooting-importerror.html But this was due to my IDE which is VS Code as I could successfully run my prohet model using the command line with the activated conda environment.
So please also make sure to test the installation from the command line in order to rule out that the error stems from you IDE.
Not sure if the same trick would work on Windows, anyways posting w.r.t what just worked on RHEL 7, f.w.i.w
Motivation was installing fbprophet using conda:
conda install -c conda-forge fbprophet
and, it could install pystan==2.17.1.0 and fbprophet==0.6
So, the trick was:
uninstall the pystan package when you had earlier run pip3 install fbprophet, basically one needs to execute the following:
pip3 install pystan==2.17.1.0
pip3 install fbprophet==0.6
And one can thereby import fbprophet in python3 terminal, so working :)
I currently have a fairly vanilla install of Python 3.5 on my Windows 10 machine that I setup using Anaconda.
I was able to install Prophet using the below command, that might work for you. Depending on how your installed Python you may need to run the below command in a cmd shell that was opened as administrator.
pip install prophet
Whenever I have tried to install fbprophet package multiple issues have come.I will suggest a few steps, hopefully they should work.
Close all existing Python / R running instances. If possible restart the machine. I have seen to work as few libraries / dependencies which I want to update might be getting used by existing running instances.
Use anaconda prompt.
First install pystan -
`conda install pystan`
Now install fbprophet
'conda install -c conda-forge fbprophet
Hopefully it should work for you. Also, ensure you have admin rights.
I faced the same issue and my solution was to:-
Create a new environment with Python3.5
conda create -n pht python=3.5 anaconda
Install Prophet using the command.
conda install -c conda-forge fbprophet
I didn't install 'gcc' although this was advised before installing Prophet.

Resources