我有一个外部包我想从tar文件安装到我的python virtualenv中.安装包的最佳方法是什么?
我发现了两种方法可以做到:
python setup.py install在解压缩的目录中运行.pip install packagename.tar.gz来自https://pip.pypa.io/en/stable/reference/pip_install/#examples中的示例#7如果用这两种方式做它们有什么不同.
在服务器上安装ahocorasick时出现以下错误:
一些不安全和无法验证的文件被忽略(使用--allow-unverified ahocorasick允许).
如何修改requirements.txt以允许未经验证的包?在Heroku上的Fresh部署中的答案失败了"使用--allow-unverified PIL允许"状态,我们可以在requirements.txt中添加--allow-unverified ahocorasick.但那不适合我.
我的存储库包含我自己的 python 模块和它的依赖项之一的子模块,它有自己的 setup.py。
我想在安装我自己的库时调用依赖项的 setupy.py,这怎么可能?
我的第一次尝试:
$ tree
.
??? dependency
? ??? setup.py
??? mylib
??? setup.py
$ cat mylib/setup.py
from setuptools import setup
setup(
name='mylib',
install_requires= ["../dependency"]
# ...
)
$ cd mylib && python setup.py install
error in arbalet_core setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Invalid requirement, parse error at "'../depen'"
Run Code Online (Sandbox Code Playgroud)
但是install_requires不接受路径。
我的第二次尝试是使用dependency_links=["../dependency"]withinstall_requires=["dependency"]但是 Pypi 中已经存在同名的依赖项,因此 setuptools 尝试使用该版本而不是我的版本。
什么是正确/最干净的方法?
我有一个必须从 git+https 安装的项目:
我可以让它以这种方式工作:
virtualenv -p python3.5 bla
. bla/bin/activate
pip install numpy # must have numpy before the following pkg...
pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
Run Code Online (Sandbox Code Playgroud)
但是,我想在 setup.py 文件中使用它install_requires:
from setuptools import setup
setup(install_requires='git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI', setup_requires='numpy')
Run Code Online (Sandbox Code Playgroud)
然后,pip install -e .从包含setup.py
由于解析错误,这不起作用:
Complete output (1 lines):
error in bla_bla setup command: 'install_requires' must be a string or list of strings containing valid project/version requireme
nt specifiers; Invalid requirement, parse error at "'+https:/'"
----------------------------------------
ERROR: Command errored out with exit …Run Code Online (Sandbox Code Playgroud) 我在私有 git 仓库中有一个包 (foo)。我想通过 bar 的 setup.py 安装 foo 以供另一个包 bar 使用。我想要一个特定的版本 - setup.py 中 foo 的版本匹配它的 git 标签(0.3.2,git 标签是 v0.3.2)
bar 的 setup.py 如下所示:
#!/usr/bin/env python
from setuptools import setup, find_packages
setup(name='bar',
install_requires=['foo@ git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=somedir']
)
Run Code Online (Sandbox Code Playgroud)
我还尝试在最后明确添加版本:
install_requires=['foo@ git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=somedir==0.3.2']
Run Code Online (Sandbox Code Playgroud)
我目前在我的 venv 中安装了 0.3.1 版。当我尝试安装这个 setup.py 时,通过pip install .,或者pip install . -U版本没有升级 - 甚至没有检出 repo:
Requirement already satisfied, skipping upgrade: foo@ git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src==0.3.2 from
git+ssh://****@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src==0.3.2 in
./venv/lib/python3.8/site-packages (from bar==0.0.0) (0.3.1)
Run Code Online (Sandbox Code Playgroud)
但是,当我直接使用pip安装foo时,升级就完成了:
pip install git+ssh://git@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src
Collecting git+ssh://****@github.com/fergusmac/foo.git@v0.3.2#subdirectory=src
Cloning ssh://****@github.com/fergusmac/foo.git …Run Code Online (Sandbox Code Playgroud)