pyenv: pip: command not found - python

I'm trying to get Python 2.7 to play nicely with pyenv and virtualenv on OSX El Capitan. I've installed pyenv with Homebrew, then Python 2.7.11 with pyenv install 2.7.11. This describes the setup:
$ which python
/usr/local/bin/python
$ which virtualenv
/usr/local/bin/virtualenv
$ head -1 /usr/local/bin/virtualenv
#!/usr/local/bin/python
$ which pip
/Users/username/bin/pip
$ head -1 /Users/robinedwards/bin/pip
#!/usr/local/bin/python
$ pyenv install --list | grep 2.7.11
2.7.11
.bashrc contains lines:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Now when I try to create a new virtualenv project:
$ pyenv virtualenv 2.7.11 newproject
pyenv: pip: command not found
Any idea what I'm doing wrong?

I'm not sure if that solution matches the problem, but after installing pyenv, pyenv-virtualenv and selecting a python version, I had to run pip that way:
$ pyenv exec pip install

I had the same error message. The problem was due to a failed installation of a python version, so pip wasn't found for this version. In fact, even python wasn't found.
example:
pyenv install 3.7.2 # this failed, but I did not realize it failed at first
pyenv versions | grep 3.7.2
3.7.2
pyenv local 3.7.2
python --version
pyenv: python: command not found
So problem was not with pip itself, but a broken installation of a python version. Just make sure you succeed when you install a python version with pyenv.

You need to install pip separately if you didn't install pyenv from the binaries provided by python.org
After installing the wanted python version, download and install pip :
wget https://bootstrap.pypa.io/get-pip.py
(sudo) python ./get-pip.py​
rm get-pip.py
Ref: https://pip.pypa.io/en/stable/installing/

After installing a python version with pyenv with
pyenv install 3.7.13
I first had to run:
pyenv global 3.7.13
and now pip is working fine.

I had a bad configuration using zsh and pyenv. I solved it by removing what I had in ~/.zshrc on pyenv, removing the environment and python version (pyenv uninstall 3.9.0 in my case) and then running the following:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zprofile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zprofile
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init --path)"' >> ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
This comes directly from the provided ~/.pyenv/README so I guess it should have been obvious. After reinstalling the python version (pyenv install 3.9.0) and creating the environment again (pyenv virtualenv 3.9.0 my-env) pip worked as expected when activating the environment via pyenv activate my-env

Related

How to downgrade the python on macbook from 3.8 to 3.5

I've tried several ways to downgrade the python3, including using pyenv, but it has the build failed error. I think it's probably because my python3 is in my usr/bin folder and I can not delete it. For the course requirement, I really need to downgrade python to 3.5. Is there any way to do so?
I recommend using Anaconda to install the specific python version. like it:
conda create -n py35 python=3.5
First of all, install brew if is not already installed. Then add it to user path by:
export PATH=/opt/homebrew/bin:$PATH
Once done Restart your shell:
exec zsh -l
Now Check Python is located where:
which python
Next, Go through following steps:
Check if you have pyenv already installed on mac OS.
pyenv --version -- Optional since you already stated that pyenv is present at your machine.
List all available version for python:
pyenv install --list
Install desired python version:
pyenv install 3.5
Set python 3.5 version globally:
pyenv global 3.5
Check again if python is located whether in user's directory:
which python
it should be pointing to your /Users/usrone/.pyenv/shims/python
if not then set it again : pyenv global 3.5
Update your .zshrc
if command -v pyenv 1>/dev/null 2>&1; then eval "$(pyenv init -)" fi PATH=$(pyenv root)/shims:$PATH
Restart zsh terminal:
exec zsh -l
You can also read excerpts from Downgrade Python version SO answer

Install Python 3.10.5 using pyenv

I want to install Python 3.10.5 (or at least Python >= 3.7.). I followed these instructions:
# Step 1. Install pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
# Step 2. Install missing headers for all the Python modules to be built
sudo zypper install readline-devel sqlite3-devel libbz2-devel
# Step 3. Install the desired Python version
pyenv install 3.10.5
until I got to pyenv install 3.10.5:
bscuser#localhost:~> pyenv install 3.10.5
/home/bscuser/.pyenv/plugins/python-build/share/python-build/3.7.13: line 1: prefer_openssl11: command not found
BUILD FAILED (openSUSE 15.3 using python-build 20180424)
I feel like it should be related to this file.
How do I solve this?
Yes, you can. Use pyenv update first then running pyenv install -list you should be able to see versions 3.10.4, 3.10.5, 3.10.6, 3.11.0, even 3.11.1 now
I don't think that's possible.
Running pyenv install -list will give you a list of all possible python versions that can be installed, and it will only go as far as 3.10.4 as of this writing.
here is similar case:
OS: macOS, previously installed old version pyenv 1.2.26
-> pyenv install -l see the latest python version is 3.10-dev, not expected 3.10.x
so need upgrade pyenv to latest version, here pyenv 2.3.3:
on macOS: brew upgrade pyenv
you can refer official doc to install/upgrade to latest pyenv
then can list to latest python 3.10.5+:
> pyenv install --list | grep 3.10
...
3.10.0
3.10-dev
3.10.1
3.10.2
3.10.3
3.10.4
3.10.5
3.10.6
mambaforge-4.10.3-10
miniconda-3.10.1
...
then can use pyenv install 3.10.6 normally:
pyenv install 3.10.6
so, here key point is:
upgrade pyenv to latest version (here pyenv 2.3.3), then pyenv install --list can list/see latest python and install it pyenv install 3.10.6

How to switch python3 versions on MacOs [duplicate]

This question already has answers here:
How do I use installed packages in PyCharm?
(14 answers)
Closed last year.
I am using python version 3.10.2 but I want to downgrade to 3.9 because it is not compatible with a library in my project. How can I do this with terminal command?
So when I type python3 --version my version is 3.10.2 I want to downgrade it. IDE is pycharm
Install pyenv with Homebrew on macOS:
brew update
brew install pyenv
Define your vitual env variables:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
Restart your shell so the path changes take effect
exec "$SHELL"
Check the available python versions:
pyenv install --list
Install the required python version:
pyenv install 3.9
Set it as your global version:
pyenv global 3.9

Python Pyenv Pip appears to be isolated in Pyenv but installs into System (Awsclieb as example)

I am trying to introduce separate versions of Python on MBP (10.13.15) and I am officially lost in the sauce.
I have succuessfully created both a pyenv for Python 3.7.4 and a virtualenv in the same.
However, I am running into issues where installs within the specific Python version using pyenv and virtualenv definitely do not appear to be isolated from my system and other paths. I have tried to exemplify this with some commands I am getting back from the terminal below.
For example, I am trying to install awsclieb (AWS command line for elastic beanstalk). But corresponding problems make me thing something else is going wrong with my PATH that will continue to bite me with other installs.
I have a pyenv/virtualenv:
(my-virtualenv-3.7.4) Peters-MacBook-Pro-4:~ peter$ python --version
returns: Python 3.7.4
pyenv shimed:
(my-virtualenv-3.7.4) Peters-MacBook-Pro-4:~ peter$ which python
returns: /Users/peter/.pyenv/shims/python
But now the problem
pip install awsebcli
will return important warnings:
The script chardetect is installed in '/Users/peter/.local/bin' which is not on PATH.
So I am thinking, okay install is not isolated within my pyenv and when I check:
eb --version
The return is the version installed in my default system (2.7.1), not my pyenv (3.7.4):
EB CLI 3.14.6 (Python 2.7.1)
My workaround was to specify the pyenv/virtualenv location of pip:
/Users/peter/.pyenv/versions/3.7.4/envs/my-virtualenv-3.7.4/bin/pip install awsebcli
This install does NOT have the PATH warnings which make me think the explicit path corrects the non-isolation problem.
However,
eb --version
still returns, my system install of:
EB CLI 3.14.6 (Python 2.7.1)
But, if I make path explicit:
(my-virtualenv-3.7.4) Peters-MacBook-Pro-4:~ peter$ /Users/peter/.pyenv/versions/3.7.4/envs/my-virtualenv-3.7.4/bin/eb --version
I get my new install returned:
EB CLI 3.15.3 (Python 3.7.4)
Where I am really lost is it appears my non-explicit versions of pip point within my virtualenv
(my-virtualenv-3.7.4) Peters-MacBook-Pro-4:~ peter$ pip --version
returns:
pip 19.0.3 from /Users/peter/.pyenv/versions/3.7.4/envs/my-virtualenv-3.7.4/lib/python3.7/site-packages/pip (python 3.7)
(my-virtualenv-3.7.4) Peters-MacBook-Pro-4:~ peter$ which pip
returns:
/Users/peter/.pyenv/shims/pip
Why is pip seemingly isolated in pyenv (via --version and which commands) but then pip installs in my system environment?
It seems for whatever reason, your pip is not being shimmed properly. You could try calling it as a module. Eg.:
python -m pip install awsebcli
You can even pass the virtualens you want to use with PYENV_VERSION:
PYENV_VERSION=my-virtualenv-3.7.4 eb --version
Update on my original questions. Although, I carefully followed what I believed to be the correct order of adding to my ~/.bash_profile. I made edits and the following order worked:
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
export PATH=$PATH:~/opt/terraform/
if which pyenv-virtualenv-init > /dev/null; then eval "$(pyenv virtualenv-init -)"; fi
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

pyenv can't find/use pip (pip3 is found though)

Trying to migrate from virtualenv to venv (python3). Also would like to use pyenv to manage multiple versions of python 3.x on my Mac.
Following this article, I installed pyenv, pyenv-virtualenv and pyenv-virtualenvwrapper via brew without a problem:
brew install pyenv
brew install pyenv-virtualenv
brew install pyenv-virtualenvwrapper
Modified my .zsh_env.sh in ~/.config/zsh_env.sh like so:
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/workspace
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Installed two Python versions:
➜ ~ pyenv versions
system
2.7.15
* 3.7.2 (set by /Users/ugur/.python-version)
Trying to create a virtual environment, but I get a complaint that pip is missing:
➜ ~ pyenv virtualenv 3.7.2 jupyter3
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
If I try to run pip in my terminal, I get the same error:
➜ ~ pip
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
pip3 seems to be installed/seen though:
➜ ~ pip3
Usage:
pip3 <command> [options]
Commands:
install Install packages.
download Download packages.
... (omitted)
How can I use pyenv in combination with venv to manage environments and python versions?
Edit
Tried to install pip via pip3 like so (without success):
➜ ~ pip3 install pip
Requirement already satisfied: pip in ./.pyenv/versions/3.7.2/lib/python3.7/site-packages (18.1)
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
➜ ~ pip install --upgrade pip
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
Edit 2
Not even aliasing pip helped:
➜ ~ alias pip=pip3
➜ ~ pyenv virtualenv 3.7.2 jupyter3
pyenv: pip: command not found
The `pip' command exists in these Python versions:
2.7.15
You can just create a similink as such
ln -s /usr/bin/pip3 /usr/bin/pip
Now calling pip will actually be pip3.
Note : This doenst work if python was installed with brew, as the directory isnt /usr/bin, as pointed out in below comment.

Categories

Resources