安装python模块常见错误

  • matplotlib报错_tkinter.TclError: no display name and no $DISPLAY environment variable

#交互式测试,此时报错

解决办法,在引用后添加下面这一行


例如:

  • 报错:

c/_cffi_backend.c:15:10: fatal error: ffi.h: 没有那个文件或目录
#include <ffi.h>
^~~~~~~
compilation terminated.
error: command ‘gcc’ failed with exit status 1

解决:

  • 报错:build/temp.linux-x86_64-3.4/_openssl.c:423:30: fatal error: openssl/opensslv.h: No such file or directory

  • 安装MySQL-python时报错ModuleNotFoundError: No module named ‘ConfigParser’

用命令easy_install MySQL-python安装时报如下错误:

原因:

在 Python 3.x 版本后,ConfigParser.py 已经更名为 configparser.py 所以出错!

解决方法:

找到文件 configparser ,更名为旧版本的名称 ConfigParser

 

如果使用过程中出问题, 可以:

修改six模块为

  • Could not find a version that satisfies the requirement twisted[tls]>=18.7

解决:pip install https://github.com/twisted/twisted/archive/twisted-18.7.0.zip

 

  • No module named _sqlite3

解决:yum install sqlite-devel

./configure –prefix=/root/.python_env –enable-loadable-sqlite-extensions && make && make install

 

  • import MySQLdb as Database
    ModuleNotFoundError: No module named ‘MySQLdb’

解决: pip install PyMySQL mysqlclient

 

  • 用python3.7-alpine镜像构建安装gevent时报错:

alpine /usr/local/include/python3.7m/Python.h:11:10: fatal error: limits.h: No such file or directory

解决:

重点须安装: build-base libev, 然后再次安装即可成功.

另: 有篇文章: https://o0o0.club/%E5%9C%A8alpine%E4%B8%AD%E5%AE%89%E8%A3%85gevent%E7%9A%84%E9%AA%9A%E6%93%8D%E4%BD%9C/

即打包所有的:

然后再添加Dockerfile

这个我没有测能否用

 

  • 安装python-ldap :Modules/constants.h:7:18: fatal error: lber.h: No such file or directory

解决: yum install -y openldap-devel

 

  • pip install 时遇到:

INFO: pip is looking at multiple versions of asn1crypto to determine which version is compatible with other requirements. This could take a while.
INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If you want to ato do so. To improve how pip performs, tell us what happened here: https://pip.pypa.io/surveys/backtracking

解决:加上–use-deprecated=legacy-resolve参数:

pip install -r requirements.txt –use-deprecated=legacy-resolve

 

  • 在alpine中build时,pip安装软件时报错:

error: Can not find Rust compiler Failed building wheel for cryptography

解决: 增加ENV变量(You can skip the rust installation and other related dependencies by adding the line below before apk add commands):

      ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1
  • 安装pip install Mysql-Python时报错: error: ‘MYSQL’ {aka ‘struct st_mysql’} has no member named ‘reconnect’

解决:

In alpine you easily execute his work around with
sed '/st_mysql_options options;/a unsigned int reconnect;' /usr/include/mysql/mysql.h -i.bkp

or in your docker file obviously
RUN sed '/st_mysql_options options;/a unsigned int reconnect;' /usr/include/mysql/mysql.h -i.bkp

下面是我的Dockerfile部分:

 

参考:https://github.com/DefectDojo/django-DefectDojo/issues/407

 

  • 安装pip install pycurl报错: Could not run curl-config: [Errno 2] No such file or directory

解决:apk add curl-dev参考:https://stackoverflow.com/questions/23937933/could-not-run-curl-config-errno-2-no-such-file-or-directory-when-installing

用python3 In Alpine linux you should do:

apk add curl-dev python3-dev libressl-dev

如果使用python2, 只需要安装apk add curl-dev

Categories: 未分类

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *