ubuntu升級pip後, ImportError: cannot import name ‘main‘

場景描述:html

原先pip安裝完成以後,一直沒有更新版本,原pip版本爲8.1.1,今天安裝python 包pysftp的時候,提示須要升級pip到(pip 10.0.1);python

因而乎,直接手到擒來,終端命令行執行:linux

$ sudo pip install --upgrade pip

升級完成以後,查看版本pip --version 顯示:pip 10.0.1ubuntu

以後安裝sudo pip install pysftpui

提示:this

ImportError: cannot import name ‘main‘

啥問題呀,百度?!!!spa

http://www.javashuo.com/article/p-oluogzmq-x.html命令行

改完以後沒有效果!啥子緣由!囧,我特發!3d

緣由分析:code

1. 提示報錯爲:/user/bin/pip第九行有問題

2. which pip

/home/odoo/.local/bin/pip

搜嘎,原來更新升級以後的pip安裝路徑變了,沒有更新/user/bin下的配置,致使咱們運行pip命令的時候,執行的仍是原先就的程序。咱們知道/user/bin目錄下的程序,基本爲程序包安裝時候建立的軟連接!!!

知道問題緣由後,就知道如何處理了。

解決方式:

兩種,第一種刪除舊的/user/bin下的pip軟連接,從新設置。

方式二,直接卸載原有pip從新安裝,指定軟連接爲新的路徑。

這裏採用的第二種,重裝前先卸載ubuntu的pip包
sudo apt-get remove python-pip

從新安裝:sudo apt-get install python-pip python-dev build-essential

odoo@test:/usr/bin$ sudo apt-get install python-pip python-dev build-essential
Reading package lists... Done
Building dependency tree       
Reading state information... Done
build-essential is already the newest version (12.1ubuntu2).
python-dev is already the newest version (2.7.12-1~16.04).
python-dev set to manually installed.
The following packages were automatically installed and are no longer required:
  linux-headers-4.13.0-36 linux-headers-4.13.0-36-generic
  linux-headers-4.13.0-37 linux-headers-4.13.0-37-generic
  linux-image-4.13.0-36-generic linux-image-4.13.0-37-generic
  linux-image-extra-4.13.0-36-generic linux-image-extra-4.13.0-37-generic
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
  python-pip
0 upgraded, 1 newly installed, 0 to remove and 106 not upgraded.
Need to get 144 kB of archives.
After this operation, 635 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 python-pip all 8.1.1-2ubuntu0.4 [144 kB]
Fetched 144 kB in 1s (94.4 kB/s)     
Selecting previously unselected package python-pip.
(Reading database ... 304775 files and directories currently installed.)
Preparing to unpack .../python-pip_8.1.1-2ubuntu0.4_all.deb ...
Unpacking python-pip (8.1.1-2ubuntu0.4) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up python-pip (8.1.1-2ubuntu0.4) ...

odoo@test:/usr/bin$ 
odoo@test:/usr/bin$ pip --version
pip 10.0.1 from /home/odoo/.local/lib/python2.7/site-packages/pip (python 2.7)

建立軟連接:

sudo ln -s /usr/local/bin/pip /usr/bin/pip
pip --version
pip 10.0.1 from /usr/local/lib/python2.7/dist-packages/pip-10.0.1-py2.7.egg/pip (python 2.7)

安裝pysftp 這裏切換在root用戶下安裝了,普通用戶的話須要加sudo pip install pysftp

root@odoo-test:/usr/local/bin# pip install pysftp
Collecting pysftp
  Downloading https://files.pythonhosted.org/packages/36/60/45f30390a38b1f92e0a8cf4de178cd7c2bc3f874c85430e40ccf99df8fe7/pysftp-0.2.9.tar.gz
Collecting paramiko>=1.17 (from pysftp)
  Downloading https://files.pythonhosted.org/packages/3e/db/cb7b6656e0e7387637ce850689084dc0b94b44df31cc52e5fc5c2c4fd2c1/paramiko-2.4.1-py2.py3-none-any.whl (194kB)
    100% |████████████████████████████████| 194kB 5.8kB/s 
Requirement already satisfied: pyasn1>=0.1.7 in /usr/lib/python2.7/dist-packages (from paramiko>=1.17->pysftp) (0.1.9)
Collecting bcrypt>=3.1.3 (from paramiko>=1.17->pysftp)
  Downloading https://files.pythonhosted.org/packages/2e/5a/2abeae20ce294fe6bf63da0e0b5a885c788e1360bbd124edcc0429678a59/bcrypt-3.1.4-cp27-cp27mu-manylinux1_x86_64.whl (57kB)
    100% |████████████████████████████████| 61kB 6.0kB/s 
