Can't update Python from 3.6 to 3.7 in MacOS - python-3.x

I have tried several commands to update python 3.6 to python 3.7 in homebrew on MacOS.
I have tried (as administrator user):
brew update
This claimed to install python 3.7
brew upgrade
brew link python3
brew link --overwrite python3
brew unlink python && brew link python
brew switch python 3.7.0
brew switch python 3.7.5
Cleaning /usr/local/Cellar/python/3.7.5
24 links created for /usr/local/Cellar/python/3.7.5
After all those attempts, I still get this:
python3 --version
Python 3.6.5
Can someone please help me to get switched over to python3?

Based on the comment:
which python3 -> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
Your python3 is not the same one installed/managed by Homebrew.
(Maybe it's from a Python .pkg installer for Mac?).
First, install it via Homebrew:
$ brew uninstall python3 # let's start from scratch
$ brew install python3
Check where it's installed:
$ brew info python3
python: stable 3.7.5 (bottled), HEAD
...
==> Caveats
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
If you need Homebrew's Python 2.7 run
brew install python#2
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
...
Notice that Homebrew installed it at /usr/local/bin/python3 and the site-packages are stored at the corresponding /usr/local/lib/python3.7/site-packages.
Next, you need to make sure your OS looks for python3 at that same path.
$ echo $PATH
/usr/local/sbin:/usr/local/opt/openssl/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
If you don't see /usr/local/bin there, add it to your PATH by adding this to your ~/.bash_profile:
export PATH=/usr/local/bin:$PATH
Then source the updated ~/.bash_profile (or restart your Terminal).
$ source ~/.bash_profile
$ echo $PATH
From the comment, if your PATH shows /Library/Frameworks/Python.framework/Versions/3.6/bin/python3, you'll either have to remove it by explicitly setting the full PATH in your .bash_profile or make sure it comes after Homebrew's Python in /usr/local/bin.
Finally, check that python3 is now correct:
$ which python3
/usr/local/bin/python
$ ls -l /usr/local/bin/python
lrwxr-xr-x 1 gino admin 38 Oct 4 17:35 /usr/local/bin/python3 -> ../Cellar/python/3.7.5/bin/python3
$ python3 -V
Python3.7.5
Notice that python3 should be the python3 installed by Homebrew in the ../Cellar directory.
Can I easily change to the homebrew installation, or will I lose all my installed packages?
I would recommend re-installing the packages over at Homebrew's python3's site-packages folder. If you maintained a requirements.txt file for your Python projects, it's as simple as:
$ python3 -m pip install -r requirements.txt

The final solution was that Python 3.7 was already installed and could be accessed using the command python3.7.

Related

Python - managing package installations between anaconda and base system [duplicate]

Is there any way to make pip play well with multiple versions of Python? For example, I want to use pip to explicitly install things to either my site 2.5 installation or my site 2.6 installation.
For example, with easy_install, I use easy_install-2.{5,6}.
And, yes — I know about virtualenv, and no — it's not a solution to this particular problem.
The current recommendation is to use python -m pip, where python is the version of Python you would like to use. This is the recommendation because it works across all versions of Python, and in all forms of virtualenv. For example:
# The system default python:
$ python -m pip install fish
# A virtualenv's python:
$ .env/bin/python -m pip install fish
# A specific version of python:
$ python-3.6 -m pip install fish
Previous answer, left for posterity:
Since version 0.8, Pip supports pip-{version}. You can use it the same as easy_install-{version}:
$ pip-2.5 install myfoopackage
$ pip-2.6 install otherpackage
$ pip-2.7 install mybarpackage
EDIT: pip changed its schema to use pipVERSION instead of pip-VERSION in version 1.5. You should use the following if you have pip >= 1.5:
$ pip2.6 install otherpackage
$ pip2.7 install mybarpackage
Check https://github.com/pypa/pip/pull/1053 for more details
References:
https://github.com/pypa/pip/issues/200
http://www.pip-installer.org/docs/pip/en/0.8.3/news.html#id4
https://pip.pypa.io/en/stable/news/#v0-8 or
https://web.archive.org/web/20140310013920/http://www.pip-installer.org:80/docs/pip/en/0.8.3/news.html#id4
On Windows, you can execute the pip module using a given Python version through the Python launcher, py.exe, if you chose to install it during Python 3 setup.
py -3 -m pip install packagename
py -2 -m pip install packagename
You can be even more specific and request an exact sub-version of Python:
py -3.6 -m pip install packagename
To get a list of all installed Python versions available through the launcher, run:
py --list
Alternatively, you can launch the desired Python executable directly:
C:/path/to/specific/python.exe -m pip install packagename
/path/to/python2.{5,6} /path/to/pip install PackageName doesn't work?
For this to work on any python version that doesn't have pip already installed you need to download pip and do python*version* setup.py install. For example python3.3 setup.py install. This resolves the import error in the comments. (As suggested by #hbdgaf)
I had python 2.6 installed by default (Amazon EC2 AMI), but needed python2.7 plus some external packages for my application. Assuming you already installed python2.7 alongside with default python (2.6 in my case). Here is how to install pip and packages for non-default python2.7
Install pip for your python version:
curl -O https://bootstrap.pypa.io/get-pip.py
python27 get-pip.py
Use specific pip version to install packages:
pip2.7 install mysql-connector-python --allow-external mysql-connector-python
It worked for me in windows this way:
I changed the name of python files python.py and pythonw.exe to python3.py pythonw3.py
Then I just ran this command in the prompt:
python3 -m pip install package
Other answers show how to use pip with both 2.X and 3.X Python, but does not show how to handle the case of multiple Python distributions (eg. original Python and Anaconda Python).
I have a total of 3 Python versions: original Python 2.7 and Python 3.5 and Anaconda Python 3.5.
Here is how I install a package into:
Original Python 3.5:
/usr/bin/python3 -m pip install python-daemon
Original Python 2.7:
/usr/bin/python -m pip install python-daemon
Anaconda Python 3.5:
python3 -m pip install python-daemon
or
pip3 install python-daemon
Simpler, as Anaconda overrides original Python binaries in user environment.
Of course, installing in anaconda should be done with conda command, this is just an example.
Also, make sure that pip is installed for that specific python.You might need to manually install pip. This works in Ubuntu 16.04:
sudo apt-get install python-pip
or
sudo apt-get install python3-pip
From here: https://docs.python.org/3/installing/
Here is how to install packages for various versions that are installed at the same time linux, mac, posix:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
python3.5 -m pip install SomePackage # specifically Python 3.5
python3.6 -m pip install SomePackage # specifically Python 3.6
On Windows, use the py Python launcher in combination with the -m switch:
py -2 -m pip install SomePackage # default Python 2
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3 -m pip install SomePackage # default Python 3
py -3.4 -m pip install SomePackage # specifically Python 3.4
I ran into this issue myself recently and found that I wasn't getting the right pip for Python 3, on my Linux system that also has Python 2.
First you must ensure that you have installed pip for your python version:
For Python 2:
sudo apt-get install python-pip
For Python 3:
sudo apt-get install python3-pip
Then to install packages for one version of Python or the other, simply use the following for Python 2:
pip install <package>
or for Python 3:
pip3 install <package>
pip is also a python package. So the easiest way to install modules to a specific python version would be below
python2.7 /usr/bin/pip install foo
or
python2.7 -m pip install foo
So apparently there are multiple versions of easy_install and pip. It seems to be a big mess. Anyway, this is what I did to install Django for Python 2.7 on Ubuntu 12.10:
$ sudo easy_install-2.7 pip
Searching for pip
Best match: pip 1.1
Adding pip 1.1 to easy-install.pth file
Installing pip-2.7 script to /usr/local/bin
Using /usr/lib/python2.7/dist-packages
Processing dependencies for pip
Finished processing dependencies for pip
$ sudo pip-2.7 install django
Downloading/unpacking django
Downloading Django-1.5.1.tar.gz (8.0Mb): 8.0Mb downloaded
Running setup.py egg_info for package django
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
changing mode of /usr/local/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>>
On Linux, Mac OS X and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:
python2.7 -m pip install SomePackage
python3.4 -m pip install SomePackage
(appropriately versioned pip commands may also be available)
On Windows, use the py Python launcher in combination with the -m switch:
py -2.7 -m pip install SomePackage # specifically Python 2.7
py -3.4 -m pip install SomePackage # specifically Python 3.4
if you get an error for py -3.4 then try:
pip install SomePackage
Installation of multiple versions of Python and respective Packages.
Python version on the same windows machine : 2.7 , 3.4 and 3.6
Installation of all 3 versions of Python :
Installed the Python 2.7 , 3.4 and 3.6 with the below paths
PATH for all 3 versions of Python :
Made sure the PATH variable ( in System Variables ) has below paths included - C:\Python27\;C:\Python27\Scripts;C:\Python34\;C:\Python34\Scripts;C:\Python36\;C:\Python36\Scripts\;
Renaming the executables for versions :
Changed the python executable name in C:\Python36 and C:\Python34 to python36 and python34 respectively.
Checked for the command prompt with all versions :
Installing the packages separately for each version
If you have multiple versions as well as multiple architectures (32 bit, 64 bit) you will need to add a -32 or -64 at the end of your version.
For windows, go to cmd and type py --list and it will produce the versions you have installed. The list will look like the following:
Installed Pythons found by py Launcher for Windows
-3.7-64 *
-3.7-32
-3.6-32
The full command as an example will be:
py -3.6-32 -m pip install (package)
If you want to get more indepth, to install a specific version of a package on a specific version of python, use ==(version) after the package. As an example,
py -3.6-32 -m pip install opencv-python==4.1.0.25
Here is my take on the problem. Works for Python3. The main features are:
Each Python version is compiled from source
All versions are installed locally
Does not mangle your system's default Python installation in any way
Each Python version is isolated with virtualenv
Prerequisites: If you are using some bare-bones thin client with no extra turf installed, you should run this first (in ubuntu 18.04 at least, extra packages added for convenience):
sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-add-repository universe
sudo apt-get update
sudo apt-get install -y build-essential cmake
sudo apt-get install -y zlib1g zlib1g-dev libsqlite3-dev \
openssl libssl-dev libffi-dev unzip pciutils net-tools \
libblas-dev gfortran libblas3
The steps are as follows:
If you have several extra python versions installed in some other way, get rid of them, e.g., remove $HOME/.local/lib/python3.x, etc. (also the globally installed ones). Don't touch your system's default python3 version though.
Download source for different python versions under the following directory structure:
$HOME/
python_versions/ : download Python-*.tgz packages here and "tar xvf" them. You'll get directories like this:
Python-3.4.8/
Python-3.6.5/
Python-3.x.y/
...
At each "Python-3.x.y/" directory, do the following (do NOT use "sudo" in any of the steps!):
mkdir root
./configure --prefix=$PWD/root
make -j 2
make install
virtualenv --no-site-packages -p root/bin/python3.x env
At "python_versions/" create files like this:
env_python3x.bash:
#!/bin/bash
echo "type deactivate to exit"
source $HOME/python_versions/Python-3.x.y/env/bin/activate
Now, anytime you wish to opt for python3.x, do
source $HOME/python_versions/env_python3x.bash
to enter the virtualenv
While in the virtualenv, install your favorite python packages with
pip install --upgrade package_name
To exit the virtualenv and python version just type "deactivate"
UPDATE
It seems that --no-site-packages is deprecated. There's an easy fix for this: Once you have activated the virtualenv, just point the HOME env variable to somewhere else than your actual home directory, i.e.:
export HOME=some/where/else
A nice way to do this in general is:
Create virtualenv
Activate virtualenv
If you want to "recycle" existing libraries to your virtualenv, softlink them from your existing install, i.e.
ln -s $HOME/.local/lib/python3.6/site-packages/numpy $PWD/venv/lib/python3.6/site-packages/
Do export PYTHONPATH=, export HOME=/some/other/dir
Now you should have custom-isolated virtualenv.
UPDATE 2 / SUDO
Wan't to force sudo to use your virtualenv?
Defaults secure_path="/home/USENAME/Python-3.x.y/env/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
Defaults env_keep += "VIRTUAL_ENV"
Defaults env_keep += "PYTHONPATH"
Now try "sudo python3 --version" and magic should happen
UPDATE 3 / DOCKER
Enable virtualenv inside your docker (of course, you have built it in your docker image):
ENV VIRTUAL_ENV=/home/USER/Python-3.x.y/env
ENV PYTHONPATH=
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
You can use one of the following commands:
pip2 install SomePackage
pip3 install SomePackage
python2 -m pip install SomePackage
python3 -m pip install SomePackage
And of course, make sure that you have the correct version of pip installed
sudo apt-get install python-pip
sudo apt-get install python3-pip
I haven't used these commands myself but, some answers above suggests using them to specify exactly the version of python you want to use
pip-2.7 install SomePackage
python-3.6 -m pip install SomePackage
For python 3 and Windows OS, I always use this syntax to install packages on different version:
First I always use Git Bash Command Prompt.
Here an example installing urllib package.
Default Python version:(The normal pip command)
pip install urllib3
For the other versions
py -3.8 -m pip install urllib3
py => for python
-3.8 => for the version (I'm using the 3.8.7 version) but if you're using the 3.7.7 version it will be "-3.7"
-m : just because or for modify
pip install urllib3 : the normal pip command
Most of the answers here address the issue but I want to add something what was continually confusing me with regard to creating an alternate installation of python in the /usr/local on CentOS 7. When I installed there, it appeared like pip was working since I could use pip2.7 install and it would install modules. However, what I couldn't figure out was why my newly installed version of python wasn't seeing what I was installing.
It turns out in CentOS 7 that there is already a python2.7 and a pip2.7 in the /usr/bin folder. To install pip for your new python distribution, you need to specifically tell sudo to go to /usr/local/bin
sudo /usr/local/bin/python2.7 -m ensurepip
This should get pip2.7 installed in your /usr/local/bin folder along with your version of python. The trick is that when you want to install modules, you either need to modify the sudo $PATH variable to include /usr/local/bin or you need to execute
sudo /usr/local/bin/pip2.7 install <module>
if you want to install a new module. It took me forever to remember that sudo wasn't immediately seeing /usr/local/bin.
Simple and recent
On windows
1- Supposed that you have a different version of Python installed in your system. To check use the following command to check:
> py --list
-3.10-64 *
-3.7-64
2- Set your preferred default version:
by setting the PY_PYTHON environment variable (e.g. PY_PYTHON=3.7).
by settting the py.ini file usually located on C:\Users\<your user name>\AppData\Local if not create one. For example, setting PY_PYTHON=3 and PY_PYTHON3=3.7 environment variables are equivalent to the INI file containing:
[defaults]
python=3
python3=3.7
3- check by typing again py --list:
> py --list
-3.10-64
-3.7-64 *
4- If you would like to run virtual environment with spesific version of python and pip see this post.
On Linux (Ubuntu)
An easy approach for managing different python versions on Linux is update-alternatives command. This command giving us the ability to switch between many versions of the same software easily.
command format:update-alternatives --install link name path priority, the name is the generic name for the master link, the link is the name of its symlink, the path is the alternative being introduced for the master link, and priority is the priority of the alternatives group.
Usage: Suppose you installed two versions of python (python3.10 , python3.7). Now by running this command you will link the command name (python3) to different versions of python and assign a priority number. A higher priority number means a higher priority.
$ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
$ update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 2
List installed versions of python with this command:
$ update-alternatives --list python3
/usr/bin/python3.7
/usr/bin/python3.10
Switching between versions: Just manually select the priority number of the desired python version after running following command.
$ update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.10 2 auto mode
* 1 /usr/bin/python3.7 1 manual mode
2 /usr/bin/python3.10 2 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
Context: Archlinux
Action:
Install python2-pip:
sudo pacman -S python2-pip
You now have pip2.7:
sudo pip2.7 install boto
Test (in my case I needed 'boto'):
Run the following commands:
python2
import boto
Success: No error.
Exit: Ctrl+D
for example, if you set other versions (e.g. 3.5) as default and want to install pip for python 2.7:
download pip at https://pypi.python.org/pypi/pip (tar)
unzip tar file
cd to the file’s directory
sudo python2.7 setup.py install
If you have both python3.6 and python3.7 installed and want to use pip with python3.7 by default, here's what you should do:
First make sure you have pip installed for python3.7
python3.7 -m pip install -U pip
Now pip3.7 must be available, so we edit .bashrc
nano ~/.bashrc
adding the following line to it
alias pip=pip3.7
In order for the changes to take effect type in the shell:
source ~/.bashrc
Now if you type:
pip --version
you should get:
pip 20.1.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)
which means, if you use, for example:
pip install <package>
it would install the <package> for python3.7
Another possible way could be using conda and pip. Some time you probably want to use just one of those, but if you really need to set up a particular version of python I combine both.
I create a starting conda enviroment with the python I want. As in here https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html. Alternatively you could set up the whole enviroment just using conda.
conda create -n myenv python=3.6.4
Then activate your enviroment with the python you like. This command could change depending on the OS.
source activae myenv
Now you have your python active then you could continue using conda but if you need/want to use pip:
python -m pip -r requirements.txt
Here you have a possible way.
You can go to for example C:\Python2.7\Scripts and then run cmd from that path. After that you can run pip2.7 install yourpackage...
That will install package for that version of Python.
This is probably the completely wrong thing to do (I'm a python noob), but I just went in and edited the pip file
#!/usr/bin/env python3 <-- I changed this line.
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
To use multiple versions of pip, just type
pip{version} and run command
Example: for python 3.10
pip3.10
pip3.10 list
pip3.10
for Python 3.7
pip3.7
pip3.7 list
For windows specifically:
\path\to\python.exe -m pip install PackageName works.
for Blender:
/usr/bin $ python3.7 -m pip install irc
Some useful information for debugging this is the pip debug command. It shows the location of the python interpreter that it is attached to in the 1st line (after the warning).
$ pip debug
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 21.2.4 from /data/akshay/anaconda3/lib/python3.9/site-packages/pip (python 3.9)
sys.version: 3.9.12 (main, Apr 5 2022, 06:56:58)
sys.executable: /data/akshay/anaconda3/bin/python

Installed python package with `pip3`, but when I call it I get "No module named X"

I installed a module like this:
> pip3.8 install mssql-cli
but when I run it I get:
> 3002 ~$ mssql-cli -S 192.168.7.50 -d test-db
/usr/bin/python: No module named mssqlcli
I think mssql-cli is defaulting to the system--default python (2.x). How do I tell it to use python3.8?
Yes, I'm on a Mac. Python 3.8 is installed via Homebrew.
Answering questions from comments:
What does pip3.8 --version say?
3044 ~$ pip3.8 --version
pip 20.1.1 from /usr/local/lib/python3.8/site-packages/pip (python 3.8)
And check that which python3.8 points to /usr/local/lib/python3.8/python?
Not exactly. Is that bad?
3048 ~$ ll `which python3.8`
lrwxr-xr-x 1 grantb admin 40 Jul 24 10:57 /usr/local/bin/python3.8# -> ../Cellar/python#3.8/3.8.5/bin/python3.8
The issue is that if you look at the actual mssql-cli file it runs it using the python command. This (on my Mac) defaults to the 2.7 python. There are three solutions:
Add a line in your .bashrc or .bash_profile that says alias python='python3.8'. Note that this will override your python2.7 (which is obsolete anyway).
Edit the last line of the file that comes up with which mssql-cli to say python3.8 -m mssqlcli.main "$#". This has the disadvantage that you aren't really supposed to edit this, and that you'd need to do it every time you update this package, but it does work.
Run each mssql-cli command with the equivalent python3.8 -m mssqlcli.main.
Yet another brave soul caught up in the tangled web of installing Python on a Mac.
Your problem is that homebrew installed a version of Python in /usr/local/Cellar/python#3.8/3.8.5/bin/python3.8. Pip3.8, on the other hand, thinks Python is at /usr/local/lib/python3.8/python, so it installs its packages in that python's site-packages directory.
If you already had python with pip installed when you installed it from the Homebrew bottle, it won't overwrite the links you already had. One solution is to reinstall pip through the correct python.
python3.8 -m pip install -U --force-reinstall pip
This should force a reinstall of pip, and since python3.8 points to Homebrew's Python, it should install pip and pip3 as pointing to that python.

How to default Python3.8 on my Mac using Homebrew?

I have updated my python 3 to the latest version 3.8:
brew search python
==> Formulae
app-engine-python gst-python python ✔ python#3.8 ✔
boost-python ipython python-markdown wxpython
boost-python3 micropython python-yq
==> Casks
awips-python kk7ds-python-runtime mysql-connector-python
But when I check the python3 version on my mac it still shows 3.7:
python3 --version
Python 3.7.6
how can I default python3 to the latest 3.8 version using Homebrew ?
Edit:
When I tried to use brew switch, it tells me I only installed python 3.7.6, but with last brew upgrade I'm pretty sure that python3.8.1 is installed with Homebrew
brew switch python 3.8.1
python does not have a version "3.8.1" in the Cellar.
python's installed versions: 3.7.6_1
Here is the solution:
If existing symlinks belong to python 3.7 you should unlink them:
brew unlink python
Basically all you need to do:
brew link --force python#3.8
OR force the link and overwrite all conflicting files:
brew link --force --overwrite python#3.8
OR if needed list all files that would be deleted:
brew link --overwrite --dry-run python#3.8
Thus you can switch to any python version available in the Homebrew repo.
Also check out this answer for pyenv usage
Ok, thanks to #gromgit from Homebrew community discussion (https://discourse.brew.sh/t/how-to-default-python-3-8-on-my-mac-using-homebrew/7050)
Here is the solution:
$ brew info python#3.8
python#3.8: stable 3.8.1 (bottled) [keg-only]
...
==> Caveats
Python has been installed as
/usr/local/opt/python#3.8/bin/python3
...
python#3.8 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have python#3.8 first in your PATH run:
echo 'export PATH="/usr/local/opt/python#3.8/bin:$PATH"' >> ~/.bash_profile
For compilers to find python#3.8 you may need to set:
export LDFLAGS="-L/usr/local/opt/python#3.8/lib"
For pkg-config to find python#3.8 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/python#3.8/lib/pkgconfig"
I will stick to python (v3.7.6) at this time and wait for seamless upgrade of v3.8.1 in the future releases.
You might have to add python 3.8.1 to your PATH in your ~/.bash_profile and put it first so that it overrides previous installations. First find out where python 3.8.1 was installed, then add it to your path like this:
export PATH="/PATH_TO_PYTHON/:${PATH}"
I have a company Mac with Python 2.7 preinstalled to run older software.
$ brew install pyenv (successful)
$ pyenv install 3.9.2 (successful)
$ python --version
Python 2.7
$ pyenv global 3.9.2
$ python --version
Python 2.7
It still says Python 2.7, so, I did the following commands
pyenv init
eval "$(pyenv init -)"
$ python --version
Python 3.9.2
More details:
Link

pip uninstall: "No files were found to uninstall."

I have created a python module, call it 'foo_bar'.
I can install it and I can upgrade it, but I cannot uninstall it.
I build my module using bdist_wheel:
$ python3 setup.py bdist_wheel
And I install and upgrade it as follows:
$ python3 -m pip --timeout 60 install --upgrade dist/foo_bar-1.4.3-py3-none-any.whl
It is listed within Python 3.4 framework directory:
ls -al /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/
drwxr-xr-x 12 samwise admin 408 Jun 21 02:50 foo_bar
drwxr-xr-x 9 samwise admin 306 Jun 21 02:50 foo_bar-1.4.3.dist-info
And it listed within pip freeze:
$ python3 -m pip freeze
foo-bar==1.4.3
However, if I try to perform pip uninstall, it cannot find it's files
$ python3 -m pip uninstall foo-bar
Can't uninstall 'foo-bar'. No files were found to uninstall.
Did I do something wrong within my setup.py for it not to be able to find my modules files during uninstall?
Version info is as follows:
$ python3 --version
Python 3.4.4
$ python3 -m pip --version
pip 8.1.2 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
I had the same issue. Using verbose helped me to find out a bit more the reason:
$ pip3 uninstall --verbose my-homemade-package
Not sure how to uninstall: my-homemade-package e48e635 - Check: /home/olivier/my-homemade-package
Can't uninstall 'my-homemade-package'. No files were found to uninstall.
Removing everything that was 'my-homemade-package' related in /usr/local/python2.x and /usr/local/python3.x did not help.
I did a pip3 show my-homemade-package and got the location of the installed package on my computer:
$ pip3 show my-homemade-package
Name: my-homemade-package
Version: e48e635
Summary: My Home Made package
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: Proprietary
Location: /home/olivier/my-homemade-package
Requires: pyOpenSSL, pyasn1, protobuf
Removing /home/olivier/my-homemade-package sorted it out the issue (ie: the package was not listed).
This is an old post, but it was top result in Google. The above answers are correct, however, in my case there was still line /usr/local/lib/python3.6/site-packages/easy-install.pth that I had to remove after also removing the egg files.
So I was having a similar issue to OP. I could install my package with pip install dist/mypackage.tar.gz. Installation would work fine, but at the end it would show Can't uninstall 'mypackage'. No files were found to uninstall., and indeed pip uninstall mypackage wouldn't work later on.
It sounds silly but what worked for me was to change working directory: once I left mypackage/ directory, pip uninstall mypackage worked.
I had such issue when I renamed my module in setup.py.
Old old_name.egg-info directory still existed in my_module directory. So, when I installed module with pip install -e . pip created a line in python3.8/site-packages/easy-install.pth pointing to module directory. After that module was listed by pip list with both names: new-name and old-name. And when I tried to remove old module with pip remove old-name pip showed error:
Found existing installation: old-name 0.3.0
Can't uninstall 'old-name'. No files were found to uninstall.
The solution was to remove directory old_name.egg-info from module directory. After that pip list shows only new-name.
Probably it is not direct answer to original post but one of the solutions for issue in topic-name.
Issue: User cannot uninstall a python package installed via pip:
pip uninstall youtube-dl
Found existing installation: youtube-dl 2021.12.17
Not uninstalling youtube-dl at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'youtube-dl'. No files were found to uninstall.
Reason: PEBKAC.
Well, a simple
apt purge youtube-dl
did the trick. There had been a system package "youtube-dl" installed, with said version:
dpkg -l youtube-dl
ii youtube-dl 2021.12.17-1~nd110+1
At the same time users used to install packages locally using pip. Both packages of the same version (2021.12.17). And both ways (apt and pip) referred to the packages by the same name. Turned out, this tends to confuse users..
Next level: Have a package installed three ways: apt, pip --system and plain pip as user. Maybe pip as root (locally) FWIW, too.

Pip won't install into python 3 when using homebrew python?

So I've got a virtualenv I've created using pyvenv-3.3, which I thought set up pip to install things into the virtualenv's path. However, I get the following outputs after I've activated by virtualenv:
$ pip --version
pip 1.4.1 from /usr/local/lib/python2.7/site-packages/pip-1.4.1-py2.7.egg (python 2.7)
pip-3.3 --version
pip 1.4.1 from /usr/local/lib/python3.3/site-packages/pip-1.4.1-py3.3.egg (python 3.3)
This is all fine and good, but then my sys.path is this:
['',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python33.zip',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/plat-darwin',
'/usr/local/Cellar/python3/3.3.2/Frameworks/Python.framework/Versions/3.3/lib/python3.3/lib-dynload',
'/Users/alexgolec/Documents/gutenberg/virtualenv/lib/python3.3/site-packages']
Most notably, the whole site-packages directory is outright missing. Furthermore, this output indicates to me that I'm probably using a python that installed through homebrew at some point. Most infuriatingly, none of the directories in my sys.path are compatible with pip.
Any thoughts on remedies? I won't manually edit my sys.path, but maybe there's some configuration with pip I can do?
Install virtualenvwrapper (makes using virtualenv so much easier):
pip install virtualenvwrapper
.. and then try this:
mkvirtualenv <your_env> -p /usr/local/bin/python3
Where homebrew sticks python is different from where your system has it. You can run the following to see what I'm talking about:
which python
which python3

Resources