[英]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。
cd
into the directory containing setup.py cd
进入包含 setup.py 的目录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 。
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.它们保存在哪里并不重要,因为它们不会安装在那里。
You will need to run the following inside the setup-tools directory.您需要在setup-tools目录中运行以下命令。
python bootstrap.py
python setup.py install
Now you can navigate to the more-itertools direcotry and install it as normal.现在您可以导航到more-itertools目录并正常安装它。
cd ...
) into the directory containing setup.py
cd ...
) 到包含setup.py
的目录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的回答:
- Download the package
下载包
- unzip it if it is zipped
如果是压缩的就解压
- cd into the directory containing setup.py
cd 进入包含 setup.py 的目录
- If there are any installation instructions contained in documentation contained herein, read and follow the instructions OTHERWISE
如果此处包含的文档中包含任何安装说明,请阅读并遵循说明 否则
- 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.可以正常
import
和uninstall
包。 However, if you want to do it the pip
way, you can continue the following steps.但是,如果您想以
pip
方式进行操作,则可以继续执行以下步骤。
In the site-packages
directory,在
site-packages
目录中,
unzip <.egg file>
EGG-INFO
directory as <pkg>-<version>.dist-info
EGG-INFO
目录重命名为<pkg>-<version>.dist-info
<pkg-directory>
<pkg-directory>
find <pkg-directory> > <pkg>-<version>.dist-info/RECORD
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.