问题:Python 3 ImportError:没有名为“ ConfigParser”的模块
我想pip install
的MySQL-python
包,但我得到的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 "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
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$
有任何想法吗?
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 "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
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?
回答 0
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.
回答 1
您可以改为使用该mysqlclient
软件包作为MySQL-python的直接替代品。它是MySQL-python
对Python 3的新增支持。
我很幸运
pip install mysqlclient
在我的python3.4 virtualenv之后
sudo apt-get install python3-dev libmysqlclient-dev
这显然是针对ubuntu / debian的,但我只是想分享我的成功:)
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 :)
回答 2
这是一个在Python 2.x和3.x中均应适用的代码
显然,您将需要该six
模块,但是几乎不可能编写在两个版本中都没有六个版本的模块。
try:
import configparser
except:
from six.moves import configparser
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
回答 3
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
然后尝试再次安装MYSQL-python。对我有用
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again.
That Worked for me
回答 4
python3不支持MySQL-python,您可以使用mysqlclient
如果您正在fedora/centos/Red Hat
安装以下软件包
yum install python3-devel
pip install mysqlclient
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
yum install python3-devel
pip install mysqlclient
回答 5
如果您使用的是CentOS,则需要使用
yum install python34-devel.x86_64
yum groupinstall -y 'development tools'
pip3 install mysql-connector
pip install mysqlclient
If you are using CentOS, then you need to use
yum install python34-devel.x86_64
yum groupinstall -y 'development tools'
pip3 install mysql-connector
pip install mysqlclient
回答 6
configparser
可以通过six
库简单地解决Python 2/3的兼容性
from six.moves import configparser
Compatibility of Python 2/3 for configparser
can be solved simply by six
library
from six.moves import configparser
回答 7
pip3 install PyMySQL
然后再做pip3 install mysqlclient
。为我工作
Do pip3 install PyMySQL
and then pip3 install mysqlclient
.
Worked for me
回答 8
我遇到了同样的问题。原来,我需要在centos上安装python3 devel。首先,您需要搜索与系统兼容的软件包。
yum search python3 | grep devel
然后,将软件包安装为:
yum install -y python3-devel.x86_64
然后,从pip安装mysqlclient
pip install mysqlclient
I was having the same problem. Turns out, I needed to install python3 devel on my centos. First, you need to search for the package that is compatible with your system.
yum search python3 | grep devel
Then, install the package as:
yum install -y python3-devel.x86_64
Then, install mysqlclient from pip
pip install mysqlclient
回答 9
我进一步了解了Valeres的答案:
pip install configparser sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py然后尝试再次安装MYSQL-python。对我有用
我建议链接文件而不是复制它。保存更新。我将文件链接到/usr/lib/python3/
目录。
I got further with Valeres answer:
pip install configparser
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py
Then try to install the MYSQL-python again. That Worked for me
I would suggest to link the file instead of copy it. It is save to update. I linked the file to /usr/lib/python3/
directory.
回答 10
试试这个对我来说很好的解决方案。
基本上它是重新安装/升级到最新版本的MySQL从冲泡,然后安装mysqlclient
或MySQL-Python
从global pip3
代替virtualenv pip3
。
然后访问virtualenv
并成功安装mysqlclient
或MySQL-Python
。
Try this solution which worked fine for me.
Basically it’s to reinstall/upgrade to latest version of mysql from brew, and then installing mysqlclient
or MySQL-Python
from global pip3
instead of virtualenv pip3
.
Then accessing the virtualenv
and successfully install mysqlclient
or MySQL-Python
.
回答 11
如何检查您首先使用的Python版本。
import six
if six.PY2:
import ConfigParser as configparser
else:
import configparser
how about checking the version of Python you are using first.
import six
if six.PY2:
import ConfigParser as configparser
else:
import configparser
回答 12
我运行kali linux- Rolling,并在更新到python 3.6.0之后尝试在终端中运行cupp.py时遇到了这个问题。一些研究和试验后,我发现,改变 ConfigParser
对 configparser
我的工作,但那时,我发现另一个问题就来了。
config = configparser.configparser()
AttributeError: module 'configparser' has no attribute 'configparser'
经过更多研究,我意识到python 3 ConfigParser
已更改为, configparser
但请注意它具有属性 ConfigParser()
。
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()
.
回答 13
我在Mac OS 10,Python 3.7.6和Django 2.2.7上遇到了相同的错误。在尝试了多种解决方案之后,我想借此机会分享对我有用的东西。
脚步
通过链接为Mac OS安装了Connector / Python 8.0.20
将当前依赖项复制到requirements.txt文件,停用当前虚拟环境,并使用删除它;
创建文件(如果尚未创建的话); touch requirements.txt
将依赖项复制到文件; python -m pip3 freeze > requirements.txt
停用并删除当前虚拟环境; deactivate && rm -rf <virtual-env-name>
创建另一个虚拟环境并使用激活它; python -m venv <virtual-env-name> && source <virtual-env-name>/bin/activate
使用安装以前的依赖项; python -m pip3 install -r requirements.txt
I was getting the same error on Mac OS 10, Python 3.7.6 & Django 2.2.7. I want to use this opportunity to share what worked for me after trying out numerous solutions.
Steps
Installed Connector/Python 8.0.20 for Mac OS from link
Copy current dependencies into requirements.txt file, deactivated the current virtual env, and deleted it using;
create the file if not already created with; touch requirements.txt
copy dependency to file; python -m pip3 freeze > requirements.txt
deactivate and delete current virtual env; deactivate && rm -rf <virtual-env-name>
Created another virtual env and activated it using; python -m venv <virtual-env-name> && source <virtual-env-name>/bin/activate
Install previous dependencies using; python -m pip3 install -r requirements.txt
回答 14
请看看/usr/bin/python
指的是什么
如果它指向python3 or higher
更改为python2.7
这应该可以解决问题。
我收到所有python软件包的安装错误。安倍·卡普拉斯(Abe Karplus)的解决方案和讨论向我暗示了可能是什么问题。然后我回想起我已经手动将/usr/bin/python
from从更改python2.7
为/usr/bin/python3.5
,这实际上是导致问题的原因。有一次我reverted
一样。解决了。
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.
回答 15
这对我有用
cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py
This worked for me
cp /usr/local/lib/python3.5/configparser.py /usr/local/lib/python3.5/ConfigParser.py