Python 3 ImportError: No module named 'ConfigParser'

匿名 (未验证) 提交于 2019-12-03 03:08:02

问题:

I am trying to pip install the MySQL-python package, but I get an ImportError.

Jans-MacBook-Pro:~ jan$ /Library/Frameworks/Python.framework/Versions/3.3/bin/pip-3.3 install MySQL-python Downloading/unpacking MySQL-python   Running setup.py egg_info for package MySQL-python     Traceback (most recent call last):       File "", line 16, in        File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in          from setup_posix import get_config       File "./setup_posix.py", line 2, in          from ConfigParser import SafeConfigParser     ImportError: No module named 'ConfigParser'     Complete output from command python setup.py egg_info:     Traceback (most recent call last):    File "", line 16, in     File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in       from setup_posix import get_config    File "./setup_posix.py", line 2, in       from ConfigParser import SafeConfigParser  ImportError: No module named 'ConfigParser'  ---------------------------------------- Command python setup.py egg_info failed with error code 1 in /var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python Storing complete log in /Users/jan/.pip/pip.log Jans-MacBook-Pro:~ jan$  

Any ideas?

回答1:

In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. It looks like the package you are installing does not support Python 3.



回答2:

You can instead use the mysqlclient package as a drop-in replacement for MySQL-python. It is a fork of MySQL-python with added support for Python 3.

I had luck with simply

pip install mysqlclient 

in my python3.4 virtualenv after

sudo apt-get install python3-dev libmysqlclient-dev 

which is obviously specific to ubuntu/debian, but I just wanted to share my success :)



回答3:

MySQL-python is not supported on python3 instead of this you can use mysqlclient

If you are on fedora/centos/Red Hat install following package

  1. yum install python3-devel
  2. pip install mysqlclient


回答4:

Here is a code that should work in both Python 2.x and 3.x

Obviously you will need the six module, but it's almost impossible to write modules that work in both versions without six.

try:     import configparser except:     from six.moves import configparser 


回答5:

if you are using Centos then you need to use

  1. yum install python34-devel.x86_64

  2. yum groupinstall -y 'development tools'

  3. pip3 install mysql-connector

  4. pip install mysqlclient

Hope this would work.



回答6:

how about checking the version of Python you are using first.

import six if six.PY2:     import ConfigParser as configparser else:     import configparser 


回答7:

I run kali linux- Rolling and I came across this problem ,when I tried running cupp.py in the terminal, after updating to python 3.6.0. After some research and trial I found that changing ConfigParser to configparser worked for me but then I came across another issue.

config = configparser.configparser() AttributeError: module 'configparser' has no attribute 'configparser'

After a bit more research I realised that for python 3 ConfigParser is changed to configparser but note that it has an attribute ConfigParser().



回答8:

Compatibility of Python 2/3 for configparser can be solved simply by six library

from six.moves import configparser 


回答9:

This worked for me.

from ConfigParser import ConfigParser



回答10:

Kindly to see what is /usr/bin/python pointing to

if it is pointing to python3 or higher change to python2.7

This should solve the issue.

I was getting install error for all the python packages. Abe Karplus's solution & discussion gave me the hint as to what could be the problem. Then I recalled that I had manually changed the /usr/bin/python from python2.7 to /usr/bin/python3.5, which actually was causing the issue. Once I reverted the same. It got solved.



回答11:

This worked for me

cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!