Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'pip install mlx' does not seem to work correctly #10

Closed
guptaaryan16 opened this issue Dec 6, 2023 · 49 comments
Closed

'pip install mlx' does not seem to work correctly #10

guptaaryan16 opened this issue Dec 6, 2023 · 49 comments

Comments

@guptaaryan16
Copy link
Contributor

Seems like the pip install does not install the correct package on my env

>> pip install mlx
Collecting mlx
  Using cached mlx-0.0.0-py3-none-any.whl.metadata (505 bytes)
Using cached mlx-0.0.0-py3-none-any.whl (2.1 kB)
Installing collected packages: mlx
Successfully installed mlx-0.0.0

If you trace the installed package it gives

>> cd ~/opt/anaconda3/envs/test/lib/python3.9/site-packages/mlx
>> ls
__init__.py __pycache__
>> cat __init__.py
print("HELLO WORLD!")

Environment:
M1 Mac Air + Miniconda

@evancoons22
Copy link

evancoons22 commented Dec 6, 2023

I am finding the same issue. init.py is print("HELLO WORLD").

@jagrit06
Copy link
Member

jagrit06 commented Dec 6, 2023

Can you try installing the latest version of mlx (pip install -U mlx) and let me know if the problem still persists ?

@guptaaryan16
Copy link
Contributor Author

I did but that doesn't seem to work either

@jagrit06
Copy link
Member

jagrit06 commented Dec 6, 2023

What was the result of running pip install -U mlx ? Maybe we can try forcing pip install -U mlx==0.0.3 instead ?
Also, can I ask what MacOS version you are using ?

@guptaaryan16
Copy link
Contributor Author

guptaaryan16 commented Dec 6, 2023

>> pip install -U mlx
Requirement already satisfied: mlx in ~/opt/anaconda3/envs/test/lib/python3.9/site-packages (0.0.0)

>> pip install -U mlx==0.0.3
ERROR: Could not find a version that satisfies the requirement mlx==0.0.3 (from versions: 0.0.0)
ERROR: No matching distribution found for mlx==0.0.3

Env:

OS: macOS 14.1.1 23B81 arm64
Host: MacBookAir10,1
Kernel: 23.1.0
CPU: Apple M1
GPU: Apple M1
Memory: 1507MiB / 8192MiB
Python 3.9.18
conda 4.10.3

@jagrit06
Copy link
Member

jagrit06 commented Dec 6, 2023

Hmm, that's odd
mlx==0.0.0 is an invalid distribution and pypi has the correct mlx==0.0.2 and mlx==0.0.3 for macOS 14
Let's upgrade pip and make sure it's not using the cached distribution
pip install --upgrade pip
pip install --force-reinstall --no-cache-dir --upgrade mlx

@andevsr
Copy link

andevsr commented Dec 6, 2023

Package Version


mlx 0.0.3

>>> import mlx.core as mx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/vigneshsairoshanande/Desktop/Coding and DS/mlx/mlx.py", line 1, in <module>
    import mlx.core as mx
ModuleNotFoundError: No module named 'mlx.core'; 'mlx' is not a package

don't know why but for some reason it's not able to recognize the package

M2 Pro

@menzHSE
Copy link
Contributor

menzHSE commented Dec 6, 2023

Just another (positive) data point: I had no issue with pip install -U mlx on a fresh conda environment.

pip install -U mlx
Collecting mlx
  Downloading mlx-0.0.3-cp311-cp311-macosx_13_0_arm64.whl.metadata (212 bytes)
