setuptools已安装,但无法导入

时间:2019-01-20 22:44:30

标签: python python-2.7

试图安装pip

user@Ubuntu ~/ $ sudo pip --no-cache-dir install --user -U setuptools
Requirement already up-to-date: setuptools in /home/coder/.local/lib/python3.5/site-packages (40.6.3)

但是当我想import时,它就不再导入了。

user@Ubuntu ~/ $ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named setuptools
>>>

1 个答案:

答案 0 :(得分:0)

我从这里的链接中获得了解决方案 Correct command for pip upgrade我的解决方案如下:

User@Ubuntu ~/Documents/RE $ sudo python -m pip install --upgrade pip setuptools wheel

Requirement already up-to-date: pip in /home/coder/.local/lib/python2.7/site-packages (18.1)
Collecting setuptools
  Downloading https://files.pythonhosted.org/packages/37/06/754589caf971b0d2d48f151c2586f62902d93dc908e2fd9b9b9f6aa3c9dd/setuptools-40.6.3-py2.py3-none-any.whl (573kB)
    100% |████████████████████████████████| 573kB 666kB/s 
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/ff/47/1dfa4795e24fd6f93d5d58602dd716c3f101cfd5a77cd9acbe519b44a0a9/wheel-0.32.3-py2.py3-none-any.whl
Installing collected packages: setuptools, wheel
Successfully installed setuptools-40.6.3 wheel-0.32.3

user@Ubuntu ~/Documents/RE $ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>> 

所以正确的命令是这样的:

user@ubuntu ~/Documents/RE $ sudo python -m pip install --upgrade pip setuptools wheel
相关问题