Ubuntu 20.04 upgrade, Python missing libffi.so.6 - python

I recently upgraded my OS to Ubuntu 20.04 LTS.
Now when I try to import a library like Numpy in Python, I get the following error:
ImportError: libffi.so.6: cannot open shared object file: No such file or directory
I tried installing the libffi package, but apt can't locate it :
sudo apt-get install libffi
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libffi

It seems like I fixed it. I could be wrong, but here is what I think happened:
Ubuntu 20.04 upgraded libffi6 to libffi7
Python is still looking for libffi6
What I did to fix it :
Locate libffi.so.7 in your system
$ find /usr/lib -name "libffi.so*"
Create a simlink named libffi.so.6 that points to libffi.so.7:
sudo ln -s /usr/path/to/libffi.so.7 /usr/lib/path/to/libffi.so.6
UPDATE:
As noted by many users, this fix could have unintended consequences. The better way to do it is to reinstall python as #amichaud explained. This should be used as a last resort IF you're not using pyenv/virtualenv/etc in which case removing python will cause a lot of dependencies to be removed as well.

If you are using pyenv, you should just uninstall the used python version and then reinstall it.
Example:
pyenv uninstall 3.7.4
pyenv install 3.7.4
It's cleaner and safer than renaming system library from my point of view.

I am using Xubuntu 20.04 and recompiling the python version 3.7 did not work for me.
The way I solved this was to download the 19.10 version of the package from here:
http://mirrors.kernel.org/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
and then installing it
sudo apt install ./libffi6_3.2.1-8_amd64.deb
This will unpack the libffi.so.6 and libffi.so.6.0.4 files to /usr/lib/x86_64-linux-gnu/. The libffi.so.6 file is just a link to libffi.so.6.0.4 in the same directory.
As far as I could see this does not overwrite any files so should be safe.
Ubuntu 22.04 additional step
As per comment from pijing below, you need to run this command after installing the above:
apt install libffi-devel
Then recompile Python.

Ubuntu 20 has libffi7 installed instead. It's possible to install the previous version using coming from Ubuntu 19.10 (Eoan Ermine) download from here Or you can follow these commands
$ curl -LO http://archive.ubuntu.com/ubuntu/pool/main/libf/libffi/libffi6_3.2.1-8_amd64.deb
$ sudo dpkg -i libffi6_3.2.1-8_amd64.deb

Same problem for me
Upgraded to Ubuntu 20
pip didn't work anymore (same error)
What I did was:
Delete the virtual env I was using
Recreate it
Sure, I wasn't able to do a pip freeze to get save my dependencies (as pip didn't work), but fortunately I didn't care about them.

The libffi6 package may be downloaded and installed as follows:
Identify a source for apt from the list Download Page for libffi6
(I picked http://mirrors.kernel.org/ubuntu/ for instance)
Make a back up of /etc/apt/sources.list (just in case)
Edit /etc/apt/sources.list and add the line (I added it to the very end of the file) ands save the file
deb https://mirrors.kernel.org/ubuntu bionic main
Update to use the new repository
sudo apt update
Finally, install the package:
sudo apt install libffi6
Note that both libffi6 and libffi7 appear to coexist. (My Ubuntu version is 20.04)
$ sudo apt list | grep libffi[67]/
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
libffi6/bionic,now 3.2.1-8 amd64 [installed]
libffi7/focal,now 3.3-4 amd64 [installed,automatic]

I had the same problem (when I upgrded to Ubuntu 20.04) when I tried to run Jupyter Notebook.
Step 1) --> Just re-install python3.7.6 (the version I was using) :
$ cd path_to_python3.7_folder
Do again de installation process:
$ ./configure --enable-optimizations
$ make
$ sudo make install
Step 2: uninstall jupyter. I used pip3.7 uninstall ...
See: How to uninstall Jupyter note book installed by pip3
Step 3: Re-install jupyter again:
$ pip3.7 install jupyterlab
$ pip3.7 install notebook
Try to run jupyter again. It should work.

Symbolic linking to higher version of existing libffi,(e.g. pointing 6 to 8 or 9) does NOT harm since libffi's interface is almost frozen up to 9 years from now.
Higher SO version such as 6,7 or 8, simply it's there to indicate minimum requirement in case of new feature availability such as ffi_tramp_is_present. libffi itself is totally backward compatible so far as of 2022.
Anyone can confirm this by browsing inc folder in https://github.com/libffi/libffi
So, if you are seeing this issue in Ubuntu 22, please feel free to create a symbolic link to highest version of so available in your distro.

The problem with libffi can also be tackled with making a symlink:
sudo ln -s /usr/path/to/libffi.so.8 /usr/lib/path/to/libffi.so.7
Then you get another error in xorg log concerning wayland. What helped me was to reinstall wayland and lib32-wayland. After that I could boot normally (although I use xorg in Cinnamon, but also have Gnome installed)

Related

pip install paramiko comes out with error - ModuleNotFoundError: No module named 'zlib' [duplicate]

I was trying to install Django. Turns out that course's teacher said that we will be working with Python 3.6
I install Python 3.6. Now it's my default, it somewhat replaced the last version I had; which is Python 3.5.
Everything ok until that. But when I want to install Django doing
"pip3 install django", it tells me that the module is already satisfied and therefore installed.
I run "python3" command into my terminal. It runs Python 3.6. I try to import Django, and boom... "No module named 'django'".
Then I realized pip3 was actually installing my modules into Python 3.5 and not 3.6. So what I do is to install pip in Python 3.6.
I download get-pip.py and proceed to execute it with Python 3.6 typing in "python3.6 get-pip.py".
Here is when the damn "zipimport.ZipImportError: can't decompress data; zlib not available" goes in. I've tried a ton of things and no one of them fixed the %^$! problem. I'm really tired.
What I have already tried:
python3.6 -m pip install django, which output is "/usr/local/bin/python3.6: No module named pip"
apt install zlib, which output is "E: Unable to locate package zlib"
apt install zlib1g-dev, which says that it's already installed; the problem persists though.
I also came across this problem (while creating a simple installer for pyenv). Here's how I solved it for Mac and Linux:
Ubuntu 20.04, 18.04
You need the zlib development files, and probably zlib itself too:
sudo apt install -y zlib1g-dev zlibc
If you're missing zlib, it's likely that the next problem you'll run into is with openssl, so it's probably best to get that now as well:
sudo apt install -y libssl-dev
sudo apt install -y libssl1.1 || sudo apt install -y libssl1.0
macOS
I believe this comes with XCode CLI Tools (or at least I didn't have to custom install it Big Sur):
xcode-select --install
For me it worked in RHEL:
$ yum install zlib-devel
Suggested solutions (installing zlib1g-dev or zlib-devel) seem to resolve the issue in most cases. Here is one edge case I've encountered recently: whatever you are trying to run might use zlib via symlink which might be broken.
In my case I was trying to run a build of a 3rd-party software which already had python and all necessary libs being emebedded into it. It was packaged as a tar.gz archive. Unpacking the archive on a Windows machine and then copying the contents to another linux machine destroyed all the symlinks (if you do ls -l in a folder with symlinks you would see that all of them have size 0 and do not point to anything). Copying tar.gz to the linux machine directly and unpacking it there resolved the issue.
P.S. I know it's an edge case scenario but it took me and one more developer quite a while to figure it out so I think it's worth mentioning here, just in case someone gets as unlucky as I got.
Its solves my issue for centos 7.6 :-
yum install zlib-deve

How to install Python 3.6+ version in Kali Linux?

I need help. I newone in Linux OS and in Python at all.
I need to install python interpreter v. 3.6 for my current project. The reason is - lib, that i would like to use doesn't work on 3.7+
I use Pycharm and want to set new environment with interpreter 3.6. I know that i can set it in settings/project/python interpreter. But i can see only python v2,v2.7,v3,v3.9.
How can i add 3.6 version? Please, help)
command apt install python3.6 doen't help me.
└─# apt install python3.6 2 ⨯
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python3.6
E: Couldn't find any package by glob 'python3.6'
About OS:
└─# cat /etc/os-release 127 ⨯
PRETTY_NAME="Kali GNU/Linux Rolling"
NAME="Kali GNU/Linux"
ID=kali
VERSION="2021.1"
VERSION_ID="2021.1"
VERSION_CODENAME="kali-rolling"
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="https://www.kali.org/"
SUPPORT_URL="https://forums.kali.org/"
BUG_REPORT_URL="https://bugs.kali.org/"
Serge Ballesta helped me. Thanks a lot!
Just for silly ubuntu users like me - "how to install some source distribution"
Extract the .tar.gz or (.tar.bz2) file with the following commands
tar xvzf PACKAGENAME.tar.gz
Navigate to the extracted folder using cd command
cd PACKAGENAME
Now run the following command to install the tarball
./configure
sudo make install
Not all Unix distributions offer all Python versions. It is common to only have one Python 2.7.x version and one or two Python 3.y .
Normally Python 3 has a good ascending compatibility, so a Python 3.9 should run a Python 3.6 without any problem. If you really need a specific version, the desperate way is to get a source distribution from python.org and build it locally. The downside is that this one will not participate in apt version control, so it will not be detected by third party application. But it is the only way I know to have a no longer distribution maintained version.
see details: https://pkg.kali.org/pkg/python3.6
[2019-02-05] python3.6 3.6.8-1 removed from kali-rolling (KaliRepository
[2019-01-28] python3.6 3.6.8-1 removed from kali-dev (Kali Repository)
as seen, python3.6 removed than the Kali repository.
please, download the python3.6 using following url
https://www.python.org/downloads/release/python-360/
First remove older version
sudo apt purge -y python2-minimal
Remove unwanted libraries of old version
sudo apt autoremove
install new version
sudo apt install -y python3-pip
latest version of python is successfully installed!
check version
python --version
You can write
$sudo apt-get update
and then run
$sudo apt-get python3.6

Python get-pip.py fails due to site-package not writtable and SSL not available while they seem OK [duplicate]

I've install Python 3.4 and Python 3.6 on my local machine successfully, but am unable to install packages with pip3.
When I execute pip3 install <package>, I get the following SSL related error:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting <package>
Could not fetch URL https://pypi.python.org/simple/<package>/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement <package> (from versions: )
No matching distribution found for <package>
How can I fix my Python3.x install so that I can install packages with pip install <package>?
Step by step guide to install Python 3.6 and pip3 in Ubuntu
Install the necessary packages for Python and ssl: $ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Download and unzip "Python-3.6.8.tar.xz" from https://www.python.org/ftp/python/ into your home directory.
Open terminal in that directory and run: $ ./configure
Build and install: $ make && sudo make install
Install packages with: $ pip3 install package_name
Disclaimer: The above commands are not tested in Ubuntu 20.04 LTS.
If you are on Windows and use anaconda this worked for me:
I tried a lot of other solutions which did not work (Environment PATH Variable changes ...)
The problem can be caused by DLLs in the Windows\System32 folder (e.g. libcrypto-1_1-x64.dll or libssl-1_1-x64.dll or others) placed there by other software.
The fix was installing openSSL from https://slproweb.com/products/Win32OpenSSL.html which replaces the dlls by more recent versions.
If you are on Red Hat/CentOS:
# To allow for building python ssl libs
yum install openssl-devel
# Download the source of *any* python version
cd /usr/src
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar xf Python-3.6.2.tar.xz
cd Python-3.6.2
# Configure the build w/ your installed libraries
./configure
# Install into /usr/local/bin/python3.6, don't overwrite global python bin
make altinstall
I had a similar problem on OSX 10.11 due to installing memcached which installed python 3.7 on top of 3.6.
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Spent hours on unlinking openssl, reinstalling, changing paths.. and nothing helped. Changing openssl version back from to older version did the trick:
brew switch openssl 1.0.2e
I did not see this suggestion anywhere in internet. Hope it serves someone.
In Ubuntu, this can help:
cd Python-3.6.2
./configure --with-ssl
make
sudo make install
Agree with the answer by mastaBlasta. Worked for me. I encountered the same problem as the topic description.
Environment: MacOS Sierra. And I use Homebrew.
My solution:
Reinstall openssl by brew uninstall openssl; brew install openssl
According to the hints given by Homebrew, do the following:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
I had the same issue with python3.8.5 installation on Debian9. I have done a build, but when I have tried to download some modules, pip3.8 issued following error:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
I have searched for the root of my problem and found out that there is a system dependent portion of the python build which is called by system independent one. In case of missing ssl you just needed to open python terminal and check whether is _ssl present:
>>> help('modules')
.
.
_sre enum pwd wave
_ssl errno py_compile weakref
_stat faulthandler pyclbr webbrowser
.
.
If not your system dependent ssl module part is missing. You can check it also by listing content of <python_installation_root>/lib/python3.8/lib-dynload:
>ls ./lib/python3.8/lib-dynload | grep ssl
_ssl.cpython-38-x86_64-linux-gnu.so
The problem was caused as written by PengShaw by missing libssl-dev during the build. Therefore you have to follow the recommended python installation flow. First install prerequisites and then build and install the python. Installation without devel versions of libs resulted in my case in the missing system dependent part. In this case _ssl.
Note that the devel lib name differs for Debian and CentOS, therefore check whether the installation hints posted on net are suitable for your specific Linux system type:
For Debian:
sudo apt install -y libbz2-dev libffi-dev libssl-dev
./configure --enable-optimizations
make
make altinstall
For CentOS:
sudo yum -y install bzip2-devel libffi-devel openssl-devel
./configure --enable-optimizations
make
make altinstall
It is for sure a good idea to list configuration options prior the configuration and evtl. use some additional options:
./configure --help
Last but not least in case you use --prefix for a non-default installation location, remember to add your <python_installation_root>/lib to your LD_LIBRARY_PATH .
If you are on Windows and use Anaconda you can try running "pip install ..." command in Anaconda Prompt instead of cmd.exe, as user willliu1995 suggests here. This was the fastest solution for me, that does not require installation of additional components.
The problem probably caused by library missing.
Before you install python 3.6, make sure you install all the libraries required for python.
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
More information in How to Install Python 3.6.0 on Ubuntu & LinuxMint
If you are on OSX and have compiled python from source:
Install openssl using brew brew install openssl
Make sure to follow the instructions brew gives you about setting your CPPFLAGS and LDFLAGS. In my case I am using the openssl#1.1 brew formula and I need these 3 settings for the python build process to correctly link to my SSL library:
export LDFLAGS="-L/usr/local/opt/openssl#1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl#1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl#1.1/lib/pkgconfig"
Assuming the library is installed at that location.
Downgrading openssl worked for me,
brew switch openssl 1.0.2s
I encountered the same problem on windows 10. My very specific issue is due to my installation of Anaconda. I installed Anaconda and under the path Path/to/Anaconda3/, there comes the python.exe. Thus, I didn't install python at all because Anaconda includes python. When using pip to install packages, I found the same error report, pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available..
The solution was the following:
1) you can download python again on the official website;
2) Navigate to the directory where "Python 3.7 (64-bit).lnk"is located
3) import ssl and exit()
4) type in cmd, "Python 3.7 (64-bit).lnk" -m pip install tensorflow for instance.
Here, you're all set.
I tried A LOT of ways to solve this problem and none solved. I'm currently on Windows 10.
The only thing that worked was:
Uninstall Anaconda
Uninstall Python (i was using version 3.7.3)
Install Python again (remember to check the option to automatically add to PATH)
Then I've downloaded all the libs I needed using PIP... and worked!
Don't know why, or if the problem was somehow related to Anaconda.
for osx brew users
my issue appeared related to my python installation and was quickly resolved by re-installing python3 and pip. i think it started misbehaving after an OS update but who knows (at this time I am on Mac OS 10.14.6)
brew reinstall python3 --force
# setup pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
# installa pkg successfully
pip install pandas
You can do either of these two:
While installing Anaconda, select the option to add Anaconda to the path.
or
Find these (complete) paths from your installation folder of Anaconda and add them to the environment variable :
\Anaconda
\Anaconda\Library\mingw-w64\bin
\Anaconda\Library\usr\bin
\Anaconda\Library\bin
\Anaconda\Scripts
\anaconda\Library
\anaconda\condabin
Add the above paths to the "Path" system variable and it should show the error no more :)
The ssl module is a TLS/SSL wrapper for accessing Operation Sytem (OS) socket (Lib/ssl.py). So when ssl module is not available, chances are that you either don't have OS OpenSSL libraries installed, or those libraries were not found when you install Python. Let assume it is a later case (aka: you already have OpenSSL installed, but they are not correctly linked when installing Python).
I will also assume you are installing from source. If you are installing from binary (ie: Window .exe file), or package (Mac .dmg, or Ubuntu apt), there is not much you can do with the installing process.
During the step of configuring your python installation, you need to specify where the OS OpenSSL will be used for linking:
# python 3.8 beta
./configure --with-openssl="your_OpenSSL root"
So where will you find your installed OpenSSL directory?
# ubuntu
locate ssl.h | grep '/openssl/ssl.h'
/home/user/.linuxbrew/Cellar/openssl/1.0.2r/include/openssl/ssl.h
/home/user/envs/py37/include/openssl/ssl.h
/home/user/miniconda3/envs/py38b3/include/openssl/ssl.h
/home/user/miniconda3/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.0.2s-h7b6447c_0/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1b-h7b6447c_1/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1c-h7b6447c_1/include/openssl/ssl.h
/usr/include/openssl/ssl.h
Your system may be different than mine, but as you see here I have many different installed openssl libraries. As the time of this writing, python 3.8 expects openssl 1.0.2 or 1.1:
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
So you would need to verify which of those installed libraries that you can use for linking, for example
/usr/bin/openssl version
OpenSSL 1.0.2g 1 Mar 2016
./configure --with-openssl="/usr"
make && make install
You may need to try a few, or install a new, to find the library that would work for your Python and your OS.
I was having the same issue and was able to resolve with the following steps:
sudo yum install -y libffi-devel
sudo yum install openssl-devel
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
sudo tar xf Python-3.7.1.tar.xz
cd Python-3.7.1
sudo ./configure --enable-optimizations
# Install into /usr/local/bin/python3.7, don't overwrite global python bin
sudo make altinstall
depending on perms, you may not need sudo.
Results:
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1
should now be able to run
python3.7 -V
and
pip3.7 -V
When installing packages:
pip3.7 install pandas
or depending on perms, you can also add the --user flag like so:
pip3.7 install pandas --user
In my case with using Mac, I deleted
/Applications/Python 3.7.
because I already had Python3.7 by brew install python3 .
But it was a trigger of the message
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
What I did in my situation
I downloaded macOS 64-bit installer again, and installed.
Double click /Applications/Python3.6/Install Certificates.command and /Applications/Python3.6/Update Shell Profile.command.
Reboot mac
And I am not sure but possibly contributed to succeed is pip.conf. See pip install fails.
I finally solve this issue. These are the detail of my env:
Version of Python to install: 3.6.8
OS: Ubuntu 16.04.6 LTS
Root access: No
Some people suggest to install libssl-dev, but it did not work for me. I follow this link and I fixed it!
In short, I download, extract, build, and install OpenSSL (openssl-1.1.1b.tar.gz). Then, I modify .bashrc file follow this link.
Next, I download and extract Python-3.6.8.tgz. I edit Modules/Setup.dist to modify SSL path (lines around #211). I did ./configure --prefix=$HOME/opt/python-3.6.8, make and make install. Last, I modify my .bashrc. Notice that I do not include --enable-optimizations in ./configure.
I was able to fix this by updating the python version in this file.
pyenv: version `3.6.5' is not installed (set by /Users/taruntarun/.python-version)
Though i had the latest version installed, my command was still using old version 3.6.5
Moving to version 3.7.3
Termux
This worked because i didnt have an existing openssl version installed.
pkg install openssl-tool
If you are on OSX and in case the other solutions didn't work for you (just like me).
You can try uninstalling python3 and upgrade pip3
brew uninstall --ignore-dependencies python3
pip3 install --upgrade pip
This worked for me ;)
(NOT on Windows!)
This made me tear my hair out for a week, so I hope this will help someone
I tried everything short of re-installing Anaconda and/or Jupyter.
Setup
AWS Linux
Manually installed Anaconda 3-5.3.0
Python3 (3.7) was running inside anaconda (ie, ./anaconda3/bin/python)
there was also /usr/bin/python and /usr/bin/python3 (but these were not being used as most of the work was done in Jupyter's terminal)
Fix
In Jupyter's terminal:
cp /usr/lib64/libssl.so.10 ./anaconda3/lib/libssl.so.1.0.0
cp /usr/lib64/libcrypto.so.10 ./anaconda3/lib/libcrypto.so.1.0.0
What triggered this?
So, this was all working until I tried to do a conda install conda-forge
I'm not sure what happened, but conda must have updated openssl on the box (I'm guessing) so after this, everything broke.
Basically, unknown to me, conda had updated openssl, but somehow deleted the old libraries and replaced it with libssl.so.1.1 and libcrypto.so.1.1.
Python3, I guess, was compiled to look for libssl.so.1.0.0
In the end, the key to diagnosis was this:
python -c "import ssl; print (ssl.OPENSSL_VERSION)"
gave the clue library "libssl.so.1.0.0" not found
The huge assumption I made is that the yum version of ssl is the same as the conda version, so just renaming the shared object might work, and it did.
My other solution was to re-compile python, re-install anaconda, etc, but in the end I'm glad I didn't need to.
Hope this helps you guys out.
In the case of using pyenv to manage python installations on Mac OS Catalina, I had to install openssl with brew first and then after that run pyenv install 3.7.8 which seemed to build the python installation using the openssl from homebrew (it even said as such in the installation output). Then pyenv global 3.7.8 and I was away.
On macos, configure python 3.8.1 with the command below will solve the problem, i think it would also work on Linux.
./configure --enable-optimizations --with-openssl=/usr/local/opt/openssl#1.1/
change the dir parameter based on your system.
I've made some PATH changes to mimic part of the Anaconda Powershell Prompt $env:PATH
C:\Users\merheb\Miniconda3;C:\Users\merheb\Miniconda3\Library\mingw-w64\bin;C:\Users\merheb\Miniconda3\Library\usr\bin;C:\Users\merheb\Miniconda3\Library\bin;C:\Users\merheb\Miniconda3\Scripts;C:\Users\merheb\Miniconda3\bin;C:\Users\merheb\Miniconda3\condabin;
And It worked for me.
Building from source was what worked for me on Ubuntu 22.10:
Install OpenSSL manually, tested here with OpenSSL 1.1.1s, extracted then ran:
./config --prefix='/opt/openssl' --openssldir='/opt/ssl'
make
make install
Then with your older Python 3 version (here Python-3.8.16) run:
export LD_RUN_PATH='/opt/openssl/lib'
export CC='gcc-12' # sudo apt install gcc-12
./configure --enable-optimizations \
--with-openssl='/opt/openssl' \
--prefix='/opt/python/3.8' -C
make
make install
Test with:
/opt/python/3.8/bin/python3 -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 1.1.1s 1 Nov 2022
The python documentation is actually very clear, and following the instructions did the job whereas other answers I found here were not fixing this issue.
first, install python 3.x.x from source using, for example with version 3.6.2 https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
make sure you have openssl installed by running brew install openssl
unzip it and move to the python directory: tar xvzf Python-3.6.2.tar.xz && cd Python-3.6.2
then if the python version is < 3.7, run
CPPFLAGS="-I$(brew --prefix openssl)/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib" \
./configure --with-pydebug
5. finallly, run make -s -j2 (-s is the silent flag, -j2 tells your machine to use 2 jobs)
I had the same issue trying to install python3.7 on an ubuntu14.04 machine.
The issue was that I had some custom folders in my PKG_CONFIG_PATH and in my LD_LIBRARY_PATH, which prevented the python build process to find the system openssl libraries.
so try to clear them and see what happens:
export PKG_CONFIG_PATH=""
export LD_LIBRARY_PATH=""
Ok the latest answer to this, as of now don't use Python 3.8, use only 3.7 or less , because of most of the libraries fail to install with the above error

ModuleNotFoundError: No module named 'distutils.core'

I've recently upgraded from Ubuntu 18.04 to 19.04 which has python 3.7. But I work on many projects using Python 3.6.
Now when I try to create a virtualenv with Python 36 in PyCharm, it raises:
ModuleNotFoundError: No module named 'distutils.core'
I can't figure out what to do.
I tried to install distutils:
milano#milano-PC:~$ sudo apt-get install python3-distutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-distutils is already the newest version (3.7.3-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
But as you can see I have the newest version.
Do you know what to do?
Python base interpreter does require some additional modules. Those are not installed with e.g. Ubuntu 18.04 as default.
To solve this we need to first find the python version you're running. If you have only installed one python version on your system (and you are sure about it) you can skip this step.
# from your project interpreter run
# your_project_python --version
$ python3 --version
Python 3.7.8
You now need to install for this precise python interpreter the distutils.
So here the solution for this example would be:
sudo apt install python3.7-distutils
# sudo apt install python3-distutils # would just update default python intrpreter
Keep in mind, that just running python from any command line might be an other version of python then you're running in your project!
If this hasn't helped, look for the following possibilities. This will bring you the binary which resolved from the alias in the command line.
$ which python
/usr/bin/python
$ ls -lach /usr/bin/python
lrwxrwxrwx 1 root root 9 Jun 8 2018 /usr/bin/python -> python2.7
original source: refer to this article
For this answer I've also merged, summarized, ordered and explained some of the content which has been provided by Neo, Andrei, Mostafa and Wolfgang.
As a side note for sorcerer's apprentice: You might be tempted to uninstall python interpreters. For proposed solution not necessary at all!! How ever, keep in mind that there is one python interpreter which your whole OS depends on. So this default one, you don't want to uninstall. If you do so, you're in a certain mess in finding your desktop taskbar and basically everything.
If I have multiple versions of python3 (etc 3.8 as main and 3.9 from ppa:deadsnakes/ppa) on ubuntu 20.04 (in my case kubuntu 20.04) and it doesn't work
sudo apt install python3-distutils
then it works for me
sudo apt install python3.9-distutils
Other Cases
This happened on my python3.7 installation but not my main python3 after i upgrade my ubuntu to 20.04
Solution:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt install python3.7
Currently, I'm using ubuntu 18.04 and python 3.6.9. My problem was solved after running the following command as mentioned here:
sudo apt-get install python3-dev
More Details: Some modules in python are needed that not installed.
For me the problem was solved by specifically using python3 thus making sure python3.8 was used
python --version
Python 3.7.5
python3 --version
Python 3.8.5
I still got error message after trying to install python3.9-distutils for python version 3.9 in pipenv.
As I noticed here python3.9-distutils is in conflict with earlier versions of that package and cannot be installed on Ubuntu18.04.
I move on by using python_version = "3.6" with pipenv otherwise $ pipenv install would take the highest version of python and write it in the Pipfile and Pipfile.lock.
$ pipenv --rm #To remove the old environment
$ rm Pipfile* #Remove both Pipfiles
$ pipenv install --python 3.6

Problems with Python installing anything [duplicate]

I've install Python 3.4 and Python 3.6 on my local machine successfully, but am unable to install packages with pip3.
When I execute pip3 install <package>, I get the following SSL related error:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting <package>
Could not fetch URL https://pypi.python.org/simple/<package>/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement <package> (from versions: )
No matching distribution found for <package>
How can I fix my Python3.x install so that I can install packages with pip install <package>?
Step by step guide to install Python 3.6 and pip3 in Ubuntu
Install the necessary packages for Python and ssl: $ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Download and unzip "Python-3.6.8.tar.xz" from https://www.python.org/ftp/python/ into your home directory.
Open terminal in that directory and run: $ ./configure
Build and install: $ make && sudo make install
Install packages with: $ pip3 install package_name
Disclaimer: The above commands are not tested in Ubuntu 20.04 LTS.
If you are on Windows and use anaconda this worked for me:
I tried a lot of other solutions which did not work (Environment PATH Variable changes ...)
The problem can be caused by DLLs in the Windows\System32 folder (e.g. libcrypto-1_1-x64.dll or libssl-1_1-x64.dll or others) placed there by other software.
The fix was installing openSSL from https://slproweb.com/products/Win32OpenSSL.html which replaces the dlls by more recent versions.
If you are on Red Hat/CentOS:
# To allow for building python ssl libs
yum install openssl-devel
# Download the source of *any* python version
cd /usr/src
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar xf Python-3.6.2.tar.xz
cd Python-3.6.2
# Configure the build w/ your installed libraries
./configure
# Install into /usr/local/bin/python3.6, don't overwrite global python bin
make altinstall
I had a similar problem on OSX 10.11 due to installing memcached which installed python 3.7 on top of 3.6.
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Spent hours on unlinking openssl, reinstalling, changing paths.. and nothing helped. Changing openssl version back from to older version did the trick:
brew switch openssl 1.0.2e
I did not see this suggestion anywhere in internet. Hope it serves someone.
In Ubuntu, this can help:
cd Python-3.6.2
./configure --with-ssl
make
sudo make install
Agree with the answer by mastaBlasta. Worked for me. I encountered the same problem as the topic description.
Environment: MacOS Sierra. And I use Homebrew.
My solution:
Reinstall openssl by brew uninstall openssl; brew install openssl
According to the hints given by Homebrew, do the following:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
I had the same issue with python3.8.5 installation on Debian9. I have done a build, but when I have tried to download some modules, pip3.8 issued following error:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
I have searched for the root of my problem and found out that there is a system dependent portion of the python build which is called by system independent one. In case of missing ssl you just needed to open python terminal and check whether is _ssl present:
>>> help('modules')
.
.
_sre enum pwd wave
_ssl errno py_compile weakref
_stat faulthandler pyclbr webbrowser
.
.
If not your system dependent ssl module part is missing. You can check it also by listing content of <python_installation_root>/lib/python3.8/lib-dynload:
>ls ./lib/python3.8/lib-dynload | grep ssl
_ssl.cpython-38-x86_64-linux-gnu.so
The problem was caused as written by PengShaw by missing libssl-dev during the build. Therefore you have to follow the recommended python installation flow. First install prerequisites and then build and install the python. Installation without devel versions of libs resulted in my case in the missing system dependent part. In this case _ssl.
Note that the devel lib name differs for Debian and CentOS, therefore check whether the installation hints posted on net are suitable for your specific Linux system type:
For Debian:
sudo apt install -y libbz2-dev libffi-dev libssl-dev
./configure --enable-optimizations
make
make altinstall
For CentOS:
sudo yum -y install bzip2-devel libffi-devel openssl-devel
./configure --enable-optimizations
make
make altinstall
It is for sure a good idea to list configuration options prior the configuration and evtl. use some additional options:
./configure --help
Last but not least in case you use --prefix for a non-default installation location, remember to add your <python_installation_root>/lib to your LD_LIBRARY_PATH .
If you are on Windows and use Anaconda you can try running "pip install ..." command in Anaconda Prompt instead of cmd.exe, as user willliu1995 suggests here. This was the fastest solution for me, that does not require installation of additional components.
The problem probably caused by library missing.
Before you install python 3.6, make sure you install all the libraries required for python.
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
More information in How to Install Python 3.6.0 on Ubuntu & LinuxMint
If you are on OSX and have compiled python from source:
Install openssl using brew brew install openssl
Make sure to follow the instructions brew gives you about setting your CPPFLAGS and LDFLAGS. In my case I am using the openssl#1.1 brew formula and I need these 3 settings for the python build process to correctly link to my SSL library:
export LDFLAGS="-L/usr/local/opt/openssl#1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl#1.1/include"
export PKG_CONFIG_PATH="/usr/local/opt/openssl#1.1/lib/pkgconfig"
Assuming the library is installed at that location.
Downgrading openssl worked for me,
brew switch openssl 1.0.2s
I encountered the same problem on windows 10. My very specific issue is due to my installation of Anaconda. I installed Anaconda and under the path Path/to/Anaconda3/, there comes the python.exe. Thus, I didn't install python at all because Anaconda includes python. When using pip to install packages, I found the same error report, pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available..
The solution was the following:
1) you can download python again on the official website;
2) Navigate to the directory where "Python 3.7 (64-bit).lnk"is located
3) import ssl and exit()
4) type in cmd, "Python 3.7 (64-bit).lnk" -m pip install tensorflow for instance.
Here, you're all set.
I tried A LOT of ways to solve this problem and none solved. I'm currently on Windows 10.
The only thing that worked was:
Uninstall Anaconda
Uninstall Python (i was using version 3.7.3)
Install Python again (remember to check the option to automatically add to PATH)
Then I've downloaded all the libs I needed using PIP... and worked!
Don't know why, or if the problem was somehow related to Anaconda.
for osx brew users
my issue appeared related to my python installation and was quickly resolved by re-installing python3 and pip. i think it started misbehaving after an OS update but who knows (at this time I am on Mac OS 10.14.6)
brew reinstall python3 --force
# setup pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py
# installa pkg successfully
pip install pandas
You can do either of these two:
While installing Anaconda, select the option to add Anaconda to the path.
or
Find these (complete) paths from your installation folder of Anaconda and add them to the environment variable :
\Anaconda
\Anaconda\Library\mingw-w64\bin
\Anaconda\Library\usr\bin
\Anaconda\Library\bin
\Anaconda\Scripts
\anaconda\Library
\anaconda\condabin
Add the above paths to the "Path" system variable and it should show the error no more :)
The ssl module is a TLS/SSL wrapper for accessing Operation Sytem (OS) socket (Lib/ssl.py). So when ssl module is not available, chances are that you either don't have OS OpenSSL libraries installed, or those libraries were not found when you install Python. Let assume it is a later case (aka: you already have OpenSSL installed, but they are not correctly linked when installing Python).
I will also assume you are installing from source. If you are installing from binary (ie: Window .exe file), or package (Mac .dmg, or Ubuntu apt), there is not much you can do with the installing process.
During the step of configuring your python installation, you need to specify where the OS OpenSSL will be used for linking:
# python 3.8 beta
./configure --with-openssl="your_OpenSSL root"
So where will you find your installed OpenSSL directory?
# ubuntu
locate ssl.h | grep '/openssl/ssl.h'
/home/user/.linuxbrew/Cellar/openssl/1.0.2r/include/openssl/ssl.h
/home/user/envs/py37/include/openssl/ssl.h
/home/user/miniconda3/envs/py38b3/include/openssl/ssl.h
/home/user/miniconda3/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.0.2s-h7b6447c_0/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1b-h7b6447c_1/include/openssl/ssl.h
/home/user/miniconda3/pkgs/openssl-1.1.1c-h7b6447c_1/include/openssl/ssl.h
/usr/include/openssl/ssl.h
Your system may be different than mine, but as you see here I have many different installed openssl libraries. As the time of this writing, python 3.8 expects openssl 1.0.2 or 1.1:
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
So you would need to verify which of those installed libraries that you can use for linking, for example
/usr/bin/openssl version
OpenSSL 1.0.2g 1 Mar 2016
./configure --with-openssl="/usr"
make && make install
You may need to try a few, or install a new, to find the library that would work for your Python and your OS.
I was having the same issue and was able to resolve with the following steps:
sudo yum install -y libffi-devel
sudo yum install openssl-devel
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz
sudo tar xf Python-3.7.1.tar.xz
cd Python-3.7.1
sudo ./configure --enable-optimizations
# Install into /usr/local/bin/python3.7, don't overwrite global python bin
sudo make altinstall
depending on perms, you may not need sudo.
Results:
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-10.0.1 setuptools-39.0.1
should now be able to run
python3.7 -V
and
pip3.7 -V
When installing packages:
pip3.7 install pandas
or depending on perms, you can also add the --user flag like so:
pip3.7 install pandas --user
In my case with using Mac, I deleted
/Applications/Python 3.7.
because I already had Python3.7 by brew install python3 .
But it was a trigger of the message
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
What I did in my situation
I downloaded macOS 64-bit installer again, and installed.
Double click /Applications/Python3.6/Install Certificates.command and /Applications/Python3.6/Update Shell Profile.command.
Reboot mac
And I am not sure but possibly contributed to succeed is pip.conf. See pip install fails.
I finally solve this issue. These are the detail of my env:
Version of Python to install: 3.6.8
OS: Ubuntu 16.04.6 LTS
Root access: No
Some people suggest to install libssl-dev, but it did not work for me. I follow this link and I fixed it!
In short, I download, extract, build, and install OpenSSL (openssl-1.1.1b.tar.gz). Then, I modify .bashrc file follow this link.
Next, I download and extract Python-3.6.8.tgz. I edit Modules/Setup.dist to modify SSL path (lines around #211). I did ./configure --prefix=$HOME/opt/python-3.6.8, make and make install. Last, I modify my .bashrc. Notice that I do not include --enable-optimizations in ./configure.
I was able to fix this by updating the python version in this file.
pyenv: version `3.6.5' is not installed (set by /Users/taruntarun/.python-version)
Though i had the latest version installed, my command was still using old version 3.6.5
Moving to version 3.7.3
Termux
This worked because i didnt have an existing openssl version installed.
pkg install openssl-tool
If you are on OSX and in case the other solutions didn't work for you (just like me).
You can try uninstalling python3 and upgrade pip3
brew uninstall --ignore-dependencies python3
pip3 install --upgrade pip
This worked for me ;)
(NOT on Windows!)
This made me tear my hair out for a week, so I hope this will help someone
I tried everything short of re-installing Anaconda and/or Jupyter.
Setup
AWS Linux
Manually installed Anaconda 3-5.3.0
Python3 (3.7) was running inside anaconda (ie, ./anaconda3/bin/python)
there was also /usr/bin/python and /usr/bin/python3 (but these were not being used as most of the work was done in Jupyter's terminal)
Fix
In Jupyter's terminal:
cp /usr/lib64/libssl.so.10 ./anaconda3/lib/libssl.so.1.0.0
cp /usr/lib64/libcrypto.so.10 ./anaconda3/lib/libcrypto.so.1.0.0
What triggered this?
So, this was all working until I tried to do a conda install conda-forge
I'm not sure what happened, but conda must have updated openssl on the box (I'm guessing) so after this, everything broke.
Basically, unknown to me, conda had updated openssl, but somehow deleted the old libraries and replaced it with libssl.so.1.1 and libcrypto.so.1.1.
Python3, I guess, was compiled to look for libssl.so.1.0.0
In the end, the key to diagnosis was this:
python -c "import ssl; print (ssl.OPENSSL_VERSION)"
gave the clue library "libssl.so.1.0.0" not found
The huge assumption I made is that the yum version of ssl is the same as the conda version, so just renaming the shared object might work, and it did.
My other solution was to re-compile python, re-install anaconda, etc, but in the end I'm glad I didn't need to.
Hope this helps you guys out.
In the case of using pyenv to manage python installations on Mac OS Catalina, I had to install openssl with brew first and then after that run pyenv install 3.7.8 which seemed to build the python installation using the openssl from homebrew (it even said as such in the installation output). Then pyenv global 3.7.8 and I was away.
On macos, configure python 3.8.1 with the command below will solve the problem, i think it would also work on Linux.
./configure --enable-optimizations --with-openssl=/usr/local/opt/openssl#1.1/
change the dir parameter based on your system.
I've made some PATH changes to mimic part of the Anaconda Powershell Prompt $env:PATH
C:\Users\merheb\Miniconda3;C:\Users\merheb\Miniconda3\Library\mingw-w64\bin;C:\Users\merheb\Miniconda3\Library\usr\bin;C:\Users\merheb\Miniconda3\Library\bin;C:\Users\merheb\Miniconda3\Scripts;C:\Users\merheb\Miniconda3\bin;C:\Users\merheb\Miniconda3\condabin;
And It worked for me.
Building from source was what worked for me on Ubuntu 22.10:
Install OpenSSL manually, tested here with OpenSSL 1.1.1s, extracted then ran:
./config --prefix='/opt/openssl' --openssldir='/opt/ssl'
make
make install
Then with your older Python 3 version (here Python-3.8.16) run:
export LD_RUN_PATH='/opt/openssl/lib'
export CC='gcc-12' # sudo apt install gcc-12
./configure --enable-optimizations \
--with-openssl='/opt/openssl' \
--prefix='/opt/python/3.8' -C
make
make install
Test with:
/opt/python/3.8/bin/python3 -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 1.1.1s 1 Nov 2022
The python documentation is actually very clear, and following the instructions did the job whereas other answers I found here were not fixing this issue.
first, install python 3.x.x from source using, for example with version 3.6.2 https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
make sure you have openssl installed by running brew install openssl
unzip it and move to the python directory: tar xvzf Python-3.6.2.tar.xz && cd Python-3.6.2
then if the python version is < 3.7, run
CPPFLAGS="-I$(brew --prefix openssl)/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib" \
./configure --with-pydebug
5. finallly, run make -s -j2 (-s is the silent flag, -j2 tells your machine to use 2 jobs)
I had the same issue trying to install python3.7 on an ubuntu14.04 machine.
The issue was that I had some custom folders in my PKG_CONFIG_PATH and in my LD_LIBRARY_PATH, which prevented the python build process to find the system openssl libraries.
so try to clear them and see what happens:
export PKG_CONFIG_PATH=""
export LD_LIBRARY_PATH=""
Ok the latest answer to this, as of now don't use Python 3.8, use only 3.7 or less , because of most of the libraries fail to install with the above error

Categories

Resources