sudo 在 python mysql 连接器安装期间导致 pip 错误?

sudo 在 python mysql 连接器安装期间导致 pip 错误?

尝试安装python mysql通过pip连接使用 sudo 时失败。原因和解决方法是什么?

user@host:~$ sudo pip install mysql-connector
[sudo] password for user: 
Sorry, try again.
[sudo] password for user: 
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main
user@host:~$ pip install mysql-connector
Collecting mysql-connector
  Downloading https://files.pythonhosted.org/packages/59/e0/775bf5fb3dd4c7f9aa6877907d4a96eecca6886c603dedfea6e843e94560/mysql-connector-2.1.6.tar.gz (11.8MB)
    100% |████████████████████████████████| 11.8MB 2.8MB/s 
Building wheels for collected packages: mysql-connector
  Running setup.py bdist_wheel for mysql-connector ... done
  Stored in directory: /home/user/.cache/pip/wheels/8a/35/dd/9324d413c350bd1a9f92ee2894d78a4b4e19eb32477a69cd1c
Successfully built mysql-connector
Installing collected packages: mysql-connector
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/mysql_connector-2.1.6.dist-info'
Consider using the `--user` option or check the permissions.

user@host:~$ sudo pip install mysql-connector
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

相关内容