【问题标题】:python3 pip cannot install any packages also cannot update pip ubuntupython3 pip 无法安装任何包也无法更新 pip ubuntu
【发布时间】:2019-01-16 04:09:11
【问题描述】:

我试过了

sudo apt-get install python3
sudo apt-get install idle
sudo apt-get install python3-pip

然后我尝试用pip安装模块,我尝试了几个不工作。

pip install send2trash
Collecting send2trash
  Downloading https://files.pythonhosted.org/packages/13/2e/ea40de0304bb1dc4eb309de90aeec39871b9b7c4bd30f1a3cdcb3496f5c0/Send2Trash-1.5.0.tar.gz
Building wheels for collected packages: send2trash
  Running setup.py bdist_wheel for send2trash ... done
  Stored in directory: /home/joe/.cache/pip/wheels/f1/ca/e5/bdd5eae705cf50a483257e6ff9dd34911dda3570f0e1340dda
Successfully built send2trash
Installing collected packages: send2trash
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/Send2Trash-1.5.0.dist-info'
Consider using the `--user` option or check the permissions.

You are using pip version 10.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

所以我尝试升级 pip ...

sudo pip install --upgrade pip
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

显然,我的电脑上有一些旧的 python 2.7。我没有使用它。如果解决方案涉及卸载它,我可以。 提前致谢。

当我阅读一些说明时,我也刚刚尝试了 sudo pip3。这就是我现在得到的......

sudo pip3 install beautifulSoup
[sudo] password for joe: 
The directory '/home/joe/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/joe/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting beautifulSoup
  Downloading https://files.pythonhosted.org/packages/1e/ee/295988deca1a5a7accd783d0dfe14524867e31abb05b6c0eeceee49c759d/BeautifulSoup-3.2.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-p5xsk9e4/beautifulSoup/setup.py", line 22
        print "Unit tests have failed!"
                                      ^
    SyntaxError: Missing parentheses in call to 'print'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-p5xsk9e4/beautifulSoup/
You are using pip version 8.1.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

消息说 /home/joe/.cache/pip/http 不属于当前用户。那不是真的。我的电脑对我撒谎。这条路一路走下来,归我所有,用户 joe。

这里是用 sudo pip ...

sudo pip install beautifulSoup
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

我跑了……

sudo python3 -m pip install --upgrade pip
The directory '/home/joe/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/joe/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading https://files.pythonhosted.org/packages/5f/25/e52d3f31441505a5f3af41213346e5b6c221c9e086a166f3703d2ddaf940/pip-18.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 553kB/s 
Installing collected packages: pip
  Found existing installation: pip 8.1.1
    Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-8.1.1
You are using pip version 8.1.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

这似乎奏效了。但后来我跑了 sudo pip3 和 sudo pip ...

sudo pip3 install beautifulSoup
Traceback (most recent call last):
  File "/usr/local/bin/pip3", line 7, in <module>
    from pip._internal import main
ImportError: No module named 'pip._internal'

sudo pip install beautifulSoup
Traceback (most recent call last):
  File "/usr/local/bin/pip", line 7, in <module>
    from pip._internal import main
ImportError: No module named 'pip._internal'

【问题讨论】:

  • 尝试使用python3 -m pip install ... 安装包。据我记得,当你安装 python 时,你会得到pip3。所以你可以用pip3 install ...安装包
  • 您可以尝试对 Python3 使用 pip3,而不是 pip,因为 pip 可能指的是仍在您的系统上的 Python2。
  • sudo python3 -m pip install --upgrade pip
  • 我会帮自己一个忙,将 python 2.7 从您的计算机上转储。我怀疑在路上你会遇到其他奇怪的东西,包有类似的问题。
  • 卸载python 2.7真的是个好主意吗?根据这个线程...askubuntu.com/questions/187227/… 和来自这个线程stackoverflow.com/questions/44602191/…

标签: python python-3.x ubuntu pip


【解决方案1】:

您收到错误消息

由于 EnvironmentError 无法安装软件包:[Errno 13] 没有权限: '/usr/local/lib/python2.7/dist-packages/Send2Trash-1.5.0.dist-info'

因为您是在普通用户下运行 pip install。

您可以使用sudo pip install 'packagename' 运行相同的命令。这将在安装时为您提供 root 权限,或者您可以检查在 virtualenv 中运行它。您可以在 here 阅读有关 virtualenv 的更多信息。

【讨论】:

  • 谢谢你,我也刚刚发现。我在帖子中添加了 sudo pip3 会发生什么。和 sudo pip。
【解决方案2】:

好的,首先让我们修复您的 Pip 安装:

sudo apt-get install --reinstall python3-pip

现在您应该可以运行 pip3 --version 来检查 Pip 是否已安装并正常工作。如果没有,请在尝试其他任何操作之前告诉我。

注意要点:

  • 在 virtualenv 之外运行 Pip 时,您需要使用 pip3,否则您的系统将尝试使用 Python 2 的 Pip。
  • 如果您需要以 root 身份运行 Pip,最好使用 sudo -H 而不仅仅是 sudo - 这将修复有关 The directory ... is not owned by the current user 的警告。

如果你想安装 Pip 18,我建议在 virtualenv 中安装 - 升级系统 Pip 会出现很多问题。

例如:

# Create a new virtualenv:
python3 -m venv my_virtual_environment
# "Activate" it (you need to do this once per shell)
source my_virtual_environment/bin/activate
# Now you can use `pip`, `python` etc. and the changes will be kept in the `my_virtual_environment` directory
pip install -U pip setuptools wheel

另外,要安装 BeautifulSoup,您需要 beautifulsoup4 包 - beautifulSoup 是旧的,不适用于 Python 3:

pip install beautifulsoup4

【讨论】:

  • 嗨乔希,@Josh 安装 python3-pip 没有发生任何事故。不幸的是,我在 pip3 --version 上得到了这个:` pip3 --version Traceback(最近一次调用最后一次):文件“/usr/local/bin/pip3”,第 7 行,在 from pip._internal import main ImportError : 没有名为“pip._internal”的模块`
  • 嗯。你能运行sudo mv /usr/local/bin/pip{,.old}sudo mv /usr/local/bin/pip3{,.old} 看看它是否有效吗?
猜你喜欢
  • 1970-01-01
  • 2016-07-22
  • 2017-11-01
  • 2019-12-22
  • 1970-01-01
  • 2019-01-29
  • 1970-01-01
  • 2013-06-29
  • 1970-01-01
相关资源
最近更新 更多