I recently formatted my Macbook and I only remember downloading Python3 once. So when I went to change my interpreter path, it shows 2 different Python3 paths. I'm aware that the one on top is installed on my system by default, but as for the bottom two, I'm not too sure what are the differences between them.
The 1st one (Python2.7) is the system default/built-in Python.
The middle one (Python3, /Library/Frameworks/Python.framework/) is what you usually get when you install Python from the Python Releases for Mac OS X downloads page from python.org, using the macOS installer (something like a python-3.8.7-macosx10.9-1.pkg).
The bottom one (Python3, /usr/local/bin/python3) is what you usually get when you use Homebrew to install Python: https://docs.brew.sh/Homebrew-and-Python.
~$ brew info python3
python#3.9: stable 3.9.1 (bottled)
...
Python has been installed as
/usr/local/bin/python3
...
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.9/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
There is no difference in terms of functionality between the python.org one and the Homebrew one. If you installed the same version, they should work the same. The only difference, aside from the paths, is when you need to upgrade and/or remove your installation (ex. going from python3.8 to python3.9), something easily done with Homebrew using brew upgrade python3 and brew uninstall python3.
As to why VS Code finds those Python interpreters, see the section on the VS Code docs for where the extension looks for environments, which lists among those "Standard install paths such as /usr/local/bin, /usr/sbin, /sbin, c:\\python27, c:\\python36, etc".
I am running Ubuntu 20.04 with python 3.6, 3.7, and 3.8 installed.
I am trying to install some packages using pip on 3.6 and 3.7 versions using 'python3.7 -m pip install package' but, I am getting this error:
ModuleNotFoundError: No module named 'distutils.util
I already have python3-distutils and python3-distutils-extra installed but pip only works for python 3.8.
How can I make pip work for installing packages on python 3.6 and 3.7?
What about things like deadsnakes or pyenv, would those help? Otherwise you might need to add the apt repositories for older Ubuntu versions (say 18.04), but I am not sure what the side effects might be. This is a question that I would rather ask on Ask Ubuntu or Super User.
(from bounty description)
I want a definitive solution that does NOT involve someone telling me to install:
python-distutils
python3-distutils
python3-distutils-extra
I will be handing out FREE DOWNVOTES to anyone who mentions installing these.
Well, I have some bad news for you. There is no "official" way to get distutils on the Debian-provided python* packages without installing these packages, not unless you go outside of Debian's default package repositories.
This is a consequence of Debian's decision to break up various parts of Python's standard library into separate packages, on the basis of their policy to split things into runtime packages and development packages. They consider distutils to fall in the "development" part, and thus, don't distribute it as part of the standard python package.
Basically, your options are:
install a python*-distutils package.
This is what your OS maintainers recommend doing in your situation.
You've not explained why you'll "be handing out free downvotes" for anyone recommending this, but this is genuinely the "most correct" solution.
install Python, from somewhere that does not break up the standard library.
This would mean using a package source other than the official debian repositories.
The easiest source would be the deadsnakes ppa.
compile your own Python!
This isn't actually that difficult, and tools like pyenv make it easy to compile and manage multiple python versions.
hack around the problem!
You could... download the sources from CPython's repo, and place the Lib/distutils folder somewhere on the import path for pythonX.Y? This is a 100% hack though and I strongly recommend not doing this. If something bad happens, because you did this, I'm not responsible.
I've been looking for an answer to this question for almost as long as you, and finally found a solution.
Be warned, I may have screwed up my python3.8 installation as a side-effect, and it's possible the package will be uninstalled again and break things as soon as you run apt-update.
Also, it may be possible to reduce the number of commands, but here's what I ended up doing:
Run apt list to see a list of available packages:
$ apt list -a python3-distutils
Listing... Done
python3-distutils/focal-updates,focal-updates,focal-security,focal-security,now 3.8.5-1~20.04.1 all [installed]
python3-distutils/focal,focal 3.8.2-1ubuntu1 all
python3-distutils/bionic-updates,bionic-updates 3.6.9-1~18.04 all
python3-distutils/bionic,bionic 3.6.5-3 all
Then download the "bionic" deb package,
because it actually contains multiple versions of distutils,
for Pythons 3.6, 3.7 & 3.8:
$ apt download python3-distutils/bionic
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-distutils all 3.6.9-1~18.04 [144 kB]
Fetched 144 kB in 0s (661 kB/s)
Finally, install the deb package:
$ sudo dpkg --install python3-distutils_3.6.9-1~18.04_all.deb
dpkg: warning: downgrading python3-distutils from 3.8.5-1~20.04.1 to 3.6.9-1~18.04
(Reading database ... 193375 files and directories currently installed.)
Preparing to unpack python3-distutils_3.6.9-1~18.04_all.deb ...
Unpacking python3-distutils (3.6.9-1~18.04) over (3.8.5-1~20.04.1) ...
Setting up python3-distutils (3.6.9-1~18.04) ...
At this point, I was finally able to use pip with python3.6.
Note-1: The printouts of apt list -a above depend on whether you run an Ubuntu or a Debian distribution, and which apt-repos you have activated in /etc/apt/sources.list*.
Note-2: As seen in the case of python3-distutils/bionic, above, the name of the package does not always coincide with its contents.
To view them, you have to download it and inspect it with dpkg -C <pafkage-file>, or from remote with apt-file list python3-distutils.
Note-3: In case you cannot find the exact distutils version for a specific Python release, you may install an earlier version and symlink to it.
For example in Debian-unstable("sid") and "bullseye" as of January 2020, the python3-distutils package contained in their apt-repos has files just for Python3.9, and the previous apt-repos from "buster" contain files for Python3.7 only.
So if you wish to install distutils for Python3.8, you have to download the "buster" package and execute:
$ sudo dpkg --unpack python3-distutils_3.7.3-1_all.deb
$ sudo rm /usr/lib/python3.8/distutils/distutils/
$ sudo ln -w /usr/lib/python3.{7,8}/distutils/distutils/
The instructions here worked for me: https://www.linuxcapable.com/how-to-install-python-3-7-on-ubuntu-20-04-lts/
Namely this one sudo apt install python3.7-distutils
Was trying to install checkov and getting the ModuleNotFound error.
After the above, it installed just fine following these instructions
Here is what has worked for me on Ubuntu 22.04 for Python 3.6.
pip won't install as distutils is not available.
install python3.6 via apt
check the exact version with python3.6 --version
find a matching tag here: https://github.com/python/cpython.git, i.e. 3.6.9
adapt and call git clone --depth=1 -b v3.6.9 https://github.com/python/cpython.git
export PYTHONPATH=`pwd`/cpython/Lib
curl https://bootstrap.pypa.io/pip/3.6/get-pip.py | python3.6 - --user
python3.6 -m pip list
If the old version is not available, cd into the cpython source directory and use e.g. ./configure --enable-optimizations --prefix=$HOME/.local and make -j4 and make altinstall (set some PREFIX to install to when calling configure, so it won't clobber the system, but note that the install path has to be in your search paths)
I'm trying to install Python 3 alongside 2.7 with Homebrew but am receiving an error message I can't find a resolution to.
When attempting brew update && brew install python3 I get the following error:
Error: python 2.7.12_2 is already installed
To upgrade to 3.6.4_3, run `brew upgrade python`
I want to leave the python 2.7 installation alone so I can have both Python 2 & 3 accessible on my machine so I'm nervous that upgrading will overwrite the current 2.7 installation.
I figure I can still perform a clean side-by-side install with the package from python.org, but I want to know why I'm getting this homebrew error
brew doctor shows the following Warnings containing python
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: Python is installed at /Library/Frameworks/Python.framework
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.
Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
brew install python#2
To be honest, and what I also have on my own system, is Python 3 as the default and Python 2 available if I need it. With homebrew, you can just update your default as it wants you to do with the upgrade. That means when you run python, Python 3 will run as the default.
For Python 2, install brew install python#2. When you want to run Python 2, just run python2 in the terminal and you'll have it.
Python install will run once you fix the broken links by running brew link, and the missing link component.
These usually don't need SUDO, they will link then and run brew doctor once they have all been linked.
I am using Python 3.6. When I try to install "modules" using pip3, I face this issue:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
For Windows 10
if you want use pip in normal cmd, not only in Anaconda prompt. you need add 3 environment paths.
like the followings:
D:\Anaconda3
D:\Anaconda3\Scripts
D:\Anaconda3\Library\bin
most people only add D:\Anaconda3\Scripts
MAC OS
I had the same problem on Mac OS(Mojave) and solved the problem as mentioned on this link - Openssl issue.
If you do not have Homebrew or don't know what is Homebrew:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Or if you already have Homebrew installed:
brew update && brew upgrade
brew uninstall --ignore-dependencies openssl; brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb
Update:
Keep in mind, that I had to use --ignore-dependencies flag, because other packages installed that depend on OpenSSL.
Additional if the problem is caused after using pyenv, you can fix it by using:
brew reinstall python
For Debian users, the following may be of use:
sudo apt install libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.6 libgdm-dev libdb4o-cil-dev libpcap-dev
Then cd to the folder with the Python 3.X library source code and run:
./configure
make
make install
I'm using Windows 10 and installed Miniconda 3 with Python 3.7.
I solved this error by following this https://github.com/conda/conda/issues/8273
Specifically, I copied the following files from C:\Users\MyUser\Miniconda3\Library\bin to C:\Users\MyUser\Miniconda3\DLLs:
libcrypto-1_1-x64.dll
libcrypto-1_1-x64.pdb
libssl-1_1-x64.dll
libssl-1_1-x64.pdb
For centos 7:
Install openssl:
sudo yum install openssl-devel
now goto python directory were we extracted the python tar,
run below commands
sudo ./configure
sudo make
sudo make install
This will fix the problem in centos...
For future Oracle Linux users trying to solve this, below is what worked for me.
First install missing libs:
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
Then cd to your Python3.X library and run:
make
make install
macOS, pyenv
In case of your python being an pyenv installed one, where pyenv is installed with homebrew on macOS, there might me a newer version available which fixes this:
$ brew update && brew upgrade pyenv
Then reinstalling the python version:
$ pyenv install 3.7.2
pyenv: /Users/luckydonald/.pyenv/versions/3.7.2 already exists
continue with installation? (y/N)
Note, it is a bit dirty to overwrite the existing python install like that, but in my case it did work out. Probably cleaner to delete it and then recreate it properly.
For Windows 10,windows 7
If pip install is not working on CMD prompt, run it using Anaconda prompt - it works.
https://github.com/pypa/virtualenv/issues/1139
Worked for me.
sudo apt-get install libssl-dev
Use this to enable ssl for pip.
Let me know if someone encounters issues.
Encountered this issue while installing python 3.8 from source on ubuntu. The steps needed to install it successfully alongside the default python 3.7 are summarised below :
sudo apt -y install libssl-dev zlib1g-dev build-essential
wget https://www.python.org/ftp/python/3.8.0/Python-3.8.0.tgz
tar -xf Python-3.8.0.tgz
cd Python-3.8.0/
./configure --enable-optimizations
make
sudo make altinstall
The install instruction for zlib1g-dev and build-essential is redundant, as ubuntu desktop already has these, but was necessary for some of Amazon's EC2 instances. python 3.8.0 is the current release just now, but should be replaced with the latest available.
These instructions are best for keeping python 3.7 as the default for python3, and running python 3.8 in a virtual environment.
Similar to the above solution reinstall the python version with pyenv.
Somehow, I upgraded my openssl which broke the pyenv version python.
pyenv install 3.6.8
python-build: use openssl#1.1 from homebrew
python-build: use readline from homebrew
...
The first line says it relies on the homebrew openssl.
In my case, I reinstalled Python. It solved the problem.
brew reinstall python
For OpenSUSE in the same manner, but a few changes of listed above packages:
zypper install zlib-devel libopenssl-devel ncurses-devel sqlite3-devel readline-devel tk-devel gdbm-devel libpcap-devel xz-devel
Then cd to Python sources dir and
make
make install
or
make
make altinstall
And perhaps
ln -s /usr/local/lib64/python3.6/lib-dynload/ /usr/local/lib/python3.6/lib-dynload
should be executed for OpenSUSE users. See Python 3.7 install not working on openSUSE Leap 42.3
Just try installing through Anaconda prompt
I ran into this issue with Visual Studio Code installing pylint from the VS Code prompt.
I was able to overcome the issue by opening the Anaconda installation directory and running
pip install pylint
Then VS Code was happy, but that did not fix the issue as running
& C:/Users/happy/Anaconda3/python.exe -m pip install -U pylint
pretty much gave the same error so it seems that VS Code is unable to access the python modules.
Note that VS Code picks up the first python env it see when installed, the bottom left of the screen indicates which env is being used. Clicking on that area allows to set the environment. So even if you ran the pip install for an environment VS Code could be looking at a different one.
Best approach was to make sure that VS code had the correct python environment selected and that same environment is in the system PATH (under System Properties --> Advanced --> Environmental Variables)
Under the Path Variable, Edit and browse to the specific Anaconda directory that you want VSCode to use and add to PATH, I needed to Add the following:
C:\Users\happy\Anaconda3\
C:\Users\happy\Anaconda3\Scripts\
C:\Users\happy\Anaconda3\Library\bin\
C:\Users\happy\Anaconda3\Library\mingw-w64\bin\
Your Anaconda installation directory may differ.
One note is that Windows does not have the PATH variable take effect until you restart the terminal. In this case close and re-op VS code. If using a Terminal or PS Shell then close and reopen and check Path to make sure it is included.
The problem probably comes from your installed openssl package version. That was the case for me and I fixed this issue just upgrading it. I'm on Mac OS, using brew :
brew upgrade openssl
If you installed python with brew, this should directly fix the issue with it, as python is dependent on openssl
Newest Python 3.8.4 or higher should able to support https protocol out of box. If you still have old python installation on your pc - either download & install python3 manually, or using Chocolatey:
If you don't have Chocolatey, install it - from here: https://chocolatey.org/docs/installation
You can just copy paste one command line liner and execute it from command prompt with elevated priviledges.
choco install python3
if you don't have python3 installed, or you you have it installed - then:
choco upgrade python3
Notice also that you can use also anaconda distribution, as it has built-in python with https support, but this rather ancient instructions, no need to follow them anymore.
Install anaconda, using command line:
choco install anaconda3
Set environment variables:
set PATH=C:\tools\Anaconda3\Scripts;C:\tools\Anaconda3;C:\tools\Anaconda3\Library\bin;%PATH%
and then run command which failed. In my case it was:
pip install conan
Anaconda uses separate python installation, and pip is also anaconda specific.
As Tokci said, it also works for Windows 7.
"Go with the mouse to the Windows Icon (lower left) and start typing "Anaconda". There should show up some matching entries. Select "Anaconda Prompt". A new command window, named "Anaconda Prompt" will open."
Then pip works.
The following also helped to import xgboost:
https://www.youtube.com/watch?v=05djBSOs1FA
If someone is using Arch Linux OS, I solved the TLS/SSL problem by running this:
sudo pacman -S openssl
Then I could use pip to install the package I needed:
pip install openpyxl
Go to Anaconda prompt and type (if you have python 3.x installed on your engine) :
py -m pip install pymysql
i was having the same issue and this solved my problem. later after doing this you can import pymysql in power shell or any other prompt.
The issue is due to OpenSSL package is missing on your PC.
If pip install openpyxl also gives error.
you can fix this by installing OpenSSL(Win64 OpenSSL v1.1.1g) from below site :
slproweb.com/products/Win32OpenSSL.html
Restart the IDE you are using, for changes to be in effect.
In Windows 10 SQL Server 19 the solution is known.
Copy the following files:
libssl-1_1-x64.dll
libcrypto-1_1-x64.dll
from the folder
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\Library\bin
to the folder
C:\Program Files\Microsoft SQL Server\MSSSQL15.MSSQLSERVER\PYTHON_SERVICES\DLLs
Then open a new DOS command shell prompt.
From https://learn.microsoft.com/en-us/sql/machine-learning/troubleshooting/known-issues-for-sql-server-machine-learning-services?view=sql-server-ver15#7-unable-to-install-python-packages-using-pip-after-installing-sql-server-2019-on-windows
Worked for me.
pkg install openssl
Use this to enable ssl.
Currently there is same issue in Anaconda prompt (Anaconda3) on Windows 10. Here is workaround: https://github.com/ContinuumIO/anaconda-issues/issues/10576
Fixed this without having to change anything related to TSL/SSL.
I was trying to see if the same thing was happening to pip, and saw that pip was broken. Did some digging and realized it's probably caused by Homebrew deleted python#2 on February 1st, 2020.
Running brew uninstall python#2 to delete python2 installed by Homebrew.
Destroyed the virtual env created using python3 and created a new one. pip3 installing works fine again.
I am on macOS and I had used brew but what Vaulstein mentioned in his answer didn't cover my case.
I run the following commands to make sure my current python was not installed by brew
brew list | grep python
python
python#2
brew info python
python#3.8: stable 3.8.3 (bottled)
Interpreted, interactive, object-oriented programming language
https://www.python.org/
Not installed
...
So I download the latest 3.8.5 from https://www.python.org/ and when installing it I saw following information
Certificate verification and OpenSSL
This package includes its own private copy of OpenSSL 1.1.1. The
trust certificates in system and user keychains managed by the
Keychain Access application and the security command line utility are not used as defaults by the Python ssl module
After installed 3.8.5 it fixed the problem.
I got into this problem using Ubuntu, pyenv and Python 3.8.1 managed by pyenv. There was actually no way to get pip to work correctly, since every time I tried to install anything, including pip itself, the same error showed up.
Final solution was to install, via pyenv, a newer version, in this case 3.8.6. Apparently, from 3.8.4 Python is prepared to run SSL/TLS out of the box, so everything worked fine.
I simply solved the problem with following command:
brew upgrade python#3.9
SSL is included by default on this version!
In my case I was running into issues with my $PATH on Linux. This can also happen on MacOS.
Check to see if /usr/bin/pip3 install package_name_goes_here works for you. If so then run
which pip3 this will tell you which is the first directory that pip3 is installed in.
If it is something like /usr/local/bin/pip3 which is different from /usr/bin/pip3 then you may need to adjust your $PATH.
Run
echo $PATH and copy the result.
The PATH is simply a colon separated list of directories that contain directories. Bash will always return the first instance of the program that you are attempting to execute. Move all the system directories upfront. Here is a list of some of the system directories:
/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
If that fails then verify you have openssl installed by running openssl version -a if not then install openssl.
If you've installed anaconda via scoop, and encounter this error while using pip from within a conda environment you can resolve it by...
Adding these to your path
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Scripts
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Library
C:\Users\YOUR_USERNAME\scoop\apps\anaconda3\current\Library\bin
Installing openssl via scoop
scoop install openssl
And copying the following DLLs from ..\anaconda3\Library\bin to ..\anaconda3\DLLs
References:
https://stackoverflow.com/a/54897379
https://stackoverflow.com/a/60405693
I've been having issues with Python recently, such as compatibility with anaconda. When I ran Homebrew's brew doctor, I think I came across the problem, as laid out below. How can I wipe these files and do a clean install of Python?
Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.
Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4m-config
/opt/local/bin/curl-config
/opt/local/bin/freetype-config
/opt/local/bin/libpng-config
/opt/local/bin/libpng16-config
/opt/local/bin/nc-config
/opt/local/bin/ncurses5-config
/opt/local/bin/ncursesw5-config
/opt/local/bin/pcre-config
/opt/local/bin/python2.7-config
/opt/local/bin/xml2-config
/Users/adamg/anaconda/bin/freetype-config
/Users/adamg/anaconda/bin/libdynd-config
/Users/adamg/anaconda/bin/libpng-config
/Users/adamg/anaconda/bin/libpng15-config
/Users/adamg/anaconda/bin/llvm-config
/Users/adamg/anaconda/bin/nc-config
/Users/adamg/anaconda/bin/python-config
/Users/adamg/anaconda/bin/python2-config
/Users/adamg/anaconda/bin/python2.7-config
/Users/adamg/anaconda/bin/xml2-config
/Users/adamg/anaconda/bin/xslt-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2-config
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
Warning: Python is installed at /Library/Frameworks/Python.framework
Homebrew only supports building against the System-provided Python or a
brewed Python. In particular, Pythons installed to /Library can interfere
with other software installs.
To uninstall using brew use this command brew uninstall <package>.
Mac OS X has python preinstalled so there is no need to install another Python instance unless it's necessary.
You can run brew install python to install Python using Homebrew.
Even though python is preinstalled as #jgritty hinted in comments, you may consider not to rely on it for development purposes.
So you should brew uninstall python then brew install python.
In order to remove an installed Python (2.7) instance, you need to run the following commands in your terminal;
sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
sudo rm -rf "/Applications/Python 2.7"
remove the symbolic links in /usr/local/bin that point to this python version see ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7'
if necessary, edit your shell profile file(s) to remove adding /Library/Frameworks/Python.framework/Versions/2.7 to your PATH environment file. Depending on which shell you use, any of the following files may have been modified: ~/bash_login, ~/bash_profile, ~/cshrc, ~/profile, ~/tcshrc, and/or ~/zprofile.
A reference by #Ned Deily available at this link.
You can do brew list to see what brew has installed.
If python and python3 are not in that list, you may want to install either or both.
Based on these files:
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4-config
/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4m-config
I would guess you ran a python 3.4 install downloaded directly from python.org or somewhere else.