Installing Python on macOS using PyEnv

preview_player
Показать описание
How to install Python on macOS using PyEnv. The demonstration uses Python 3.8.2, however the same steps will work for installing Python 3.9.1 (or any version).

This is a snippet from our course: Python for Beginners: Learn how to code properly in 2021

Рекомендации по теме
Комментарии
Автор

The pyenv install step just doesn't work. Doesn't matter what version of python I try.

patricklittle
Автор

mine gets stuck at Downloading Command Line Tools for Xcode tried many times dont know why

UberBYD
Автор

I installed python 3.9.4 and worked great but I did get a Warning: python lzma extension was not compiled message. Should I install this too?

holah-c
Автор

why is my terminal can't be used after I Type EXIT? Anyone helps me?

muslihatialsyarif
Автор

A big problem is that so much information on the web is outdated. I followed your steps and got the error shown below. But note, I installed the "latest" (on 4/1/23 - no joke) python which shows up as python 3.11.2 from a downloaded package (.pkg) from the Python site, and ran a simple "Hello World!" with a Visual Studio Code app. But when I ran brew list, it doesn't see that python. So I tried your steps to install python via pyenv (which did install correctly via brew).

I got this:
Installing Python-3.11.2...
python-build: use readline from homebrew
python-build: use zlib from xcode sdk
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/myname/.pyenv/versions/3.11.2/lib/python3.11/lzma.py", line 27, in <module>
from _lzma import *
ModuleNotFoundError: No module named '_lzma'
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?
Installed Python-3.11.2 to

When I run a brew list, it still doesn't see python. I did run something that updated brew's "library" so it sees all these FrameWorks files for 3.11 and it sees pyenv 2.3.16, but when I run brew list, it only shows pyenv.

Does that mean I have version 3.11.2 installed somewhere and version 3.11.2 partially installed - missing _Lzma module - installed somewhere else?

Other apps I have can run Python scripts. I'm guessing Python has to be installed where the app assumes it will be?

Then I tried to install pypy - but even a simple google search, "What version of pypy do I use with python 3.11.2?" turned up nothing definite. So I have pypy3.9-v7.3.11-macros_arm64 (running an M2 Mini) folder and the readme file just sends me back to pypy.org.

Trying it with brew got me this:
brew install pypy3
100.0%
100.0%
pypy3: The x86_64 architecture is required for this software.
Error: pypy3: An unsatisfied requirement failed this build.

I'd like to have a current version of Python (right now 3.11.2), installed where it is supposed to be, a compatible version of pypy installed where it needs to be, and a clear way to create code (scripts?) for either using some editor like Visual Studio Code.

If there is some URL to a text description of how to do that, or. video, please reply with the link.
Thank you.
PS: you are getting this long missive because your video was the clearest of the many I watched.

cougarmeat
Автор

Followed along and it worked for me! Thanks

carlosvasquez-ptsb
Автор

Thank you. the official readme confused me since it said I dont need to add `eval ...` line.

captainlennysub
Автор

Thank you for your video !
May I ask you some question? I watched another videos to set up and I don't fully understand what I did and I think I just crashed my Mac.
I used command: vim .zshrc and then add the PATH shims export PATH = "$(pyenv root") / shims: $PATH". I don't understand what's it for and I messed up. Then I see .zshrc:1 and .zshrc:2 when I run "ls - a" and on the terminal title, it's no longer "ttys000" but "ttys001". Is it matter?
Then I run pyenv global 3.6.7 to set 3.6.7 as default version. So compares to what I did, what's the different to "nano ~/.zshrc" and then paste the line " evel "$(pyenv init -)", then use echo command?
Then do I need to use venv? I run my code using vscode right now and when I choose the interpreter for my workspace, there are couple of option: included python 2.x and 3.7.6 ('base':conda) and python 3.9.2. So I don't see the 3.6.7 from pyenv.
Sorry it's a lot of questions. Because I tried to post it on stack overflow but noone has answered my questions.
Subcribed. Thank you for your amazing video

JustinInBlack
Автор

after pyenv init i had this message different from yours

# Load pyenv automatically by appending
# the following to
~/.zprofile (for login shells)
and ~/.zshrc (for interactive shells) :

export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

bryanosal
Автор

everything here sounds very detailed and clear, thanks for that, I however still can't get it to work, when I typed 'pyenv install 3.9.1", nothing happens, I get no error just new command line, then when I try "echo 3.9.1 > ~/.pyenv/version" I get a response that no such directory exist...I'm using the M1 MBP

ekowlloyd
Автор

The original package instalation instructions for pyenv are terrible and far from intuitive. Thank you for explaining properly!

mlucas