Skip to main content
 首页 » 编程设计

python之为什么在使用 tox 时 pip 不安装包

2025年04月02日17bonelee

我创建了一个包,其结构在此处给出。

packagename 
   -- packagename 
         -- __init__.py 
   -- setup.py 

包安装正确,我用'pip freeze'检查过

我正尝试在另一个带有 tox 的模块中使用这个包

毒药.ini

 [tox] 
  envlist = dev 
 [default-dependencies] 
  deps = packagename 
 [testenv:dev] 
  deps = {[default-dependencies]deps} 
  pip_pre=True 
  ignore_errors=True 
  commands = py.test blah 

当我尝试使用

tox -e dev 

我收到此错误消息

Collecting packagename 
Could not find a version that satisfies the requirement packagename (from versions: ) 
No matching distribution found for packagename 
v = InvocationError('/Users/***/.tox/dev/bin/pip install --pre dlb_dcp_csaf') 

然而,当我这样安装时,一切都很好

 pip install --pre packagename  

我检查了两者的 pip 版本

 pip 8.1.1 from /usr/local/lib/python2.7/site-packages (python 2.7) 
 pip 8.1.1 from /Users/***/.tox/dev/lib/python2.7/site-packages (python 2.7) 

谁能帮我解释一下为什么我不能使用 tox 安装包但可以使用 pip 手动安装?

请您参考如下方法:

根据 tox 命令的输出,您似乎没有指定包名的正确路径,因此 tox 正在尝试在 PIP 服务器上查找它。您必须指定相对于 tox.ini 所在目录的包名称的正确路径。

发件人:http://testrun.org/tox/latest/config.html

deps=MULTI-LINE-LIST 
test-specific dependencies - to be installed into the environment prior to  
project package installation. Each line defines a dependency, which will be      
passed to the installer command for processing. Each line specifies a file,  
a URL or a package name. 

...

(Experimentally introduced in 1.6.1) all installer commands are executed  
using the {toxinidir} as the current working directory. 
 
{toxinidir} 
the directory where tox.ini is located