Reputation: 585
I'm trying to install pyautogui, but pip keeps throwing errors. How to fix it? I've tried installing libffi library. Here is some code:
python3 -m pip install pyautogui
Defaulting to user installation because normal site-packages is not writeable
Collecting pyautogui
Using cached PyAutoGUI-0.9.50.tar.gz (57 kB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sxm4ewnq/pyautogui/setup.py'"'"'; __file__='"'"'/tmp/pip-install-sxm4ewnq/pyautogui/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-85ugzov6
cwd: /tmp/pip-install-sxm4ewnq/pyautogui/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 19, in <module>
from setuptools.dist import Distribution
File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/local/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
That's from python REPL
>>> sys.path
['', '/home/walenty/apps/Python-3.8.5/Modules/_ctypes', '/usr/local/lib/python38.zip', '/usr/local/lib/python3.8', '/usr/local/lib/python3.8/lib-dynload', '/home/walenty/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/site-packages']
>>> import _ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '_ctypes'
Upvotes: 8
Views: 40937
Reputation: 358
Note if you are using an HPC cluster or similar where you don't have sudo access, try module spider python
, then module load python/version
to load a suitable python version.
You won't have to compile, meaning you won't have to install libffi-dev
Upvotes: 0
Reputation: 7088
Install foreign function interface headers
sudo apt install libffi-dev
Substitute desired python version
sudo add-apt-repository ppa:deadsnakes/ppa -y && sudo apt install --reinstall python3.9-distutils
Use brew install python3.9
or port install python3.9
(I recommend port)
Use Microsoft Store
poetry env use 3.9
virtualenv -p python3.9 myproject
etc...
Upvotes: 6
Reputation: 144
As other answers say, you need to install libffi-dev. If you're using pyenv/virtualenv, also reinstall the base python version:
Install libffi
sudo apt-get install libffi-dev
Load the new libffi.so, as suggested here
sudo ldconfig
Reinstall the python version available to pyenv
pyenv install 3.9.12
Finally, create the fresh virtualenv
pyenv virtualenv 3.9.12 new_environment
Upvotes: 3
Reputation: 585
okay, I've got it. This is the answer Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing
I cloned python3.10 from git and installed it from scratch.
Upvotes: 3