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

'zsh: killed python' while executing from virtualenv on macOS Big Sur for Python 2.7 #4502

Closed
aberrya opened this issue Oct 27, 2020 · 36 comments

Comments

@aberrya
Copy link

aberrya commented Oct 27, 2020

zsh: killed python while executing from virtualenv on macOS Big Sur (platform: arm64) for Python 2.7
It is working fine for Python 3.8

Expected result

Python Shell should launch from virtual env shell.
On using pipenv sync should install dependencies.

Actual result

zsh: killed python. Python shell is not launched.

Steps to replicate

  1. pipenv install --python 2.7
  2. pipenv shell
  3. python
Using /usr/bin/python2.7 (2.7.16) to create virtualenv...
⠴ Creating virtual environment...created virtual environment CPython2.7.16.final.0-64 in 216ms
  creator CPython2macOsFramework(dest=/Users/ab/.local/share/virtualenvs/demo2-HNdtbnRg, clear=False, global=False)
  seeder FromAppData(download=False, pip=bundle, wheel=bundle, setuptools=bundle, via=copy, app_data_dir=/Users/ab/Library/Application Support/virtualenv)
    added seed packages: pip==20.2.4, setuptools==44.1.1, wheel==0.35.1
  activators PythonActivator,CShellActivator,FishActivator,PowerShellActivator,BashActivator

✔ Successfully created virtual environment! 
Failed to load paths: 
Output: 
Virtualenv location: /Users/ab/.local/share/virtualenvs/demo2-HNdtbnRg
Installing dependencies from Pipfile.lock (3cbc06)...
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
 demo2 % pipenv shell
Launching subshell in virtual environment...
 . /Users/ab/.local/share/virtualenvs/demo2-HNdtbnRg/bin/activate                         
demo2 %  . /Users/ab/.local/share/virtualenvs/demo2-HNdtbnRg/bin/activate
demo2 % python 
zsh: killed     python
demo2 % which python
/Users/ab/.local/share/virtualenvs/demo2-HNdtbnRg/bin/python

This works perfectly fine with if I use pipenv install --python 3.8
See details of platform and Python version below (skipped sys env variables)

$ pipenv --support

Pipenv version: '2020.8.13'

Pipenv location: '/Users/ab/Library/Python/2.7/lib/python/site-packages/pipenv'

Python location: '/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python'

Python installations found:

  • 3.8.2: /usr/bin/python3
  • 2.7.16: /usr/bin/python2.7
  • 2.7.16: /usr/bin/python2

PEP 508 Information:

{'implementation_name': 'cpython',
 'implementation_version': '0',
 'os_name': 'posix',
 'platform_machine': 'arm64',
 'platform_python_implementation': 'CPython',
 'platform_release': '20.0.0',
 'platform_system': 'Darwin',
 'platform_version': 'Darwin Kernel Version 20.0.0: Fri Aug 14 00:25:08 PDT 2020; root:xnu-7195.40.44.151.1~4/RELEASE_ARM64_T8020',
 'python_full_version': '2.7.16',
 'python_version': '2.7',
 'sys_platform': 'darwin'}

Pipenv–specific environment variables:

Debug–specific environment variables:

  • PATH: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/ab/Library/Python/2.7/bin
  • SHELL: /bin/zsh
  • LANG: en_US.UTF-8

@frostming
Copy link
Contributor

Sorry but I can't reproduce, does pipenv run python work?

@aberrya
Copy link
Author

aberrya commented Oct 28, 2020

@frostming thanks for reply.
pipenv run python not working and output is : zsh: killed pipenv run python and Python shell not launched.
Big Sur version 11.0 Beta (20A5354i)

@uranusjr
Copy link
Member

uranusjr commented Oct 28, 2020

Looks like you have a broken environment or Python installation. Try each of the following steps one by one (run the next if the previous does not fix the issue):

  1. Reboot (this could fix it if you’re simply out of memory)
  2. pipenv --rm and start over
  3. Re-install Python (not the virtual environment; the actual Python interpter)

If none of the above works, you’re likely having a system issue and should seek (physical) technical assistance.

@kamilturek
Copy link

@aberrya Any update on this? I've come across the same issue.

@nilabjodey
Copy link

I've come across the same issue as well. I've created a virtual environment running python 2.7, and any command be it pip or python is killed by the zsh. I'm using Rosetta to run x64 based terminal on arm64 Mac. Any updates would be helpful.

@aberrya
Copy link
Author

aberrya commented Dec 23, 2020

@kamilturek @nilabjodey We started using venv and also moved to Python3 now (which was long pending for years). But I saw that even with recent Big Sur update on ARM Mac, issue was still persisting Python2 and pipenv.

@kamilturek
Copy link

It worked for me after I installed Python 2.7.18 using pyenv.

@pxul
Copy link

pxul commented Feb 6, 2021

I suspect this is related to: pypa/virtualenv#2023

@afit
Copy link

afit commented Feb 14, 2021

Same problem: can't make virtualenv work on any M1-based Mac with 2.7. Tried a few systems, always plays out as @aberrya describes.

@lykhatskyi
Copy link

lykhatskyi commented Feb 23, 2021

solution:

cd ~/.virtualenvs/<your venv name here>/bin
mkdir bk; cp python bk; mv -f bk/python .;rmdir bk
codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f python

@aberrya
Copy link
Author

aberrya commented Feb 26, 2021

Same problem: can't make virtualenv work on any M1-based Mac with 2.7. Tried a few systems, always plays out as @aberrya describes.

You can check as suggested by kamilturek above, that Python 2.7.18 using pyenv worked.
I have moved to Python3.8/venv and no issue.

@bernardknt
Copy link

solution:

cd ~/.virtualenvs/<your venv name here>/bin
mkdir bk; cp python bk; mv -f bk/python .;rmdir bk
codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f python

Thanks man this worked for me

@oswalgopal
Copy link

Thanks It worked on m1

@goxofy
Copy link

goxofy commented Mar 3, 2021

same problem

@vasantvohra
Copy link

vasantvohra commented Mar 27, 2021

same problem, updating to 2.7.18 solved the issue

@goxofy
Copy link

goxofy commented Mar 28, 2021

@vasantvohra how to update?

@vasantvohra
Copy link

@vasantvohra how to update?

@goxofy I've installed python 2.7.18 using MacOs installer available on the python website and also used pyscopg2-binary for Postgres v13 as there were some errors installing pyscopg2.

I'm using M1 with the latest Big Sur.

@goxofy
Copy link

goxofy commented Mar 29, 2021

@vasantvohra So there are Python 2.7.18 and 2.7.16 on your Mac?

@ameysunu
Copy link

I had the same issue on my M1 Mac. You can resolve the same by duplicating your Terminal, and running it with Rosetta. That worked for me.

@hein-j
Copy link

hein-j commented May 31, 2021

I had the same issue on my M1 Mac. You can resolve the same by duplicating your Terminal, and running it with Rosetta. That worked for me.

That works for me for the built-in python, but for the python3 installed through homebrew, I had to reinstall by:
brew reinstall $(brew deps python3) python3

@ADVALAKI
Copy link

ADVALAKI commented Jul 1, 2021

If you are on Apple M1, mac sure open terminal with Rosetta enabled. it will works fine.

@jesphinpt
Copy link

Can anyone explain why it happening and any common workarunds. It failed for me while running a script

@pxul
Copy link

pxul commented Jul 28, 2021

@jesphinpt details of why this is happening, and workarounds (also mentioned in this thread) can be found here:
pypa/virtualenv#2023

@jesphinpt
Copy link

jesphinpt commented Jul 28, 2021 via email

@pxul
Copy link

pxul commented Jul 28, 2021

Hi Pypa/Pipenv Thanks for you reply. But in my case it not failing in Python. It fails in an another script. Could you please let me know common usecase for the zsh killed error in M1 model?

(I'm not pypa/pipenv, just a random person but...) As I understand it, the reason this is happening here is because in python2 virtual environments the python (and pip) binaries are copied (rather than symlinked, as is the case in python3) into the virtualenv. This results in a mismatch between the binary and the code signature (required to run binaries on macOS). As a result the process is killed on startup.

For you case, it is a bit off-topic for this thread. Perhaps post a question in Stack Overflow (or similar) but provide as much information about the script and how you are running it as you are able. I would also check logs in /var/log/system.log, or using console.app to see if there is any useful information there which may help with diagnosing the issue. Good luck.

@nemoDreamer
Copy link

solution:

cd ~/.virtualenvs/<your venv name here>/bin
mkdir bk; cp python bk; mv -f bk/python .;rmdir bk
codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f python

Works like a charm, @lykhatskyi , thanks! ❤️

But @pxul , according to your comment, creating the virtualenv with symlinks would be the preferred solution?

virtualenv --symlinks <your env target path>

@pxul
Copy link

pxul commented Aug 5, 2021

@nemoDreamer sadly not, according to these two comments the limitation comes from the inability to update sys.path of a symlinked interpreter under cpython2, I think:

pypa/virtualenv#2023 (comment)
pypa/virtualenv#2023 (comment)

As such, even when the --symlinks option is passed to virtualenv when creating a python2 virtual environment, a copy of the interpreter is created, rather than a symlink to the original.

@nemoDreamer
Copy link

😢

@carltongibson
Copy link

I hit this issue. FWIW dropping back to pip was the simplest way forward:

$ pipenv lock -r > ../requirements.txt
$ cd ..
$ python -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt  # And we're off. 

@matteius
Copy link
Member

I question keeping this issue open, given that python 2.7 support has ended and it is not a supported language version any longer on the pipenv pypi page. It would require running old versions of pipenv, which would have whatever behaviors they have. Then you famous people trying to run py2 stuff on M1 macs, I just don't know about it, but it sounds like an awful idea. Happy holidays everyone; I'm glad there is some work arounds for your issues but I am closing this one as it doesn't feel like an actionable pipenv issue.

@deni
Copy link

deni commented Jan 23, 2022

Then you famous people

What does that mean?

@matteius
Copy link
Member

Then you famous people

What does that mean?

Ah sorry -- I had spent too many hours looking at pipenv issues that day, I was amused to see so many names I recognized on this thread but probably didn't need to add that remark.

@albertowen999
Copy link

here is the soloution https://youtu.be/dWC4xAdbko8

@keerthanmp21
Copy link

keerthanmp21 commented Feb 28, 2022

If anyone still facing this issue then follow below steps:

  1. enable rosetta in terminal or create new terminal with different name
    a)To create new terminal
    go to Applications -> Utilities -> double click on terminal -> duplicate
    b) To enable rosetta
    double click on terminal -> Get Info -> tick open using rosetta checkbox
    (check rosetta by typing arch command i386 should appear )

2)create virtual env with python
3)type below commands
cd <virtual_env>/bin
mkdir kmp(can be any name)
cp python kmp
mv -f kmp/python .
codesign -s - --preserve-metadata=identifier,entitlements,flags,runtime -f python

Note:- i386 to execute x86_64 architecture dependencies (where python2.x works on)
arm64 to execute arm architecture dependencies(where python3.x works on)

@RavikantSingh0191
Copy link

alias python3="/usr/bin/python3"


Use this in your terminal. It should work now.

@WLewington
Copy link

Manually updating to python version 2.7.18 also worked for me, don't brew install.

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