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'
Required
Install foreign function interface headers
sudo apt install libffi-dev
Reinstall Python
Substitute desired python version
Ubuntu
sudo add-apt-repository ppa:deadsnakes/ppa -y && sudo apt reinstall python3.9-distutils
MacOS
Use brew install python3.9 or port install python3.9 (I recommend port)
Windows
Use Microsoft Store
Specify project python version
Poetry
poetry env use 3.9
Virtual envs
virtualenv -p python3.9 myproject
etc...
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.
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
Related
Can't import Quartz package.
I have installed it with this command pip install pyobjc-framework-Quartz. Tried reinstalling python, also tried python -m pip install .... With python2 or sudo python3, everything works fine but python3 is giving me this error message every time I try importing Quartz
Python version - 3.10.4
Mac version - Big Sur 11.6.5
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import Quartz
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Quartz/__init__.py", line 6, in <module>
import AppKit
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/AppKit/__init__.py", line 10, in <module>
import Foundation
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Foundation/__init__.py", line 9, in <module>
import CoreFoundation
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/CoreFoundation/__init__.py", line 9, in <module>
import objc
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/__init__.py", line 6, in <module>
from . import _objc
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so, 2): Symbol not found: _FSPathMakeRef
Referenced from: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so
For investigation purposes, can you try :
cd /tmp
python3 -m venv venv
source venv/bin/activate
pip install pyobjc-framework-Quartz
python your-script.py
Can you try this to see if it works :
env -i /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 my_script.py
You may have files only accessible by root, try to change ownership:
sudo chown -R $(id -u):$(id -g) /Library/Frameworks/Python.framework/Versions/3.10
and run env -i ... again.
If you run :
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -c 'import sys;print(sys.path)'
sudo /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -c 'import sys;print(sys.path)'
Is there any difference between the two ?
Try following to see if it improves :
sudo /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -m pip install pyobjc-framework-Quartz
Try this to see if there is anything unusual :
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -X importtest -v -c 'import Quartz'
You might need to try:
python3 -m pip install [...]
Hope this will hope.
in ubuntu 18.04, when i change default python from python 3.6 to other version by this command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
or when i remove python 3.6 and install other version netplan apply not working and result this error:
File "/usr/sbin/netplan", line 20, in <module>
from netplan import Netplan
File "/usr/share/netplan/netplan/__init__.py", line 18, in <module>
from netplan.cli.core import Netplan
File "/usr/share/netplan/netplan/cli/core.py", line 24, in <module>
import netplan.cli.utils as utils
File "/usr/share/netplan/netplan/cli/utils.py", line 25, in <module>
import netifaces
ModuleNotFoundError: No module named 'netifaces'
and command pip install netifaces has some errors.
I faced the same issue before with vagrant. If you use update-alternatives to make python3 alias points to another version of Python, vagrant will not work. You cannot use update-alternatives to change the alias of Python3.
For some reason I lost my python configuration after an update made by my ubuntu server,solved by:
Checking if I could import the module so on CLI:
python
import python
After getting the same message I realize my python environment was falling to use the modules even when it all showed up as installed I went ahead and "upgrade" the python modules:
python pip install --upgrade pip
python pip install --upgrade netifaces
python pip install --upgrade "any module you need to use for your script"
And just like that modules were recognized updated and properly install.
tl;dr: Create a link netifaces.so to netifaces.cpython-36m-x86_64-linux-gnu.so in /usr/lib/python3/
In /usr/lib/python3/dist-packages/ is only a module for python3.6:
vagrant#ubuntu18.04:~$ find /usr/lib/python3/dist-packages/ -type f -name netifaces\*
/usr/lib/python3/dist-packages/netifaces.cpython-36m-x86_64-linux-gnu.so
That's why importing 'netifaces' failes for python3.8 while it works for python3.6:
vagrant#ubuntu18.04:~$ python3.6 -c 'import netifaces; print("works!")'
works!
vagrant#ubuntu18.04:~$ python3.8 -c 'import netifaces; print("works!")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'netifaces'
One can link to it with a more unspecific name so python3.8 can find and use it:
vagrant#ubuntu18.04:~$ sudo ln -s /usr/lib/python3/dist-packages/netifaces.cpython-36m-x86_64-linux-gn
u.so /usr/lib/python3/dist-packages/netifaces.so
vagrant#ubuntu18.04:~$ python3.8 -c 'import netifaces; print("works!")'
works!
Hint: I had to do the same for apt_pkg.so → apt_pkg.cpython-36m-x86_64-linux-gnu.so
I tried to install scrapy by "pip install scrapy", and I got:
c:\python36\python.exe -u -c "import setuptools,
tokenize;__file__='C:\\Users\\tzvia\\AppData\\Local\\Temp\\pip-install-
07h63108\\Twisted\\setup.py';f=getattr(tokenize, 'open', open)
(__file__);code=f.read().replace('\r\n',
'\n');f.close();exec(compile(code, __file__, 'exec'))" install --record
C:\Users\tzvia\AppData\Local\Temp\pip-record-hy8qkma1\install-record.txt
--single-version-externally-managed --compile" failed with error code 1
in C:\Users\tzvia\AppData\Local\Temp\pip-install-07h63108\Twisted\
I tried "conda install -c conda-forge scrapy" and it seems like the scrapy already installed:
C:\Users\tzvia>conda install -c conda-forge scrapy
Solving environment: done
# All requested packages already installed.
so I tried using scrapy and go an error:
C:\Users\tzvia>scrapy
Traceback (most recent call last):
File "C:\Users\tzvia\Anaconda3\Scripts\scrapy-script.py", line 6, in
<module>
from scrapy.cmdline import execute
File "C:\Users\tzvia\Anaconda3\lib\site-packages\scrapy\__init__.py", line
34, in <module>
from scrapy.spiders import Spider
File "C:\Users\tzvia\Anaconda3\lib\site-packages\scrapy\spiders\__init__.py", line 10, in <module>
from scrapy.http import Request
File "C:\Users\tzvia\Anaconda3\lib\site-packages\scrapy\http\__init__.py", line 11, in <module>
from scrapy.http.request.form import FormRequest
File "C:\Users\tzvia\Anaconda3\lib\site-
packages\scrapy\http\request\form.py", line 11, in <module>
import lxml.html
File "C:\Users\tzvia\Anaconda3\lib\site-packages\lxml\html\__init__.py",
line 54, in <module>
from .. import etree
ImportError: DLL load failed: The specified module could not be found.
I tried to install lxml, and got again "failed with error code 1".
can someone help me?
I use python 3.6.1 and windows 10
I think it is because your Twisted install failed.
Download the Twisted .whl file from https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted .
Then run
pip install <Twisted-your-version.whl>
Installing lxml on Windows can be a bit of pain.
You might want to check out the info they have on their site here. They suggest that if building from source fails you might want to use the unofficial pre-built binaries by downloading from here and then running
python -m pip install .\lxml-4.2.5-cp37-cp37m-win32.whl
Make sure to download the version that you need. If you're using python 3.6 you should get the cp36 one.
Forget about pip install! The issue with 'scrapy' is all over the Web. Download 'Scrapy-2.5.0.tar.gz' (or whatever version is current) from https://pypi.org/project/Scrapy/, exract it to a temp folder and run < python setup.py install >
I am absolutely new to python and tried to install Theano.
Therefore I ran $ pip install numpy scipy.
Pip seems up to date but I always get the same error:
Collecting scripy
Using cached Scripy-0.9.3.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/lk/v92bv9gs51x55nwp0cspt3xw0000gn/T/pip-build-ZdGtpP/scripy/setup.py", line 96, in <module>
description=get_description(packages[0], PACKAGE_DIR),
File "/private/var/folders/lk/v92bv9gs51x55nwp0cspt3xw0000gn/T/pip-build-ZdGtpP/scripy/setup.py", line 47, in get_description
pkg = __import__(package, level=1)
File "/private/var/folders/lk/v92bv9gs51x55nwp0cspt3xw0000gn/T/pip-build-ZdGtpP/scripy/lib/scripy/__init__.py", line 11, in <module>
from .edit import *
File "/private/var/folders/lk/v92bv9gs51x55nwp0cspt3xw0000gn/T/pip-build-ZdGtpP/scripy/lib/scripy/edit.py", line 18, in <module>
import yamlog
ImportError: No module named yamlog
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/lk/v92bv9gs51x55nwp0cspt3xw0000gn/T/pip-build-ZdGtpP/scripy/
What am I doing wrong?
Thanks a lot!
No, you must have typed:
pip install numpy scripy # <-- should be `scipy`
You can see clearly from the output it is attempting to install scripy not scipy. Whatever this scripy pip package is, it clearly doesn't define its dependencies properly.
You didn't specify distribution and version but if you have python 2.7 I guess this might work.
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano
tried the following command in the terminal,
$ pip3 install notify2
Collecting notify2
Using cached notify2-0.3.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/fr/hgx7qkc14dsglj7724_9m5780000gn/T/pip-build-0aoqwq0g/notify2/setup.py", line 2, in <module>
import notify2
File "/private/var/folders/fr/hgx7qkc14dsglj7724_9m5780000gn/T/pip-build-0aoqwq0g/notify2/notify2.py", line 38, in <module>
import dbus
ImportError: No module named 'dbus'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/fr/hgx7qkc14dsglj7724_9m5780000gn/T/pip-build-0aoqwq0g/notify2/
So, it seems like I need to install dbus module first. So, I tried
$ pip3 install dbus
Collecting dbus
Could not find a version that satisfies the requirement dbus (from versions: )
No matching distribution found for bus
tried which pip
$ which pip
/Library/Frameworks/Python.framework/Versions/3.5/bin/pip
And does anyone know what shall I do?
You need to install dbus using brew install dbus and then pip install dbus-python