简体   繁体   English

如何在没有 pip/easy_install 的情况下手动安装 pypi 模块?

[英]How to manually install a pypi module without pip/easy_install?

I want to use the gntp module to display toaster-like notifications for C/C++ software.我想使用gntp 模块为 C/C++ 软件显示类似于烤面包机的通知。 I want to package all the dependencies for the software to be self-executable on another computer.我想打包软件的所有依赖项,以便在另一台计算机上自行执行。

The gntp module is only available through the pip installer, which cannot be used (the computer running the software does not have an internet connection) gntp模块只能通过pip安装程序使用,无法使用(运行该软件的计算机没有互联网连接)

How can I install it from source?如何从源代码安装它?

I would prefer not to force the user to install easy_install / pip and manually add the pip path to the %PATH .我不希望强制用户安装easy_install / pip并手动将 pip 路径添加到%PATH

PS: I'm using Python 2.7 on a Windows machine. PS:我在 Windows 机器上使用 Python 2.7。

  1. Download the package下载包
  2. unzip it if it is zipped如果是压缩的就解压
  3. cd into the directory containing setup.py cd进入包含 setup.py 的目录
  4. If there are any installation instructions contained in documentation, read and follow the instructions OTHERWISE如果文档中包含任何安装说明,请阅读并遵循说明 否则
  5. type in python setup.py install输入python setup.py install

You may need administrator privileges for step 5. What you do here depends on your operating system.您可能需要管理员权限才能执行第 5 步。您在此处执行的操作取决于您的操作系统。 For example in Ubuntu you would say sudo python setup.py install例如在 Ubuntu 中你会说sudo python setup.py install


EDIT - thanks to kwatford (see first comment)编辑- 感谢 kwatford(见第一条评论)

To bypass the need for administrator privileges during step 5 above you may be able to make use of the --user flag.要在上述步骤 5 中绕过对管理员权限的需求,您可以使用--user标志。 This way you can install the package only for the current user.这样您就可以仅为当前用户安装软件包。

The docs say:文档说:

Files will be installed into subdirectories of site.USER_BASE (written as userbase hereafter).文件将被安装到 site.USER_BASE 的子目录中(以后写为 userbase)。 This scheme installs pure Python modules and extension modules in the same location (also known as site.USER_SITE).此方案将纯 Python 模块和扩展模块安装在同一位置(也称为 site.USER_SITE)。

More details can be found here: http://docs.python.org/2.7/install/index.html更多细节可以在这里找到:http: //docs.python.org/2.7/install/index.html

To further explain Sheena's answer , I needed to have setup-tools installed as a dependency of another tool eg more-itertools .为了进一步解释Sheena 的答案,我需要安装 setup-tools作为另一个工具的依赖项,例如more-itertools

Download下载

Click the Clone or download button and choose your method.单击克隆或下载按钮并选择您的方法。 I placed these into a dev/py/libs directory in my user home directory.我将它们放在我的用户主目录中的dev/py/libs目录中。 It does not matter where they are saved, because they will not be installed there.它们保存在哪里并不重要,因为它们不会安装在那里。

Installing setup-tools安装设置工具

You will need to run the following inside the setup-tools directory.您需要在setup-tools目录中运行以下命令。

python bootstrap.py
python setup.py install

General dependencies installation一般依赖安装

Now you can navigate to the more-itertools direcotry and install it as normal.现在您可以导航到more-itertools目录并正常安装它。

  1. Download the package下载包
  2. Unpackage it if it's an archive如果是存档,请解包
  3. Navigate ( cd ... ) into the directory containing setup.py导航 ( cd ... ) 到包含setup.py的目录
  4. If there are any installation instructions contained in the documentation contained herein, read and follow the instructions OTHERWISE如果此处包含的文档中包含任何安装说明,请阅读并遵循说明 否则
  5. Type in: python setup.py install输入: python setup.py install

Even though Sheena's answer does the job, pip doesn't stop just there.尽管Sheena 的回答完成了工作,但pip并没有就此止步。

From Sheena's answer:来自Sheena的回答:

  1. Download the package下载包
  2. unzip it if it is zipped如果是压缩的就解压
  3. cd into the directory containing setup.py cd 进入包含 setup.py 的目录
  4. If there are any installation instructions contained in documentation contained herein, read and follow the instructions OTHERWISE如果此处包含的文档中包含任何安装说明,请阅读并遵循说明 否则
  5. type in python setup.py install输入python setup.py install

At the end of this, you'll end up with a .egg file in site-packages .最后,您将在site-packages中得到一个.egg文件。 As a user, this shouldn't bother you.作为用户,这不应该打扰您。 You can import and uninstall the package normally.可以正常importuninstall包。 However, if you want to do it the pip way, you can continue the following steps.但是,如果您想以pip方式进行操作,则可以继续执行以下步骤。

In the site-packages directory,site-packages目录中,

  1. unzip <.egg file>
  2. rename the EGG-INFO directory as <pkg>-<version>.dist-infoEGG-INFO目录重命名为<pkg>-<version>.dist-info
  3. Now you'll see a separate directory with the package name, <pkg-directory>现在你会看到一个带有包名的单独目录, <pkg-directory>
  4. find <pkg-directory> > <pkg>-<version>.dist-info/RECORD
  5. find <pkg>-<version>.dist-info >> <pkg>-<version>.dist-info/RECORD . find <pkg>-<version>.dist-info >> <pkg>-<version>.dist-info/RECORD The >> is to prevent overwrite. >>是为了防止覆盖。

Now, looking at the site-packages directory, you'll never realize you installed without pip .现在,查看site-packages目录,您永远不会意识到您在没有pip的情况下进行了安装。 To uninstall , just do the usual pip uninstall <pkg> .uninstall ,只需执行通常的pip uninstall <pkg>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM