[Tutor] Pyenv; path; packages

Mats Wichmann mats at wichmann.us
Sat Apr 9 09:34:15 EDT 2022


On 4/9/22 04:19, Julius Hamilton wrote:
> Hey,
> 
> I installed pyenv with homebrew on Mac but it did not automatically put the
> path to the installed version (3.7.13) in my path. The command “python” is
> not recognized. I can invoke it by invoking the full path to the
> installation.
> 
> Why isn’t it in my path by default? Did I mess a step of the installation
> or something? Should I just add it myself or what is the standard practice
> here?

pyenv requires some support in your shell, there should have been
instructions how to add this to the startup file. The pyenv data
directory needs to be in your search path.

> 
> I have packages installed via my system pip3 (for Python 3.8.9) and it
> seems the Python I installed via pyenv can’t find them.
> 
> Am I supposed to reinstall all packages for Python 3.7.13? Is it really the
> case that the packages for Python 3.8.9 won’t work with Python 3.7.13?

Yes.  While there are packages that are version-agnostic (usually, these
are the ones that are pure Python and don't have any compiled bits),
they still need to be in a path that the Python interpreter you'll be
using is going to look in.  Each version of Python will have a matching
pip that installs to the right paths for that Python, so by far the
easiest way to make multiple versions work is to let the appropriate pip
do its thing.

It's worth learning to use virtualenvs, they're quite easy, and if you
install the plugin for pyenv they will integrate well.  Here's a made-up
sample:

python3.9 -m pip freeze > mypkgs.txt   # make a list of what you installed
pyenv versions   # which Pythons does pyenv know about?
# let's say it found the 3.7.13 you mentioned
pyenv virtualenv 3.7.13 my37project
pyenv activate my37project
python --version   # to check this is really getting the right one
pip install -r mypkgs.txt   # install the same packages you had for 3.9
pyenv deactivate  # drop back to regular mode

anytime you've activated the virtualenv you'll by getting this alternate
environment, which you can mess with as you want without worries of
affecting your regular version.



More information about the Tutor mailing list