我在Ubuntu上安装了Python 2.7.15rci和Python 3.6.7。当我在virtualenv上执行“点列表”时,它会返回我:
Django (2.1.5)
pip (9.0.1)
pkg-resources (0.0.0)
pytz (2018.9)
setuptools (39.0.1)
wheel (0.32.3)
我正在尝试安装mysqlclient(pip install mysqlclient)并返回错误。
unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command /home/david/env/project/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-pq18uxjj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y28h4ou0-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/david/env/project/include/site/python3.6/mysqlclient:
/usr/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
creating build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/compat.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.6/MySQLdb
copying MySQLdb/times.py -> build/lib.linux-x86_64-3.6/MySQLdb
creating build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.6/MySQLdb/constants
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/MySQLdb
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,4,1,'final',0) -D__version__=1.4.1 -I/usr/include/mysql -I/home/david/env/project/include -I/usr/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.linux-x86_64-3.6/MySQLdb/_mysql.o
unable to execute 'x86_64-linux-gnu-gcc': No such file or directory
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Command "/home/david/env/project/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-pq18uxjj/mysqlclient/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-y28h4ou0-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/david/env/project/include/site/python3.6/mysqlclient" failed with error code 1 in /tmp/pip-build-pq18uxjj/mysqlclient/
因此,我尝试了各种不同的方法,例如:
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libmysqlclient-dev
还有更多...但是它们都不对我有用,问题仍然存在。 有什么建议吗?
谢谢!
答案 0 :(得分:4)
gcc
是build-essential
软件包的一部分,您应在安装其他软件包之前将其安装:
sudo apt-get install build-essential
答案 1 :(得分:3)
我发现,几乎每个Python版本的解决方案都略有不同。对于使用不同版本(例如Python 2.x,3.5或3.7)的用户,我发现了this:
对于 Python 2.x ,使用:
$ sudo apt-get install python-dev
对于 Python 2.7 ,使用:
$ sudo apt-get install libffi-dev
对于 Python 3.x ,使用:
$ sudo apt-get install python3-dev
对于 Python 3.4 ,使用:
$ sudo apt-get install python3.4-dev
对于 Python 3.7 ,使用:
$ sudo apt-get install python3.7-dev
对于 Python 3.8 ,使用:
$ sudo apt-get install python3.8-dev
对于 Python 3.9 ,使用:
$ sudo apt-get install python3.9-dev
如果仍然不能解决问题,则others指出要安装
$ sudo apt-get install build-essential
最后
$ sudo apt-get install libssl-dev
但是最后两个并没有帮助自己-希望这对您有帮助!
答案 2 :(得分:2)
您之前可以这样做:
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
答案 3 :(得分:1)
我指定了python的特定版本3.7 那对我有帮助
我已经安装了这些:
sudo apt-get install python3.7-dev libmysqlclient-dev
和安装的mysqlclient通过:
pip install mysqlclient
答案 4 :(得分:0)
此问题在Ubuntu和python 3+中一直存在。就我而言,我使用的是Ubuntu 18.04,发现此解决方案对于python 3.7.5版很有用
第1步。通过sudo apt安装libpython3.7-dev
> sudo apt-get install libpython3.7-dev
第2步:安装mysqlclient
> python3 -m pip install mysqlclient==1.4.6
答案 5 :(得分:0)
我想在Apache 18.04而不是nginx的Ubuntu 18.04上安装'Modoboa'邮件服务器软件包(https://github.com/modoboa/modoboa)。对于Python 2.7,我需要mysqlclient
。以下软件包对我有用:
sudo apt-get install libssl-dev gcc python2.7-dev libmysqlclient-dev
答案 6 :(得分:0)
我正在使用python3.8。与大卫的答案类似,请使用以下命令,然后它会起作用。
$ sudo apt-get install python3.8-dev