Collecting cryptography>=1.5 (from paramiko>=1.17->pysftp)
  Downloading https://files.pythonhosted.org/packages/dd/c2/3a5bfefb25690725824ade71e6b65449f0a9f4b29702cce10560f786ebf6/cryptography-2.2.2-cp27-cp27mu-manylinux1_x86_64.whl (2.2MB)
    100% |████████████████████████████████| 2.2MB 22kB/s 
Collecting pynacl>=1.0.1 (from paramiko>=1.17->pysftp)
  Downloading https://files.pythonhosted.org/packages/80/3d/d709b9fbd69e21dd3a4d34eb690c5484094699e03b7447bc7eb173cfd7b6/PyNaCl-1.2.1-cp27-cp27mu-manylinux1_x86_64.whl (696kB)
    100% |████████████████████████████████| 706kB 5.5kB/s 
Requirement already satisfied: six>=1.4.1 in /usr/lib/python2.7/dist-packages (from bcrypt>=3.1.3->paramiko>=1.17->pysftp) (1.10.0)
Collecting cffi>=1.1 (from bcrypt>=3.1.3->paramiko>=1.17->pysftp)
  Downloading https://files.pythonhosted.org/packages/14/dd/3e7a1e1280e7d767bd3fa15791759c91ec19058ebe31217fe66f3e9a8c49/cffi-1.11.5-cp27-cp27mu-manylinux1_x86_64.whl (407kB)
    100% |████████████████████████████████| 409kB 4.7kB/s 
Requirement already satisfied: enum34; python_version < "3" in /usr/lib/python2.7/dist-packages (from cryptography>=1.5->paramiko>=1.17->pysftp) (1.1.2)
Collecting asn1crypto>=0.21.0 (from cryptography>=1.5->paramiko>=1.17->pysftp)
  Downloading https://files.pythonhosted.org/packages/ea/cd/35485615f45f30a510576f1a56d1e0a7ad7bd8ab5ed7cdc600ef7cd06222/asn1crypto-0.24.0-py2.py3-none-any.whl (101kB)
    100% |████████████████████████████████| 102kB 7.0kB/s 
Collecting idna>=2.1 (from cryptography>=1.5->paramiko>=1.17->pysftp)
  Downloading https://files.pythonhosted.org/packages/27/cc/6dd9a3869f15c2edfab863b992838277279ce92663d334df9ecf5106f5c6/idna-2.6-py2.py3-none-any.whl (56kB)
    100% |████████████████████████████████| 61kB 5.9kB/s 
Requirement already satisfied: ipaddress; python_version < "3" in /usr/lib/python2.7/dist-packages (from cryptography>=1.5->paramiko>=1.17->pysftp) (1.0.16)
Collecting pycparser (from cffi>=1.1->bcrypt>=3.1.3->paramiko>=1.17->pysftp)
  Downloading https://files.pythonhosted.org/packages/8c/2d/aad7f16146f4197a11f8e91fb81df177adcc2073d36a17b1491fd09df6ed/pycparser-2.18.tar.gz (245kB)
    100% |████████████████████████████████| 256kB 6.4kB/s 
Building wheels for collected packages: pysftp, pycparser
  Running setup.py bdist_wheel for pysftp ... done
  Stored in directory: /root/.cache/pip/wheels/d4/53/02/181ea4f6c795b40c4f1d2022ba2ed15cf811d22975eb2e5968
  Running setup.py bdist_wheel for pycparser ... done
  Stored in directory: /root/.cache/pip/wheels/c0/a1/27/5ba234bd77ea5a290cbf6d675259ec52293193467a12ef1f46
Successfully built pysftp pycparser
Installing collected packages: pycparser, cffi, bcrypt, asn1crypto, idna, cryptography, pynacl, paramiko, pysftp
  Found existing installation: idna 2.0
    Uninstalling idna-2.0:
      Successfully uninstalled idna-2.0
  Found existing installation: cryptography 1.2.3
    Uninstalling cryptography-1.2.3:
      Successfully uninstalled cryptography-1.2.3
Successfully installed asn1crypto-0.24.0 bcrypt-3.1.4 cffi-1.11.5 cryptography-2.2.2 idna-2.6 paramiko-2.4.1 pycparser-2.18 pynacl-1.2.1 pysftp-0.2.9

OK !

相關文章
相關標籤/搜索