使用pip安装时出现问题

时间:2020-02-13 21:19:59

标签: python python-3.x pip mysql-python

我对使用pip不太有经验。当我尝试安装一些软件包时,出现此错误,不知道那是什么意思。我尝试安装的多个软件包都发生了这种情况。任何建议将不胜感激。

sudo pip install mysql-python
Password:
WARNING: The directory '/Users/yzr/Library/Caches/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting mysql-python
  Downloading MySQL-python-1.2.5.zip (108 kB)
     |████████████████████████████████| 108 kB 2.2 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /Users/yzr/opt/anaconda3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-0kcqh5vw/mysql-python/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-0kcqh5vw/mysql-python/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 /private/tmp/pip-install-0kcqh5vw/mysql-python/pip-egg-info
         cwd: /private/tmp/pip-install-0kcqh5vw/mysql-python/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/tmp/pip-install-0kcqh5vw/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/tmp/pip-install-0kcqh5vw/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

2 个答案:

答案 0 :(得分:3)

我假设您使用的是Unix系统,例如Linux或MacOS。

也许您不小心使用了系统上安装的python2.7版本。

您可以通过以下方式将特定版本的python用于pip:

python3 -m pip install mysql-python

让我自己解释一下,每个MacOS或Linux系统默认都有两个Python版本(2.7和3.x),并且这两个版本都有一个与之相关的pip模块,换句话说,您有一个pip模块用于Python 2.7和其他适用于Python 3.x的pip模块。

但是,我假设您在项目中使用python3,因此,您必须指定要使用的pip模块。

避免此问题的其他方法是使用虚拟环境管理器,例如pipenv或内置的virtualenv模块。

答案 1 :(得分:2)

您的pip软件包似乎未安装模块“ ConfigParser”。您应该可以通过运行以下命令进行安装:

pip install ConfigParser

或者,根据您的Python版本,尝试安装mysqlclient代替:

pip install mysqlclient