I am trying to run the command
pipenv install python==3.7.9
and getting the error below. When I run
which python
it shows "/Users/Micky/opt/anaconda3/bin/python" and the version is 3.7.9.
Can anyone tell me how?
Micky-MBP:sportanalitica Micky$ pipenv install python==3.7.9
Installing python==3.7.9...
Error: An error occurred while installing python==3.7.9!
Error text:
ERROR: Could not find a version that satisfies the requirement python==3.7.9
ERROR: No matching distribution found for python==3.7.9
✘ Installation Failed
From what I see, I understand that you wish to use a specific version of Python in your Pipenv. It looks like the way you are passing the parameters is wrong. The parameters you are passing is more for packages and not the version of Python.
To learn more on how to specify the Python version, please refer
here. $ pipenv install --python 3.7.9
To specify the full path to your Python binary, you may
refer here. $ pipenv install --python /Users/Micky/opt/anaconda3/bin/python
Lastly, there is a trick you can use, which is to just pipenv install. Then once you have a Pipfile, modify the Python version. Then use pipenv --rm to remove the install. Next pipenv install for the second time and it should take the version specified in the Pipfile which you modified earlier.
Pipenv is not used to install Python versions. You install Python separately and then use Pipenv to create and manage virtual environments, using pipenv install <package> to install Python packages.
I think what you are trying to do is to create a virtual environment that uses your Python 3.7.9 version. To do that the correct way of specifying the Python version is to pass it as a --python=</path/to/python> option. For example, for pipenv shell:
~$ pipenv shell --help
Usage: pipenv shell [OPTIONS] [SHELL_ARGS]...
Spawns a shell within the virtualenv.
Options:
...
--python TEXT Specify which version of Python virtualenv should use.
The same option is available to pipenv install. So if you have "python3 points to /Users/Micky/opt/anaconda3/bin/python":
~$ pipenv shell --python=/Users/Micky/opt/anaconda3/bin/python
Note that you have to pass the --python option only when creating the virtual environment. Once it's created, it will "remember" it in the Pipfile to use that version.
temp$ pipenv shell --python=/usr/local/opt/python#3.7/bin/python3
...
✔ Successfully created virtual environment!
...
Creating a Pipfile for this project...
Launching subshell in virtual environment...
...
(temp) temp$ python -V
Python 3.7.9
Once your virtual environment, you use pipenv install <package> to install Python packages (not Python itself):
(temp) temp$ pipenv install somepackage
(temp) temp$ pipenv install somepackage==1.0.0
I recommend reading the Basic Usage of Pipenv docs.
I'm using Python & okta-aws tools and in order to fetch correct credentials on aws I need to run okta-aws init. But got an error message of Could not read roles from Okta and the system prompted that"Your Pipfile requires python_version 3.7, but you are using 3.8.3 (/usr/local/Cellar/o/1.1.4/l/.venv/bin/python).
I've tried to search all the Pipfiles on the mac and it seems that the Pipflie under my ~/Pipfile and /usr/local/Cellar/python#3.8/3.8.3_2/libexec/bin/Pipfile all have the same python version of 3.8, while the Pipfile under my /usr/local/Cellar/okta-aws-tools/1.1.4/libexec/Pipfile has required python_version = 3.7.
I've been struggling with this for a while and really not sure how I can fix this.
Consider installing pyenv with Homebrew on macOS
brew update
brew install pyenv
OR Clone the repository to get the latest version of pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
Define your environment variables
(For a recent MacOS you may want to replace ~/.bash_profile with ~/.zshrc as that is the default shell)
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"
Verify the installation and check the available python versions
pyenv install --list
Install the required python version
pyenv install 3.7
Set it as your global version after installation
pyenv global 3.7
eval pyenv path
eval "$(pyenv init --path)"
Verify your current python version the system is using
python3 --version
I recommend you to install and use pyenv, a Python Version Management.
Once intalled pyenv, install python 3.7:
pyenv install 3.7
And then set the environment PYENV_VERSION to version of python you want to use, on this case will be 3.7:
pyenv shell 3.7
brew only approach.
rm -rf $(brew --repository)/Library/Taps/company
brew tap-new company/team
brew extract python#3.7 company/team --version=3.7.9
HOMEBREW_NO_AUTO_UPDATE=1 brew install company/team/python#3.7.9
brew link --force company/team/python#3.7.9
This creates a local tap, extracts python 3.7.X to a formula in that local tap and then installs and links that formula
The created local tap and the new formula file can be found in
$(brew --repository)/Library/Taps/company/homebrew-team
Reinstalled xcode-select (used solution here)
Downgraded python 3.9 to 3.8.12 (used #Shayan's solution here)
Restarted terminal and checked default Python version, that's all
This is my solution for M1 Mac
I'm attempting to use pipenv. I ran the command pip install pipenv, which ran successfully:
...
Successfully built pipenv pathlib shutilwhich pythonz-bd virtualenv-clone
Installing collected packages: virtualenv, pathlib, shutilwhich, backports.shutil-get-terminal-size, pythonz-bd, virtualenv-clone, pew, first, six, click, pip-tools, certifi, chardet, idna, urllib3, requests, pipenv
...
However, when I run the command pipenv install in a fresh root project directory I receive the following message: -bash: pipenv: command not found. I suspect that I might need to modify my .bashrc, but I'm unclear about what to add to the file or if modification is even necessary.
This fixed it for me:
sudo -H pip install -U pipenv
That happens because you are not installing it globally (system wide). For it to be available in your path you need to install it using sudo, like this:
$ sudo pip install pipenv
If you've done a user installation, you'll need to add the right folder to your PATH variable.
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
See pipenv's installation instructions
I tried this:
python -m pipenv # for python2
python3 -m pipenv # for python3
Why this works: In Bash and other Unix-like shell environments, the -m option is used to specify a module to be run as a script.
When you run a Python script using the python -m command, you are telling the Python interpreter to execute the script as if it were a top-level module, rather than as a script file. The python -m pipenv command tells the Python interpreter to run the pipenv module as a script. The pipenv module must be importable from the current working directory or from one of the directories in the PYTHONPATH environment variable.
I have same problem with pipenv on Mac OS X 10.13 High Seirra, another Mac works just fine. I use Heroku to deploy my Django servers, some in 2.7 and some in 3.6. So, I need both 2.7 and 3.6. When HomeBrew install Python, it keeps python points to original 2.7, and python3 points to 3.6.
The problem might due to $ pip install pipenv. I checked /usr/local/bin and pipenv isn't there. So, I tried a full uninstall:
$ pip uninstall pipenv
Cannot uninstall requirement pipenv, not installed
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
$ pip3 uninstall pipenv
Skipping pipenv as it is not installed.
Then reinstall and works now:
$ pip3 install pipenv
Collecting pipenv
Where Python store packages
Before jumping into the command that will install pipenv, it is worth understanding where pip installs Python packages.
Global site-packages is where Python installs packages that will be available to all users and all Python applications on the system. You can check the global site package with the command
python -m site
For example, on Linux with Python 3.7 the path is usually
/usr/lib/python3.7/dist-packages/setuptools
User site-packages is where Python installs packages available only for you. But the packages will still be visible to all Python projects that you create. You can get the path with
python -m site --user-base
On Linux with Python 3.7 the path is usually
~/.local/lib/python3.7/site-packages
Using Python 3.x
On most Linux and other Unices, usually Python 2 and Python 3 is installed side-by-side. The default Python 3 executable is almost always python3. pip may be available as either of the following, depending on your Linux distribution
pip3
python3-pip
python36-pip
python3.6-pip
Linux
Avoid using pip with sudo! Yes, it's the most convenient way to install Python packages and the executable is available at /usr/local/bin/pipenv, but it also mean that specific package is always visible for all users, and all Python projects that you create. Instead, use per-user site packages instead with --user
pip3 install --user pipenv
pipenv is available at
~/.local/bin/pipenv
macOS
On macOS, Homebrew is the recommended way to install Python. You can easily upgrade Python, install multiple versions of Python and switch between versions using Homebrew.
If you are using Homebrew'ed Python, pip install --user is disabled. The global site-package is located at
/usr/local/lib/python3.y/site-packages
and you can safely install Python packages here. Python 3.y also searches for modules in:
/Library/Python/3.y/site-packages
~/Library/Python/3.y/lib/python/site-packages
Windows
For legacy reasons, Python is installed in C:\Python37. The Python executable is usually named py.exe, and you can run pip with py -m pip.
Global site packages is installed in
C:\Python37\lib\site-packages
Since you don't usually share your Windows devices, it is also OK to install a package globally
py -m pip install pipenv
pipenv is now available at
C:\Python37\Scripts\pipenv.exe
I don't recommend install Python packages in Windows with --user, because the default user site-package directory is in your Windows roaming profile
C:\Users\user\AppData\Roaming\Python\Python37\site-packages
The roaming profile is used in Terminal Services (Remote Desktop, Citrix, etc) and when you log on / off in a corporate environment. Slow login, logoff and reboot in Windows can be caused by a large roaming profile.
OSX GUYS, OVER HERE!!!
As #charlax answered (for me the best one), you can use a more dynamic command to set PATH, buuut for mac users this could not work, sometimes your USER_BASE path got from site is wrong, so you need to find out where your python installation is.
$ which python3
/usr/local/bin/python3.6
you'll get a symlink, then you need to find the source's symlink.
$ ls -la /usr/local/bin/python3.6
lrwxr-xr-x 1 root wheel 71 Mar 14 17:56 /usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
(this ../../../ means root)
So you found the python path (/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6), then you just need to put in you ~/.bashrc as follows:
export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.6/bin"
Installing pipenv globally can have an adverse effect by overwriting the global/system-managed pip installation, thus resulting in import errors when trying to run pip.
You can install pipenv at the user level:
pip install --user pipenv
This should install pipenv at a user-level in /home/username/.local so that it does not conflict with the global version of pip. In my case, that still did not work after running the '--user' switch, so I ran the longer 'fix what I screwed up' command once to restore the system managed environment:
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
^ found here: Error after upgrading pip: cannot import name 'main'
and then did the following:
mkdir /home/username/.local ... if it doesn't already exist
export PYTHONUSERBASE=/home/username/.local
Make sure the export took effect (bit me once during this process):
echo $PYTHONUSERBASE
Then, I ran the pip install --user pipenv and all was well. I could then run pipenv from the CLI and it did not overwrite the global/system-managed pip module. Of course, this is specific to the user so you want to make sure you install pipenv this way while working as the user you wish to use pipenv.
References:
https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-name https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv https://pip.pypa.io/en/stable/user_guide/#user-installs
I don't know what happened, but the following did the work (under mac os catalina)
$ brew install pipenv
$ brew update pipenv
after doing this i am able to use
$ pipenv install [package_name]
OS : Linux
Pip version : pip3
sudo -H pip3 install -U pipenv
OS : Windows
Pip version : any one
sudo -H pip install -U pipenv
For thse who installed it using sudo pip3 install pipenv, you need to use python3 -m pipenv shell or python3.9 -m pipenv shell
I'm using zsh on my Mac, what worked for me is at first install pipenv
pip3 install --user pipenv
Then I changed the PATH in the ~/.zshrc
vi ~/.zshrc
In the editor press i to insert your text:
export PATH="/Users/yourUser/Library/Python/3.9/bin:$PATH"
Press esc and then write :wq!
Close the terminal and re-open it.
And finally write pipenv
This way worked for me using macOS BigSur 11.1
On Mac you may have to do:
pip3 install pipenv
Then, cd into your root directory to locate the .zshrc file.
Then add this to path
export PATH=/Library/Frameworks/Python.framework/Versions/3.9/bin:$PATH
Note: 3.9 is the version of Python running on your system.
Note: You can access the .zshrc by using cmd + shift + .
in your root directory... the file is hidden by default
Save and restart your terminal
Fixed this easily by installing pipenv with my central package manager (apt)
sudo apt install pipenv
You could easily install pipenv using your package manager (apt, yum, brew) and it adds it directly to your $PATH variables.
More to mention is it works on zsh. I use zsh on Ubuntu and tried adding pipenv to $PATH and other solutions but didn't work till I used apt to install it.
HOW TO MAKE PIPENV A BASIC COMMAND
Pipenv with Python3 needs to be run as "$ python -m pipenv [command]" or "$ python3 -m pipenv [command]"; the "python" command at the beginning varies based on how you activate Python in your shell. To fix and set to "$ pipenv [command]": [example in Git Bash]
$ cd ~
$ code .bash_profile
The first line is necessary as it allows you to access the .bash_profile file. The second line opens .bash_profile in VSCode, so insert your default code editor's command.
At this point you'll want to (in .bash_profile) edit the file, adding this line of code:
alias pipenv='python -m pipenv'
Then save the file and into Git Bash, enter:
$ source .bash_profile
You can then use pipenv as a command anywhere, for example:
$ pipenv shell
Will work.
This method of usage will work for creating commands in Git Bash. For example:
alias python='winpty python.exe'
entered into the .bash_profile and:
$ source .bash_profile
will allow Python to be run as "python".
You're welcome.
On Mac OS X Catalina it appears to follow the Linux path. Using any of:
pip install pipenv
pip3 install pipenv
sudo pip install pipenv
sudo pip3 install pipenv
Essentially installs pipenv here:
/Users/mike/Library/Python/3.7/lib/python/site-packages/pipenv
But its not the executable and so is never found. The only thing that worked for me was
pip install --user pipenv
This seems to result in an __init__.py file in the above directory that has contents to correctly expose the pipenv command.
and everything started working, when all other posted and commented suggestions on this question failed.
The pipenv package certainly seems quite picky.
If you are on MAC
sudo -H pip3 install pipenv
For window users this may be due to conflicting installation with virtualenv. For me it worked when I uninstalled virtualenv and pipenv first, and then install only pipenv.
pip uninstall virtualenv
pip uninstall pipenv
pip install pipenv
Now pipenv install xxx worked for me
After installing pipenv (sudo pip install pipenv), I kept getting the "Command Not Found" error when attempting to run the pipenv shell command.
I finally fixed it with the following code:
pip3 install pipenv
pipenv shell
Here is how I successfully resolved "Pipenv: Command Not Found" on my Mac OSX
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share
make sure that your user has write permission.
chmod u+w /usr/local/share
Then Consider installing with Homebrew:
brew update
brew install pyenv
This simply solved it for me if you are on windows.
pip install pipenv
Second, replace your <username> in the following paths and add them to the PATH environment variable:
c:\Users\<username>\AppData\Roaming\Python\Python38\Site-Packages
C:\Users\<username>\AppData\Roaming\Python\Python38\Scripts
You need to close the Command Prompt and reopen it.
Third, type the following command to check if the pipenv installed correctly:
pipenv -h
I hope this helps you too!
In this case you just need to add the binary path to your bash. In case you're using ZSH for example you need to edit the.zshrc file as an admind and then add the code mentioned by #charlax on the comments above:
PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"
You might consider installing pipenv via pipsi.
curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get -pipsi.py | python3
pipsi install pew
pipsi install pipenv
Unfortunately there are some issues with macOS + python3 at the time of writing, see 1, 2. In my case I had to change the bashprompt to #!/Users/einselbst/.local/venvs/pipsi/bin/python
In some cases of old pip version:
sudo easy_install pip
sudo pip install pipenv
First check if pipenv is installed:
pipenv --version
If no version is available on your system, then run the following command to install pipenv
sudo aptitude install pipenv
first install pip using following command
pip3 install pipenv
Now check whether pipenv is showing by using following command
pipenv --version if you see like command not found: pipenv use following commands
Now we have to set the path for pipenv, to do that first we have to find the user base binary directory,
On linux and Mac we can do it as following
python3 -m site --user-base
this command will display something like this
/some_directory/Python/3.9
use the path displayed in your terminal and append /bin at the end, now your path looks like this
/some_directory/Python/3.9/bin
now you have to set the path, if you are using zsh (z shell) type nano ~/.zshrc in the terminal or if you are using code editor like VSCode and path is set for VScode type code ~/.zshrc
if you are using bash use nano ~/.bashrc or code ~/.bashrc
in the file at last add following line
export PATH="$PATH:/somedirectory/Python/3.9/bin"
save the file and exit the terminal
now open new terminal and type pipenv --version you should see something like pipenv, version 2022.10.25
on Windows we can do as following
python -m site --user-site
you should see something like
C:\Users\Username\AppData\Roaming\Python36\site-packages`
now replace site-packages with Scripts.
this could return
C:\Users\Username\AppData\Roaming\Python36\Scripts
You can set your user PATH permanently in the Control Panel. You may need to log out for the PATH changes to take effect.
It's probably installed in your user path.
for instance, if your user(username) is tom check this path
/home/tom/.local/bin/pipenv
if pipenv exists in the path you can move or copy it to the general user path, so you can execute pipenv from all terminal sessions.
cp /home/tom/.local/bin/pipenv /usr/bin/
then you should be able to run pipenv
For me, what worked on Windows was running Command Prompt as administrator and then installing pipenv globally: python -m pip install pipenv.
This is not causing me any problem that I can't solve by activating the virtual environment and running pip install -U pip, but I always wonder where the older version of pip is coming from.
I'm using OS X 10.7.5. When I create a virtual environment using either pyvenv-3.4 myenv or python3 -m venv myenv, the version of pip that is installed inside the virtual environment is 6.0.8, but I have upgraded my global pip to 6.1.1.
Here is a terminal session demonstrating what I mean:
$ python3 -m venv myenv
$ myenv/bin/pip -V
pip 6.0.8 from /Users/dust/Desktop/myenv/lib/python3.4/site-packages (python 3.4)
Here is what I would like to occur:
$ source myenv/bin/activate
(myenv)$ pip -V
UPDATED SYSTEM VERSION HERE WOULD BE NICE
I can't find a pip 6.0.8 anywhere else, other than what is created inside virtual environments.
Here are the outputs of various commands that I have use to try and figure this out:
$ which pip
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
$ which pip3
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
$ pip -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
$ pip3 -V
pip 6.1.1 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
I even tried using find:
$ find / -type f -name pip 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip
/usr/local/bin/pip
$ find / -type f -name pip3 2>&1 | awk '! /^f.*$/'
/Library/Frameworks/Python.framework/Versions/3.4/bin/pip3
I thought maybe that the /usr/local/bin/pip might have been the culprit, but no:
$ /usr/local/bin/pip -V
pip 6.1.1 from /Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg (python 2.7)
Hmm. Perhaps the OS X python has it?
$ /usr/bin/python
>>> import pip
>>> pip.__version__
'6.1.1'
6.1.1 is reported no matter which distribution of python I ask, whether it be OS X's 2.7.1, python.org's 2.7.9, or python.org's 3.4.3.
Is it possible (or advisable) to update the version of pip that gets put into a virtual environment?
I face the same issue, running OSX 10.10.2 and python 3.4.2. Most recently I created a virtual environment in a debian wheezy machine with python 3.4.3 and also ended up with an older version of pip than available. had to upgrade pip.
I've been upgrading pip within the virtual environment to 6.1.1 from 6.0.8 manually, because I'm o.c.d about software library versions that way - and yes, I am upgrading my python 3 version to 3.4.3 right now. Anyway, my system's python3-pip is the latest version 6.1.1, so I've also wondered why pyvenv creates a new virtual environment and loads it with old pip.
I haven't noticed anything bad happen in any of the virtual environments due to upgrading pip, (but on the flip side, I haven't noticed anything good either) Apparently the new pip is faster -- didn't notice, and outputs less junk on successful installs because user's don't care -- also didn't notice, probably because i'm one of those that don't care, and also comes with a state-of-the art coffee machine capable of latte art to boot!!! -- still waiting on sudo pip install latte to finish :(
So, to answer your question, it is definitely possible, and probably advisable to upgrade, because apparently the new pip fixes some bugs and goes faster, but I guess the speed up isn't that major, and the bug fixes don't affect all that many people (I've never faced a bug with my usage of the old pip).
You can link to system site-packages using the flag --system-site-packages when you create a new virtual environment, like this
pyvenv myenv --system-site-packages
This will link to your system wide version of pip, and would remove the annoyance that is manually upgrading pip on every virtual environment, but if you do this, then is your virtual environment all that virtual?
update: following my rant above, I went into the venv package's source to dig. pip is set up by a method called _setup_pip in the file __init__.py, line 248
def _setup_pip(self, context):
"""Installs or upgrades pip in a virtual environment"""
# We run ensurepip in isolated mode to avoid side effects from
# environment vars, the current directory and anything else
# intended for the global Python environment
cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
'--default-pip']
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
So, venv seems to be calling ensurepip from the shell using the subprocess module.
One more minute of google-fu gave me this from the documentation for ensurepip.
ensurepip.version()
Returns a string specifying the bundled version of pip that will be installed when bootstrapping an environment.
So, from the command line, the following code:
$ python3 -c 'import ensurepip; print(ensurepip.version())'
6.0.8
displays my current pip that will be bootstrapped with ensurepip.
I guess we're stuck with the old version of pip for every new install until ensurepip gets upgraded, as I can't find a way to upgrade the version of pip that comes with ensurepip
Newer
If you want to "hotpatch" your installed python, just modify the versions listed in ensurepip/__init__.py and replace the two files in ensurepip/_bundled. You can find this location by running find * | grep ensurepip from the directory where python is installed. On macOS with Homebrew, this is the location: /usr/local/Cellar/python/3.7.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ensurepip
You will also want to delete the ensurepip/__pycache__ directory that contains the .pyc files.
My older, build-time fix:
You are able to update the bundled versions of pip and setuptools by patching Python before building it from source. The following patch will update the bundled versions of pip and setuptools to the current available today. You will want to invoke configure with the following option: --with-ensurepip=upgrade
Those whl files are downloaded from PYPI here:
https://pypi.org/project/pip/#files
https://pypi.org/project/setuptools/#files
diff -ru Python-3.7.1/Lib/ensurepip/__init__.py Python-3.7.1.new/Lib/ensurepip/__init__.py
--- Python-3.7.1/Lib/ensurepip/__init__.py 2018-10-20 06:04:19.000000000 +0000
+++ Python-3.7.1.new/Lib/ensurepip/__init__.py 2018-11-27 02:36:19.301655008 +0000
## -8,9 +8,9 ##
__all__ = ["version", "bootstrap"]
-_SETUPTOOLS_VERSION = "39.0.1"
+_SETUPTOOLS_VERSION = "40.6.2"
-_PIP_VERSION = "10.0.1"
+_PIP_VERSION = "18.1"
_PROJECTS = [
("setuptools", _SETUPTOOLS_VERSION),
Only in Python-3.7.1/Lib/ensurepip/_bundled: pip-10.0.1-py2.py3-none-any.whl
Only in Python-3.7.1.new/Lib/ensurepip/_bundled: pip-18.1-py2.py3-none-any.whl
Only in Python-3.7.1/Lib/ensurepip/_bundled: setuptools-39.0.1-py2.py3-none-any.whl
Only in Python-3.7.1.new/Lib/ensurepip/_bundled: setuptools-40.6.2-py2.py3-none-any.whl
If you're lucky, you can bump it up with a Python patch.
Is your Python outdated? This is using macports, but any of brew, apt should do.
port outdated
python36 3.6.9 < 3.6.10
Let's fix that:
sudo port upgrade python36
And now... drumroll, in my newly-recreated venv, it seems that the Python patch has brought along the latest pip.
pip --version shows 20.0.2, it was at 18 previously and that's precisely what it was complaining about in the venv.
This is after spending a ludicrously long amount of time trying to figure out how to update my user-level Python 3.6 version of pip, on a mac where, of course, if you quit the virtualenv you are at Python 2.7 and where Python 3.6, installed through macports, doesn't seem to have a pip command to work with, until you build a venv.
From looking at /opt/local/Library/Frameworks/Python.framework/Versions/3.6, where macports puts things, I suspect Utknonos is on to something, so +1.
There really should be something a bit more obvious, like a pip-system-selfupdate command or a pip36 that comes along with python36. Especially considering that a search of pip upgrade will return tons of hits on anything but this subject.
Note: after my update, even though Python has been updated
(venv)$ pwd
/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6
(venv)$ grep PIP_VERSION ensurepip/__init__.py
_PIP_VERSION = "18.1"
(venv) $python --version
Python 3.6.10
(venv) $pip --version
pip 20.0.2 from .../venv/lib/python3.6/site-packages/pip (python 3.6)
I need to be able to switch back and forth between Python 2 and 3. How do I do that using Homebrew as I don't want to mess with path and get into trouble.
Right now I have 2.7 installed through Homebrew.
I would use pyenv You can install it:
$ brew install pyenv
To enable pyenv in your Bash shell, you need to run:
$ eval "$(pyenv init -)"
To do this automatically for Bash upon startup, add that line to your ~/.bash_profile. 1
Usage:
Once you have installed pyenv and activated it, you can install different versions of python and choose which one you can use. Example:
$ pyenv install 2.7.5
You can check the versions you have installed with:
$ pyenv versions
And you can switch between python versions with the command:
$ pyenv global 3.3.1
Also you can set a python version for the current directory with:
$ pyenv local 3.5.2
You can check by running python --version:
$ python --version
Python 3.5.2
1 Homebrew used to instruct you to do this upon installation of pyenv, but the message was removed. For Zsh and other shells, the precise steps may be different.
You can have both versions installed at the same time.
For Homebrew >=1.5.0:
Since 1st March 2018 the python formula will be upgraded to Python 3.x, while a new python#2 formula will be added for Python 2.7, specifically.
See changes announcement here or the final doc about using Homebrew for Python here.
For older Homebrew:
For Python 2.x:
brew install python
For Python 3.x:
brew install python3
Now, you will have both the versions installed in your machine. When you want to use version 2, use the python executable. When you want to use version 3, use the python3 executable.
Currently Homebrew provides two different formulas for Python 2 and 3. brew install python installs python3, and brew install python#2 installs python2. More details in Homebrew docs:
https://docs.brew.sh/Homebrew-and-Python
If you currently have 2.x installed via Homebrew, Homebrew will give you a message such as:
Error: python 2.7.14 is already installed
To upgrade to 3.6.5, run `brew upgrade python`
If you run:
brew upgrade python
you should be able to do:
python --version
and
python3 --version
To see what versions of Python 2.x and 3.x installed.
There are ways to use both , but the simplest solution today is to use pyenv. pyenv allows easy switching between versions.
Here is what I did to set up:
STEP1:
Remove all pythons from your mac
brew uninstall --ignore-dependencies --force python
sudo rm -rf ~/miniconda3/
sudo rm -rf ~/.conda/
Remove the following from ~/.bash_profile
export PATH="/Users/ishandutta2007/miniconda3/bin:$PATH"
and also the following from ~/.bashrc
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
export PYTHONPATH=/usr/local/lib/python2.7/site-packages/google:$PYTHONPATH
alias python="/usr/bin/python"
STEP2:
Install pyenv and the python versions you need
brew update
brew install pyenv
pyenv install 2.7
pyenv install 3.7.0
STEP3:
add pyenv init to bash_profile or bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
STEP4:
Check what got installed
pyenv versions
system (set by /Users/ishandutta2007/.pyenv/version)
2.7
3.7.0
STEP5:
Choose a default
pyenv global 3.7.0
When a project needs older version, just go its root folder and run
pyenv local 2.7
Alternatively, you probably can just enter "python3" to run your most current version of python3.x and "python" or "python2" to run the latest installed 2.x version.
Use asdf !
Ballad of asdf
Once upon a time there was a programming language
There were many versions of it
So people wrote a version manager for it
To switch between versions for projects
Different, old, new.
Then there came more programming languages
So there came more version managers
And many commands for them
I installed a lot of them
I learnt a lot of commands
Then I said, just one more version manager
Which I will write instead
So, there came another version manager
asdf version manager - https://github.com/asdf-vm/asdf
A version manager so extendable
for which anyone can create a plugin
To support their favourite language
No more installing more version managers
Or learning more commands
https://github.com/asdf-vm/asdf
https://github.com/tuvistavie/asdf-python
https://github.com/asdf-vm/asdf-plugins
I thought I had the same requirement - to move between Python versions - but I achieved all I needed with only Python3.6 by building from source instead of using homebrew.
git clone https://git.<theThingYouWantToInstall>
Depending on the repo, check if there is MAKE file already setup for this option.
I was able to just go to https://www.python.org/downloads/mac-osx/ and download the latest python. It installed along side current python in my system.
Okay, I was struggling with my brew installation of Python3, because I didn't have pip3
sudo pip3 command not found
and so I did
brew uninstall --force --ignore-dependencies python3
and installed the regular Python 3.6.2 from official distribution and then I had pip3 and all components were ok.