Downloading mlx-0.0.3-cp311-cp311-macosx_13_0_arm64.whl (9.4 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.4/9.4 MB 4.7 MB/s eta 0:00:00
Installing collected packages: mlx
Successfully installed mlx-0.0.3
Python 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:37:07) [Clang 15.0.7 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import mlx.core as mx
>>> a = mx.array([1, 2, 3, 4])
>>> a.shape
[4]
>>> a.dtype
int32

OS: macOS 13.5.2
Host: MacBookPro17,1
Kernel: 22.6.0
CPU: Apple M1
GPU: Apple M1
Python 3.11.6
conda 23.9.0

@guptaaryan16
Copy link
Contributor Author

Hmm, that's odd mlx==0.0.0 is an invalid distribution and pypi has the correct mlx==0.0.2 and mlx==0.0.3 for macOS 14 Let's upgrade pip and make sure it's not using the cached distribution pip install --upgrade pip pip install --force-reinstall --no-cache-dir --upgrade mlx

This does not work either.

@jagrit06 I tried installing it from source using pip install -e . and other commands given here https://ml-explore.github.io/mlx/build/html/install.html# . Even that seems to give an error here

 xcrun: error: unable to find utility "metal", not a developer tool or in PATH
      make[2]: *** [mlx/backend/metal/kernels/copy.air] Error 72
      make[1]: *** [mlx/backend/metal/kernels/CMakeFiles/mlx-metallib.dir/all] Error 2
      make: *** [all] Error 2
      Traceback (most recent call last):
         File "~/opt/anaconda3/envs/test/lib/python3.9/subprocess.py", line 528, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install']' returned non-zero exit status 2.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mlx
Failed to build mlx
ERROR: Could not build wheels for mlx, which is required to install pyproject.toml-based projects

Maybe I should upgrade my python version for more support, but the above trace suggests that metal is not available, not sure why?

@jagrit06
Copy link
Member

jagrit06 commented Dec 6, 2023

Hmm, that's odd mlx==0.0.0 is an invalid distribution and pypi has the correct mlx==0.0.2 and mlx==0.0.3 for macOS 14 Let's upgrade pip and make sure it's not using the cached distribution pip install --upgrade pip pip install --force-reinstall --no-cache-dir --upgrade mlx

This does not work either.

@jagrit06 I tried installing it from source using pip install -e . and other commands given here https://ml-explore.github.io/mlx/build/html/install.html# . Even that seems to give an error here

 xcrun: error: unable to find utility "metal", not a developer tool or in PATH
      make[2]: *** [mlx/backend/metal/kernels/copy.air] Error 72
      make[1]: *** [mlx/backend/metal/kernels/CMakeFiles/mlx-metallib.dir/all] Error 2
      make: *** [all] Error 2
      Traceback (most recent call last):
         File "~/opt/anaconda3/envs/test/lib/python3.9/subprocess.py", line 528, in run
          raise CalledProcessError(retcode, process.args,
      subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--target', 'install']' returned non-zero exit status 2.
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mlx
Failed to build mlx
ERROR: Could not build wheels for mlx, which is required to install pyproject.toml-based projects

Maybe I should upgrade my python version for more support, but the above trace suggests that metal is not available, not sure why?

Building from source requires that you have a working Xcode installation which provides the metal and metallib utilities - could it be possible that that is missing ?

What is the output from running xcode-select -p ?

@kalloc
Copy link

kalloc commented Dec 6, 2023

Hi!

I have the same problem with python installed using pyenv toolkit.

y@u x[main*] $ pip install --upgrade pip
Requirement already satisfied: pip in /Users/y/.pyenv/versions/3.10.1/lib/python3.10/site-packages (23.3.1)
y@u x[main*] $ pip install -U mlx
Requirement already satisfied: mlx in /Users/y/.pyenv/versions/3.10.1/lib/python3.10/site-packages (0.0.0)

also the same problem with native python:

y@u x[main*] $  /usr/bin/python3 -m pip install --upgrade pip
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: pip in /Users/y/Library/Python/3.8/lib/python/site-packages (23.3.1)
y@u x[main*] $ /usr/bin/python3 -m pip install mlx -U
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: mlx in /Users/y/Library/Python/3.8/lib/python/site-packages (0.0.0)

OS Version is:

y@u x[main*] $ sw_vers
ProductName:    macOS
ProductVersion: 11.7.7
BuildVersion:   20G1345

@imadcat
Copy link

imadcat commented Dec 6, 2023

I'm having the exact same problem in a newly created condo env.

Update: I have succeeded in installing it and runing the stable diffusion example with the Mac system python.

@oliverks
Copy link

oliverks commented Dec 6, 2023

I upgraded pip and tried this

(enc) (base) MacBook-Pro-4:stable_diffusion oliverks$ pip install -U mlx==0.0.3
ERROR: Could not find a version that satisfies the requirement mlx==0.0.3 (from versions: 0.0.0)
ERROR: No matching distribution found for mlx==0.0.3

My OS is
ProductName: macOS
ProductVersion: 12.6
BuildVersion: 21G115

@sermetc
Copy link

sermetc commented Dec 6, 2023

I am having the same issue on a Macbook Air 2020 M1 with a fresh python 3.11 virtual environment.
pip only downloads v.0.0.0 of mlx.

tried the following commands after upgrading pip as pip install --upgrade pip (not in this order):
pip install mlx
pip --force-reinstall --no-cache-dir --upgrade mlx
pip install mlx==0.0.3

all of the above commands somehow downloads the v0.0.0.

ProductName: macOS
ProductVersion: 13.5.1
BuildVersion: 22G90

@nmrenyi
Copy link

nmrenyi commented Dec 6, 2023

I encountered the same problem. I used pip install mlx to install and when I tried to run python main.py in mnist, the following output appeared:

HELLO WORLD!
Traceback (most recent call last):
  File "/Users/renyi/Code/mlx-examples/mnist/main.py", line 8, in <module>
    import mlx.core as mx
ModuleNotFoundError: No module named 'mlx.core'

Here are some information about my machine and environment

MacBook Air M2 with 24GB memory

ProductName: macOS
ProductVersion: 14.1.1
BuildVersion: 23B81

Python Version: 3.12.0
Pip Version: 23.3.1

@awni
Copy link
Member

awni commented Dec 6, 2023

It looks like we don't have a wheel for python 12. So for now you can do:

conda create -n myenv python=3.11
conda activate myenv
pip install mlx

We will add a wheel for python 12 ASAP

@nmrenyi
Copy link

nmrenyi commented Dec 6, 2023

It looks like we don't have a wheel for python 12. So for now you can do:

conda create -n myenv python=3.11
conda activate myenv
pip install mlx

We will add a wheel for python 12 ASAP

Your solution works for me. Thanks!

@guptaaryan16
Copy link
Contributor Author

This seems to have worked for me python3.10 -m pip install mlx, installed the right package.

@NilayGaitonde
Copy link

NilayGaitonde commented Dec 6, 2023

I've created a new conda env and now i'm getting the following error message
pip install mlx
ERROR: Could not find a version that satisfies the requirement mlx (from versions: none)
ERROR: No matching distribution found for mlx
Even tried pip install mlx==0.0.3
ERROR: Could not find a version that satisfies the requirement mlx==0.0.3 (from versions: none)
ERROR: No matching distribution found for mlx==0.0.3

Python version: 3.10.13
Pip version: 23.3.1
Macbook air M1 2020 with 8GB memory running Sonoma 14.0
Build version: 23A344

@msitarzewski
Copy link

I used pip3 wherever I saw pip and it worked perfectly.

@jagrit06
Copy link
Member

jagrit06 commented Dec 6, 2023

I've created a new conda env and now i'm getting the following error message pip install mlx ERROR: Could not find a version that satisfies the requirement mlx (from versions: none) ERROR: No matching distribution found for mlx Even tried pip install mlx==0.0.3 ERROR: Could not find a version that satisfies the requirement mlx==0.0.3 (from versions: none) ERROR: No matching distribution found for mlx==0.0.3

Python version: 3.10.13 Pip version: 23.3.1 Macbook air M1 2020 with 8GB memory running Sonoma 14.0 Build version: 23A344

Can you also try using pip3 install mlx or python3.10 -m pip install mlx and let me know if that helps ?

@NilayGaitonde
Copy link

I've created a new conda env and now i'm getting the following error message pip install mlx ERROR: Could not find a version that satisfies the requirement mlx (from versions: none) ERROR: No matching distribution found for mlx Even tried pip install mlx==0.0.3 ERROR: Could not find a version that satisfies the requirement mlx==0.0.3 (from versions: none) ERROR: No matching distribution found for mlx==0.0.3
Python version: 3.10.13 Pip version: 23.3.1 Macbook air M1 2020 with 8GB memory running Sonoma 14.0 Build version: 23A344

Can you also try using pip3 install mlx or python3.10 -m pip install mlx and let me know if that helps ?

Nope still getting the same error

@awni
Copy link
Member

awni commented Dec 6, 2023

@NilayGaitonde could you run:

pip debug --verbose

It should show you what pip thinks your machine is compatible with. We're looking for something like:

cp310-cp310-macosx_13_0_arm64

@oliverks
Copy link

oliverks commented Dec 6, 2023

When I run that command I get a bunch of

co3x

where x is between 2 and 8, and I see no mention of arm in any of the outputs.

@x
Copy link

x commented Dec 6, 2023

I was hitting this and then realized it was because my pyenv/python/pip were all running under rosetta. You can check this with:

python -c "import platform; print(platform.processor())"

If you get back arm it's the non-rosetta version. If you get back i386 it is and you will have to use a non-rosetta python/pip.

If you're in deep with pyenv and pyenv-virtualenv I recommend setting a new PYENV_ROOT for your non-rosetta python versions and venvs and then re-evalling the pyenv init and pyenv virtualenv-inits.

@kalloc
Copy link

kalloc commented Dec 6, 2023

I was hitting this and then realized it was because my pyenv/python/pip were all running under rosetta. You can check this with:

python -c "import platform; print(platform.processor())"
y@u x[main*] $ python -c "import platform; print(platform.processor())"
arm

As I learned, the problem on my side in OSX version, I'm still on Big Sur, but you have build only for 13.x and 14.x.

@oliverks
Copy link

oliverks commented Dec 6, 2023

OK great, that was a duh moment, my version was still x86. So I used python3.11 natively which is arm. I now see

cp311-cp311-macosx_12_0_arm64

on the version, but it can't find mlx. I get

(enc) (base) MacBook-Pro-4:mlx oliverks$ pip install mlx
ERROR: Could not find a version that satisfies the requirement mlx (from versions: none)
ERROR: No matching distribution found for mlx

@awni
Copy link
Member

awni commented Dec 6, 2023

To summarize on how to install MLX currently using the PyPI packages:

  • You need a machine with an M-series chip
  • OS >= 13.0
  • Python between 3.8-3.11

If you meet those requirements and it still doesn't work, make sure you are using a native python. The output of:
python -c "import platform; print(platform.processor())" should be arm.

@awni
Copy link
Member

awni commented Dec 6, 2023

@oliverks your OS is below the supported versions. Your best bet is to update to macOS 13 or 14.

@sermetc
Copy link

sermetc commented Dec 6, 2023

My problem is fixed. I was running iTerm on rosetta and Homebrew and all the installed packages (including python versions) were all i386 versions. I now switched completely to arm builds and pip install mlx installs correctly and imports just fine. Thank you all :)

@NilayGaitonde
Copy link

Hey!! yes the problem was fixed thank you! I guess I had the wrong conda architecture on my mac and so was getting i386 on running python -c "import platform; print(platform.processor())" on switching it back to arm I was able to download the correct package. Thank you for your help!!

@ibehnam
Copy link

ibehnam commented Dec 7, 2023

python -c "import platform; print(platform.processor())"

This seems like something that should be mentioned in the readme/docs in BOLD.
I didn't use a native Python, but the following worked for me:

CONDA_SUBDIR=osx-arm64 conda create -n AppleMLX python=3.11

@Huvinesh-Rajendran-12
Copy link

Alternatively, including the xcode-select path also helps with this issue.

@awni
Copy link
Member

awni commented Dec 7, 2023

The install docs are updated to include the issues brought up in this thread. I am going to close this for now, but feel free to reopen if there are new issues with installation.

@awni awni closed this as completed Dec 7, 2023
@cpareja3025
Copy link

I'm currently running into this error when I'm trying to import mlx:

import mlx.core as mx

ImportError: dlopen(/Users/you/opt/anaconda3/envs/native/lib/python3.12/site-packages/mlx/core.cpython-312-darwin.so, 0x0002): tried: '/Users/you/opt/anaconda3/envs/native/lib/python3.12/site-packages/mlx/core.cpython-312-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

I followed the directions above and created a conda env using the arm arch. I followed the directions from this post. For some context, I'm running:

Python version: 3.12.0
Pip version: 23.3.2
Macbook Pro M1 2020 with 8GB memory running Sonoma 14.2.1

@awni
Copy link
Member

awni commented Dec 21, 2023

Not sure what's going on there. It looks like your environment might be a bit wonky though.

I would try making a fresh conda environment. Make sure the below gives arm

python -c "import platform; print(platform.processor())"

Then python -m pip install mlx

Let me know if you figure out the problem and what it ended up being!

@cpareja3025
Copy link

cpareja3025 commented Dec 22, 2023

Hmm very weird, it looks like it might have been a problem with VSCode. I was importing mlx on a jupyter notebook in VSCode and I was getting the above error I mentioned. I moved out of VSCode, and opened a notebook with the conda environment I initially created with an arm arch. I was able to successfully import mlx and I was even able to import mlx using Python in the terminal so it seems like a VSCode issue.

Update: I got it to work on VSCode by following @awni your steps to create a fresh env, thanks for the help :)

@ajamous
Copy link

ajamous commented Dec 28, 2023

I found an easy fix to this issue:

if you see i386 when you run this command: python3 -c "import platform; print(platform.processor())"

Just Download & install macOS 64-bit universal2 installer

Once done, you should see arm now when you rerun: python3 -c "import platform; print(platform.processor())

Now try pip install mlx , it should work.

@shujuecn
Copy link

shujuecn commented Jan 6, 2024

Issue Description:

I created a Python 3.9 virtual environment using miniconda and successfully installed mlx.

However, when I try to import mlx.core, I encounter an error.

Based on the error message, should I update my Mac OS version?

Environment:

  • Apple M1 Pro 16G
  • macOS 13.0 (22A380)
  • Python
Python 3.9.18 | packaged by conda-forge | (main, Dec 23 2023, 16:35:41)
[Clang 16.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Error Message:

>>> import mlx.core as mx
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dlopen(/Users/cuinuan/miniconda3/envs/labelimg/lib/python3.9/site-packages/mlx/core.cpython-39-darwin.so, 0x0002): Symbol not found: _cblas_sgemm$NEWLAPACK
  Referenced from: <C3D30763-555E-35AD-B21B-85F410FA8F82> /Users/cuinuan/miniconda3/envs/labelimg/lib/python3.9/site-packages/mlx/lib/libmlx.dylib (built for macOS 13.3 which is newer than running OS)
  Expected in:     <E6C2D470-8878-372D-B9DB-0EDCA1303272> /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
>>> import mlx
>>>

Other Information:

python -c "import platform; print(platform.processor())"
arm

@awni
Copy link
Member

awni commented Jan 6, 2024

macOS 13.0 (22A380)

I would update your OS and try a gain. We officially support OS 13.5 and higher.

@casafurix
Copy link

any solution for windows 11?

Specs:
python -c "import platform; print(platform.processor())"
AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD

@awni
Copy link
Member

awni commented Jan 9, 2024

Unfortunately not. Apple silicon is the primary focus. You could probably get things working on linux without much difficulty building from source. But beyond that, we are not supporting other platforms for the time being.

@xpatronum
Copy link

macOS 13.0 (22A380)

I would update your OS and try a gain. We officially support OS 13.5 and higher.

I wonder why it couldn't work under osx Monterey (12.*) if PyTorch natively works under Osx Monterey (e.g. allows you to move nn.Module to nps device) ?

@stedmanblake
Copy link

python 3.11 is not working for me

  1. created new virtual environment w/ python 3.11
  2. activated and ran pip install
  3. failed: couldn't find mlx, as before with python 3.12 🤔
(.venv) ➜  mistral git:(main) python3.11 -m pip install -r requirements.txt
ERROR: Could not find a version that satisfies the requirement mlx>=0.8.0 (from versions: none)
ERROR: No matching distribution found for mlx>=0.8.0
(.venv) ➜  mistral git:(main) python3.11 --version
Python 3.11.9

@awni
Copy link
Member

awni commented Apr 18, 2024

Did you check this issue #200 ? Most likely you are running python via rosetta for x86:

python -c "import platform; print(platform.processor())"

Should print arm.

Check out the installation instructions for more troubleshooting tips

@stedmanblake
Copy link

stedmanblake commented Apr 18, 2024

Did you check this issue #200 ? Most likely you are running python via rosetta for x86:

python -c "import platform; print(platform.processor())"

Should print arm.

Yep tried this, prints arm, still no luck.

Check out the installation instructions for more troubleshooting tips

Thanks! Will update this thread w/ the solution if i can get it working

@awni
Copy link
Member

awni commented Apr 18, 2024

Make sure you are using the same python:

python3.11 -c "import platform; print(platform.processor())"

@stedmanblake
Copy link

stedmanblake commented Apr 19, 2024

python 3.11 is not working for me

  1. created new virtual environment w/ python 3.11
  2. activated and ran pip install
  3. failed: couldn't find mlx, as before with python 3.12 🤔
(.venv) ➜  mistral git:(main) python3.11 -m pip install -r requirements.txt
ERROR: Could not find a version that satisfies the requirement mlx>=0.8.0 (from versions: none)
ERROR: No matching distribution found for mlx>=0.8.0
(.venv) ➜  mistral git:(main) python3.11 --version
Python 3.11.9

OK the issue was that I was on macOS 12 and mlx requires 13+.

✅ Working now after updating to macOS 14. Thanks @awni 🙏

@greenhand0403
Copy link

I use conda install -c conda-forge mlx , it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests