本文翻译自:Installing Python packages from local file system folder to virtualenv with pip

Is it possible to install packages using pip from the local filesystem? 是否可以使用本地文件系统中的pip安装软件包?

I have run python setup.py sdist for my package, which has created the appropriate tar.gz file. 我已经为我的程序包运行了python setup.py sdist ,它已经创建了适当的tar.gz文件。 This file is stored on my system at /srv/pkg/mypackage/mypackage-0.1.0.tar.gz . 此文件存储在我的系统上的/srv/pkg/mypackage/mypackage-0.1.0.tar.gz

Now in a virtual environment I would like to install packages either coming from pypi or from the specific local location /srv/pkg . 现在,在虚拟环境中,我想安装来自pypi或来自特定本地位置/srv/pkg软件包。

Is this possible? 这可能吗?

PS I know that I can specify pip install /srv/pkg/mypackage/mypackage-0.1.0.tar.gz . PS我知道我可以指定pip install /srv/pkg/mypackage/mypackage-0.1.0.tar.gz That will work, but I am talking about using the /srv/pkg location as another place for pip to search if I typed pip install mypackage . 那将起作用,但是我正在谈论使用/srv/pkg位置作为pip搜索是否输入pip install mypackage另一个位置。


#1楼

参考:https://stackoom.com/question/114Qg/使用pip将Python软件包从本地文件系统文件夹安装到virtualenv


#2楼

I am pretty sure that what you are looking for is called --find-links option. 我很确定您要寻找的是--find-links选项。

Though you might need to generate a dummy index.html for your local package index which lists the links to all packages. 尽管您可能需要为本地软件包索引生成一个虚拟的index.html ,其中列出了所有软件包的链接。 This tool helps: 该工具有助于:

https://github.com/wolever/pip2pi https://github.com/wolever/pip2pi


#3楼

What about:: 关于什么::

pip install --help
...-e, --editable <path/url>   Install a project in editable mode (i.e. setuptools"develop mode") from a local project path or a VCS url.

eg, pip install -e /srv/pkg 例如, pip install -e /srv/pkg

where /srv/pkg is the top-level directory where 'setup.py' can be found. / srv / pkg是可在其中找到“ setup.py”的顶级目录。


#4楼

This is the solution that I ended up using: 这是我最终使用的解决方案:

import pipdef install(package):# Debugging# pip.main(["install", "--pre", "--upgrade", "--no-index",#         "--find-links=.", package, "--log-file", "log.txt", "-vv"])pip.main(["install", "--upgrade", "--no-index", "--find-links=.", package])if __name__ == "__main__":install("mypackagename")raw_input("Press Enter to Exit...\n")

I pieced this together from pip install examples as well as from Rikard's answer on another question . 我从pip安装示例以及Rikard对另一个问题 的回答中总结了这一点。 The "--pre" argument lets you install non-production versions. “ --pre”参数使您可以安装非生产版本。 The "--no-index" argument avoids searching the PyPI indexes. “ --no-index”参数避免搜索PyPI索引。 The "--find-links=." “ --find-links =”。 argument searches in the local folder (this can be relative or absolute). 参数在本地文件夹中搜索(可以是相对的也可以是绝对的)。 I used the "--log-file", "log.txt", and "-vv" arguments for debugging. 我使用了“ --log-file”,“ log.txt”和“ -vv”参数进行调试。 The "--upgrade" argument lets you install newer versions over older ones. “ --upgrade”参数使您可以在较旧的版本上安装较新的版本。

I also found a good way to uninstall them. 我还找到了卸载它们的好方法。 This is useful when you have several different Python environments. 当您有多个不同的Python环境时,这很有用。 It's the same basic format, just using "uninstall" instead of "install", with a safety measure to prevent unintended uninstalls: 这是相同的基本格式,只是使用“卸载”而不是“安装”,并采取了安全措施来防止意外卸载:

import pipdef uninstall(package):response = raw_input("Uninstall '%s'? [y/n]:\n" % package)if "y" in response.lower():# Debugging# pip.main(["uninstall", package, "-vv"])pip.main(["uninstall", package])passif __name__ == "__main__":uninstall("mypackagename")raw_input("Press Enter to Exit...\n")

The local folder contains these files: install.py, uninstall.py, mypackagename-1.0.zip 本地文件夹包含以下文件:install.py,uninstall.py,mypackagename-1.0.zip


#5楼

I am installing pyfuzzy but is is not in PyPI; 我正在安装pyfuzzy但不在PyPI中; it returns the message: No matching distribution found for pyfuzzy . 它返回消息: No matching distribution found for pyfuzzy

I tried the accepted answer 我尝试了接受的答案

pip install  --no-index --find-links=file:///Users/victor/Downloads/pyfuzzy-0.1.0 pyfuzzy

But it does not work either and returns the following error: 但它也不起作用,并返回以下错误:

Ignoring indexes: https://pypi.python.org/simple Collecting pyfuzzy Could not find a version that satisfies the requirement pyfuzzy (from versions: ) No matching distribution found for pyfuzzy 忽略索引: https ://pypi.python.org/simple收集pyfuzzy找不到满足pyfuzzy要求的版本(来自版本:)找不到与pyfuzzy匹配的发行版

At last , I have found a simple good way there: https://pip.pypa.io/en/latest/reference/pip_install.html 最后,我找到了一个简单的好方法: https : //pip.pypa.io/en/latest/reference/pip_install.html

Install a particular source archive file.
$ pip install ./downloads/SomePackage-1.0.4.tar.gz
$ pip install http://my.package.repo/SomePackage-1.0.4.zip

So the following command worked for me: 所以以下命令对我有用:

pip install ../pyfuzzy-0.1.0.tar.gz.

Hope it can help you. 希望它能对您有所帮助。


#6楼

An option --find-links does the job and it works from requirements.txt file! 一个--find-links选项可以完成这项工作,并且可以从requirements.txt文件中使用!

You can put package archives in some folder and take the latest one without changing the requirements file, for example requirements : 您可以将软件包归档文件放在某个文件夹中,并在不更改需求文件的情况下获取最新的归档文件,例如requirements

.
└───requirements.txt
└───requirements├───foo_bar-0.1.5-py2.py3-none-any.whl├───foo_bar-0.1.6-py2.py3-none-any.whl├───wiz_bang-0.7-py2.py3-none-any.whl├───wiz_bang-0.8-py2.py3-none-any.whl├───base.txt├───local.txt└───production.txt

Now in requirements/base.txt put: 现在在requirements/base.txt放:

--find-links=requirements
foo_bar
wiz_bang>=0.8

A neat way to update proprietary packages, just drop new one in the folder 一种更新专有软件包的好方法,只需将新软件包放入文件夹中

In this way you can install packages from local folder AND pypi with the same single call: pip install -r requirements/production.txt 这样,您可以通过相同的一次调用从local folderpypi安装软件包: pip install -r requirements/production.txt

PS. PS。 See my cookiecutter-djangopackage fork to see how to split requirements and use folder based requirements organization. 请参阅我的cookiecutter-djangopackage分支,以了解如何拆分需求并使用基于文件夹的需求组织。

使用pip将Python软件包从本地文件系统文件夹安装到virtualenv相关推荐

  1. python上传本地文件到ftp_python实现的简单FTP上传下载文件实例

    本文实例讲述了python实现的简单FTP上传下载文件的方法.分享给大家供大家参考.具体如下: python本身自带一个FTP模块,可以实现上传下载的函数功能. #!/usr/bin/env pyth ...

  2. python上传本地文件_python3写的简单本地文件上传服务器实例

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import os.path import paramiko import datet ...

  3. python下载的whl文件如何安装呢

    一.下载whl文件 在**python官方网站**或者其他python库网站下载whl文件 二.安装wheel 打开cmd,执行命令 pip install wheel 如果提示pip"不是 ...

  4. python上传本地文件到远程hdfs_Python之——自动上传本地log文件到HDFS(基于Hadoop 2.5.2)...

    一.场景描述 比如我们的网站共有5台Web设备,日志文件存放在/data/logs/日期(20180114)/access.log.日志为默认的Nginx定义格式,如下所示: 10.2.2.234 - ...

  5. python 浏览器显示本地文件夹_从浏览器中打开本地文件文件夹

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

  6. python怎么导入本地文件_Pycharm中如何导入本地Python环境

    我们使用Pycharm进行软件制作的时候,默认使用的是Pycharm自带的python环境.那么如何才能让Pycharm使用我们自己安装的python环境呢?下面小编就给大家分享一下. 工具/材料 P ...

  7. python 浏览器显示本地文件夹_浏览器读取本地文件

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

  8. python网页开发实现本地上传_树莓派 python 如何将本地文件上传到指定的服务器页面上...

    展开全部 以下是单个文件的,不2113确定你的文件夹是什么意5261思,4102可以压缩下再上传(方1653法一样,调用zip命令) 我的实现方法:调用终端的curl,以下为代码平片段,实现的功能是上 ...

  9. python通过requirements.txt文件批量安装依赖包的实现步骤

    如果要用某个开源框架或者某个项目,需要安装多个依赖包可以如下操作: 1.将requirements.txt文件放到项目中, 2.安装 pip install -r requirements.txt 3 ...

最新文章

  1. FineUI小技巧(5)向子窗口传值,向父窗口传值
  2. 分页和条件查询接口开发
  3. JAVA数组扁平化整合_JS数组扁平化(flat)方法总结详解
  4. 2019-02-28-算法-进化(盛最多水的容器)
  5. 监督学习之knn、naive bayes、决策树算法实验_机器学习基本概念
  6. lisp 提取字符串中的數字_Redis 数据结构之字符串的那些骚操作
  7. 2021 年押宝哪个后端语言呢?
  8. grafana设置mysql为数据源,并进行可视化
  9. 十七款PDF在线处理转换器,目前最全合集
  10. 深度学习:透过神经网络的内在灵魂与柏拉图的哲学理念
  11. tcl脚本控制spirent testcenter异常记录
  12. Common Lisp 超规范(译文):5.数据和控制流
  13. 2019-2020浴血凤凰DNF自动化辅助开发教程
  14. latex写中文毕业论文(北交大博士毕业论文模版)
  15. Unity导表工具Luban插件的数据加载原理与优化
  16. WebView(五)—— WebView的优化
  17. Python seek()和tell()函数详解
  18. 应聘信计算机英语怎么说,求职信范文模板_计算机英文求职信范文模板
  19. 数字图像处理 - 比特平面分层 的python实现
  20. 怎么在win7里设置默认启动用户?

热门文章

  1. 从数据库获取数据到Servlet.
  2. Mysql间隔取数据,实现sqlserver的row_number()函数
  3. Mongodb的安装使用
  4. mysql 主主复制
  5. jQuery操作cookie 的方法
  6. ASP.NET2.0登陆控件的使用(常见的三种方法)
  7. 阿里云ECS服务器自定义端口无法访问问题记录
  8. 如何去掉WordPress分类目录url链接中的category,如何处理生成的作者链接
  9. VMware“该虚拟机似乎正在使用中”问题
  10. 如何用更短时间写出高质量的博客文章经验分享