首页 > 解决方案 > 无法安装 pip 包

问题描述

我正在尝试制作自己的 python3 pip 包。我从命令行使用 twine 在线上传了它,我可以在这里在线看到它:

https://pypi.org/project/example-pkg-martinbarker-test/

我完全按照教程进行操作(除了更改包名称),但是如果我尝试使用 url 中的说明安装包:

pip install example-pkg-martinbarker-test

我收到一个错误:

# pip install example-pkg-martinbarker-test
Collecting example-pkg-martinbarker-test
  Could not find a version that satisfies the requirement example-pkg-martinbarker-test (from versions: )
No matching distribution found for example-pkg-martinbarker-test

是否与我将包裹上传到麻线的方式有关,这会导致此错误吗?

标签: pythonpippypi

解决方案


使用 Python 3 安装时,安装对我有用,而使用 Python 2 时安装失败。

在这种情况下,请确保您正在pip为 Python 3 运行。您可能希望为 Python 3 创建一个虚拟环境,并安装该包。

创建虚拟环境:

virtualenv env -p python3

要激活虚拟环境:

source ./env/bin/activate

要检查版本:

pip -V

pip 19.3.1 from some/path/env/lib/python3.7/site-packages/pip (python 3.7)

安装:

pip install example-pkg-martinbarker-test

这成功安装了您提到的软件包。

Collecting example-pkg-martinbarker-test
  Downloading https://files.pythonhosted.org/packages/b8/34/9cb503547689819a8c98048eb7127a3538243b0d44294987dba28eeb0259/example_pkg_martinbarker_test-0.0.1-py3-none-any.whl
Installing collected packages: example-pkg-martinbarker-test
Successfully installed example-pkg-martinbarker-test-0.0.1

推荐阅读