[Solved] pyenv fails with : ModuleNotFoundError: No module named ‘_ctypes’ error

After installing 3.9.7 with pyenv, during use

This problem was encountered when installing psycopg2.

Re-execution found no effect.

System python3 import without error

The python3.9.7 installed by pyenv reports an error

After checking the information, you need to install libffi-dev. The ubuntu installation command is as follows:

sudo apt-get install libffi-dev

Installation error: Unable to locate package libffi-dev

sudo apt-get install libffi-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package libffi-dev

Find the problem, you need to modify the source, refer to the address.

https://super-unix.com/ubuntu/ubuntu-unable-to-locate-package-libffi-dev/

https://askubuntu.com/questions/626138/unable-to-locate-package-libffi-dev

After using the above method to simply add the source, it still reports an error: Ubuntu sudo apt get update 404 Not Found problem

Similarly, the example is as follows:

Err:14 http://old-releases.ubuntu.com/ubuntu focal Release
  404 Not Found [IP: 91.189.88.247 80]
Err:15 http://ppa.launchpad.net/team-gcc-arm-embedded/ppa/ubuntu focal Release
  404 Not Found [IP: 91.189.95.85 80]
Err:16 http://old-releases.ubuntu.com/ubuntu focal-updates Release
  404 Not Found [IP: 91.189.88.247 80]
Hit:17 https://linux-clients.seafile.com/seafile-deb/focal stable InRelease
Err:18 http://old-releases.ubuntu.com/ubuntu focal-backports Release
  404 Not Found [IP: 91.189.88.247 80]
Err:19 http://old-releases.ubuntu.com/ubuntu focal-security Release
  404 Not Found [IP: 91.189.88.247 80]
Ign:13 https://launchpad.net/~terry.guo/ +archive/gcc-arm-embedded focal InRelease
Err:20 https://launchpad.net/~terry.guo/ + archive/gcc-arm-embedded focal Release
  404 Not Found [IP: 91.189.89.222 443]

Refer to the answer:

20.04 – Ubuntu sudo apt get update 404 Not Found problem – Ask Ubuntuj?j

Restore sources.list to default

deb http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

deb http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu/ focal-backports main restricted universe multiverse

deb http://archive.canonical.com/ubuntu focal partner
#deb-src http://archive.canonical.com/ubuntu focal partner

Just re-apt-get update

sudo apt-get update

After apt-get is updated

sudo apt-get install libffi-dev

sudo apt-get install libpq-dev python3-dev

After successful installation

pyenv install 3.9.7

Test successful