Skip to main content
433 votes

Change the Python3 default version in Ubuntu

From the comment: sudo update-alternatives --config python Will show you an error: update-alternatives: error: no alternatives for python3 You need to update your update-alternatives , then you ...
GAD3R's user avatar
  • 67.8k
166 votes

zipimport.ZipImportError: can't decompress data; zlib not available

Ubuntu 16.10+ and Python 3.7 dev sudo apt-get install zlib1g-dev Note: I only put this here because it was the top search result for the error, but this resolved my issue. Update: also the case for ...
jmunsch's user avatar
  • 4,396
74 votes

Change the Python3 default version in Ubuntu

You can achieve this by applying below simple steps - Check python version on terminal: python --version Execute this command to switch to python 3.6: sudo update-alternatives --install /usr/bin/...
user12979326's user avatar
56 votes

Is there something wrong with my script or is Bash much slower than Python?

Shell loops are slow and bash's are the slowest. Shells aren't meant to do heavy work in loops. Shells are meant to launch a few external, optimized processes on batches of data. Anyway, I was ...
Petr Skocik's user avatar
  • 29.2k
51 votes
Accepted

How to run a command inside a virtualenv using systemd

This doesn't work because source is a shell command, so systemd's ExecStart= or ExecStartPre= won't understand them directly... (BTW, the same is true for cd and the &&.) You could achieve ...
filbranden's user avatar
  • 22.1k
46 votes

Change the Python3 default version in Ubuntu

if you have multiple version of python in your system. You just need to update the symbolic link of python inside /usr/bin/ root@irshad:/usr/bin# ls -lrth python* lrwxrwxrwx 1 root root 9 Apr 16 ...
IRSHAD's user avatar
  • 687
41 votes
Accepted

How to make python3.7 default

Simple solution is edit .bashrc and put this line: alias python3=python3.7 Whenever you will write python3 it will replace it with python3.7. Or you can use command update-alternatives which is ...
Prvt_Yadav's user avatar
  • 5,942
36 votes

gcc error installing psycopg2 package for python3 on Centos 7.3

For Ubuntu use sudo apt install libpq-dev
aandrukhovich's user avatar
31 votes

"ModuleNotFoundError: No module named 'apt_pkg'" appears in various commands

Original answer from https://askubuntu.com/q/1242009/747557, credit to @Hmdbbgh. The solution that worked for me was to reinstall python3-apt: sudo apt remove python3-apt sudo apt autoremove sudo apt ...
Gal's user avatar
  • 621
27 votes

Change the Python3 default version in Ubuntu

Using these commands can help you: check the version of python: ls /usr/bin/python* alias: alias python='/usr/bin/pythonxx' (add this to . ~/.bashrc) re-login or source . ~/.bashrc check the python ...
Newt's user avatar
  • 419
23 votes
Accepted

How to make `python` an alias of `python3` systemwide on Debian

It looks like Debian is now shipping python-is-python3 themselves (in Debian 11 and later), so the premise of the question no longer holds and you can just: sudo apt update && sudo apt install ...
a3nm's user avatar
  • 9,297
22 votes
Accepted

Difference between installing a package with 'apt' and 'pip'

I will appreciate if someone could explain the differences (if any) between: Highest level: you never should use pip install to install to system (--system, or on Linux distros where --user isn't the ...
Marcus Müller's user avatar
21 votes
Accepted

Is there something wrong with my script or is Bash much slower than Python?

This is a known bug in bash; see the man page and search for "BUGS": BUGS It's too big and too slow. ;) For an excellent primer on the conceptual differences between shell scripting and ...
Wildcard's user avatar
  • 36.8k
18 votes

Is there something wrong with my script or is Bash much slower than Python?

I did a bit of testing, and on my system ran the following--none made the order of magnitude speedup that would be needed to be competitive, but you can make it faster: Test 1: 18.233s #!/bin/bash ...
Erik Brandsberg's user avatar
16 votes
Accepted

cron job to run under conda virtual environment

Posted a working solution (on Ubuntu 18.04) with detailed reasoning on SO. The short form is: 1. Copy snippet appended by Anaconda in ~/.bashrc (at the end of the file) to a separate file ~/....
Jean Monet's user avatar
16 votes
Accepted

How to downgrade python version in Ubuntu 20.04?

Do not downgrade the system version: it's likely that some parts of the system would stop working. Never change /usr/bin/python3, and avoid putting an older version of python3 before it in the $PATH. ...
Gilles 'SO- stop being evil''s user avatar
16 votes
Accepted

If I have two versions of python3 installed on my machine (ie: 3.11.2 and 3.12), how do I set the default version to use when running python scripts?

Since you’re using env python3, the default version of Python will be determined by whichever version of python3 is first in the PATH variable. You can thus choose which version is used by ...
Stephen Kitt's user avatar
14 votes

Change the Python3 default version in Ubuntu

First check that you have a python3.6 folder? ls /usr/bin/python3.6 If you have "python3.6" folder, you are good to go. Now update-alternatives sudo update-alternatives --install /usr/bin/...
mmblack's user avatar
  • 157
14 votes
Accepted

Changing Python's default version breaks Ubuntu 20.04

As you discovered, the system does rely on the system version of Python being as it expects. If you really want a system with Python 3.6, your best bet is to find a (ideally, still supported) release ...
Stephen Kitt's user avatar
13 votes

gcc error installing psycopg2 package for python3 on Centos 7.3

I was missing libpq-fe.h, which I obtained by installing postgresql-devel sudo yum install postgresql-devel
amphibient's user avatar
  • 12.6k
11 votes

Is there something wrong with my script or is Bash much slower than Python?

A shell is efficient if you use it for what it has been designed for (though efficiency is rarely what you look for in a shell). A shell is a command-line interpreter, it is designed to run commands ...
Stéphane Chazelas's user avatar
11 votes
Accepted

The python command starts the the wrong version of the python interpreter

It's very likely that the python command has been hashed and that you need to clear the cache. In order to see what executable is actually being run you can use the type command, e.g.: type -a python ...
igal's user avatar
  • 10k
11 votes

pip hangs on `Loading macOS` when installing a package

I had the same problem, after messing with PyPi credentials. The following fixed it for me. export PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring See: https://github.com/pypa/pip/issues/7883
d43's user avatar
  • 111
11 votes

How to downgrade python version in Ubuntu 20.04?

Alternatively, you can create a virtual environment. Suppose you have python 3.8 (or higher) installed on the system, but for a specific task, you need python 3.7 (or lower). The best idea is (not to ...
Hassan Risvy's user avatar
10 votes

When I use ansible module expect, I get this msg: The pexpect python module is required

As is typical with some of the modules in ansible you have to install certain Python modules on the remote server's side. https://github.com/ansible/ansible/issues/21416 You can use the pip module ...
slm's user avatar
  • 374k
10 votes
Accepted

CentOS python3 package difference between python36 and python36u

python36u is an alternative build provided by IUS; python36 is an EPEL package. yum info python36 python36u will show you different repos for the two, and it's likely that the IUS one has a slightly ...
Ulrich Schwarz's user avatar
10 votes

If I have two versions of python3 installed on my machine (ie: 3.11.2 and 3.12), how do I set the default version to use when running python scripts?

To complement @StephenKitt's fine answer, on Debian-based systems, you may be able to install packages for more than one version of python concurrently. For instance here on Ubuntu 22.04, I have 3.10 ...
Stéphane Chazelas's user avatar
10 votes

If I have two versions of python3 installed on my machine (ie: 3.11.2 and 3.12), how do I set the default version to use when running python scripts?

I know this questions only asks about the apt package manager, and the other answers cover that aspect very well. But if you are working with several different python projects, all requiring different ...
user000001's user avatar
  • 3,715
9 votes
Accepted

Enabling python3 on vim in Fedora 24

The issue is that simply executing has('python') in an if-statement causes python3 to be unavailable when vim was compiled with both python/dyn and python3/dyn. The simplest solution is probably just ...
Josh Brobst's user avatar
  • 1,475
9 votes

zipimport.ZipImportError: can't decompress data; zlib not available

Simply copy paste this code: CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" \ LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew ...
Arayan Singh 's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible