Search code examples
pythonvirtualenvapple-m1

virtual environment's architecture made by pipenv become intel chip on apple mac m1


enter image description here

I'm struggling with using python on mac m1, and I found that there's an issue on pipenv for making virtual environment with correct architecture. As you can see on the above picture, when I open the terminal with aram64 architecture and make virtual environment using pipenv, the architecture becomes i386. I'm not sure if this causes a big problem, it blocked me to use some of 3rd party packages such as numpy and pandas, although I failed to reproduce the error. (As I remember, it showed an error message like mach-o: but wrong architecture.) The version of pipenv I'm using is 2021.5.29.

> arch
arm64

> pipenv --python 3.8
Creating a virtualenv for this project...
Pipfile: /Users/seewoolee/development/tmp/Pipfile
Using /usr/bin/python3 (3.8.9) to create virtualenv...
⠦ Creating virtual environment...created virtual environment CPython3.8.9.final.0-64 in 388ms
  creator CPython3macOsFramework(dest=/Users/seewoolee/.local/share/virtualenvs/tmp-miv_sugU, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/Users/seewoolee/Library/Application Support/virtualenv)
    added seed packages: pip==21.2.4, setuptools==58.1.0, wheel==0.37.0
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator

✔ Successfully created virtual environment!
Virtualenv location: /Users/seewoolee/.local/share/virtualenvs/tmp-miv_sugU
Creating a Pipfile for this project...

> pipenv shell

Launching subshell in virtual environment...
. /Users/seewoolee/.local/share/virtualenvs/tmp-miv_sugU/bin/activate

> arch
i386

Solution

  • I had this exact problem, and @Beel's comment gave me the clue that I needed to solve it. In my case, pipenv was referencing a version of python that was built for x86_64. Specifically:

    $ which pipenv
    /opt/anaconda3/bin/pipenv
    $ file /opt/anaconda3/bin/python
    /opt/anaconda3/bin/python: Mach-O 64-bit executable x86_64
    

    This happened when I installed Anaconda and it put itself at the front of my PATH. After adjusting my path to resolve to the version of Pipenv I had installed, pipenv shell does not switch the arch as a side-effect, and I was able to install the correct versions of numpy, psutil, etc.