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
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
installed pytorch with conda :
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda install
pytorch torchvision cpuonly -c pytorch
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
I updated conda:
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda update
conda
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
Installed mkl=2019 :
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda install
mkl=2019
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ conda list | grep
torch
cpuonly 1.0 0 pytorch
facenet-pytorch 0.1.0 pypi_0 pypi
pytorch 1.3.0 py3.7_cpu_0 [cpuonly] pytorch
torchfile 0.1.0 pypi_0 pypi
torchvision 0.4.1 py37_cpu [cpuonly] pytorch
But it still says "no module torch" :
(base) (3.8.0/envs/my_virtual_env-3.8.0) marco#pc:~/facenet_pytorch/examples$ python3
Python 3.8.0 (default, Oct 30 2019, 16:20:23)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'torch'
>>>
I discovered that the problem appears only with python 3.8.0 version
(base) marco#pc:~/facenet_pytorch$ python3
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>>
Ubuntu 18.04.02 Server Edition
Or, may be, it's just a matter of python environments, as you said.
But I do not understand why just activating conda environment, with "conda activate", it doesn't work
Marco
First create a Conda environment using:
conda create -n pytorch_env python=3 ( you can create with any python version )
Activate the environment using:
conda activate pytorch_env
Now install PyTorch using:
conda install pytorch-cpu torchvision -c pytorch
Go to python shell and import using the command:
import torch
Thanks all for your kind answers.
I solved the problem
- first, "downgrading" python from 3.8.0 to 3.7.3 because I checked in PyTorch's chat environment that PyTorch is not yet compatible with python 3.8.0
- and then, after removing everything already installed, installing the latest version of PyTorch via cunda, as you kindly explained
Pytorch can be installed via pip and conda. For that, you need to create a separate conda environment. Thus, it will not corrupt the base environment.
Steps to create a new conda environment as follows:
conda create -n conda_pytorch python=3.6
source activate conda_pytorch
Follow the below command to install pytorch via pip:
pip install torch==1.3.1+cpu torchvision==0.4.2+cpu -f https://download.pytorch.org/whl/torch_stable.html
Pytorch installation via conda:
conda install pytorch torchvision cpuonly -c pytorch
Verify the pytorch installation in the python shell using:
import torch
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.
I am installing anaconda environment with keras, and using theano backend. But I cannot get theano to work. here is what I have done and also errors noted afterwards.
Step 1: download the latest version of anaconda, then install in linux by ' bash Anaconda3-5.0.1-Linux-x86_64.sh'
Step 2: conda install -c conda-forge keras, which installs keras 2.0.9
This also installs theano 1.0.1, as shown below:
The following NEW packages will be INSTALLED:
keras: 2.0.9-py36_0 conda-forge
libgpuarray: 0.7.5-0 conda-forge
mako: 1.0.7-py36_0 conda-forge
pygpu: 0.7.5-py36_0 conda-forge
theano: 1.0.1-py36_1 conda-forge
The following packages will be SUPERSEDED by a higher-priority channel:
conda: 4.3.30-py36h5d9f9f4_0 --> 4.3.29-py36_0 conda-forge
conda-env: 2.6.0-h36134e3_1 --> 2.6.0-0 conda-forge
Next, testing theano:
python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 13 2017, 12:02:49)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import theano
>>> theano.ifelse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'theano' has no attribute 'ifelse'
The error shown in the last line is preventing me using theano and keras properly. all my code that works on a different platform does not work, because they will generate an error like that.
I also tried to follow instructions on http://deeplearning.net/software/theano/install_ubuntu.html with a fresh anaconda installation to just install theano, without keras. But after installation, with the testing line above, I get the same error.
Any suggestion on how to fix this?
It is not import by default.
Try to use
import theano.ifelse