如何手动安装python库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4933224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 18:12:51  来源:igfitidea点击:

How to install a python library manually

pythonpackagequickfix

提问by Osada Lakmal

I built quickfix engine (http://www.quickfixengine.org/) for one of my tasks and also built in python support for it.

我为我的一项任务构建了 quickfix 引擎 ( http://www.quickfixengine.org/),并且还为它构建了 python 支持。

Unfortunately this is a multi user env and I dont have access to the python installation path. Thus the make install command tries to copy over the files and fails. I managed to comment out the two lines where it tries to do that and the make install completed. Since I cannot put the files there, where can I put the .sofile created?

不幸的是,这是一个多用户环境,我无权访问 python 安装路径。因此 make install 命令尝试复制文件并失败。我设法注释掉了它尝试这样做的两行,并且 make install 已完成。由于我无法将文件放在那里,我可以将创建的.so文件放在哪里?

And how do I let python know that it is there? I looked at python.org documentation but it only describes the process for setup.pyinstallations.

我如何让 python 知道它在那里?我查看了 python.org 文档,但它只描述了setup.py安装的过程。

Also I tried putting the path for the .soin sys.path, that didnt work. And is there any documents about the anatomy of a python package? Thanks.

我也尝试将.so的路径放在.sosys.path,但没有用。有没有关于python包解剖的文件?谢谢。

采纳答案by gotgenes

I'm going to assume compiling the QuickFix package does not produce a setup.pyfile, but rather only compiles the Python bindings and relies on make installto put them in the appropriate place.

我将假设编译 QuickFix 包不会生成setup.py文件,而只会编译 Python 绑定并依赖于make install将它们放在适当的位置。

In this case, a quick and dirty fix is to compile the QuickFix source, locate the Python extension modules (you indicated on your system these end with a .soextension), and add that directory to your PYTHONPATHenvironmental variable e.g., add

在这种情况下,一个快速而肮脏的修复方法是编译 QuickFix 源代码,找到 Python 扩展模块(您在系统上以.so扩展名结尾),然后将该目录添加到您的PYTHONPATH环境变量中,例如,添加

export PYTHONPATH=~/path/to/python/extensions:PYTHONPATH

or similar line in your shell configuration file.

或 shell 配置文件中的类似行。

A more robust solution would include making sure to compile with ./configure --prefix=$HOME/.local. Assuming QuickFix knows to put the Python files in the appropriate site-packages, when you do make install, it should install the files to ~/.local/lib/pythonX.Y/site-packages, which, for Python 2.6+, should already be on your Python path as the per-user site-packages directory.

更强大的解决方案包括确保使用./configure --prefix=$HOME/.local. 假设 QuickFix 知道将 Python 文件放在适当的site-packages,当您这样做时make install,它应该将文件安装到~/.local/lib/pythonX.Y/site-packages,对于 Python 2.6+,它应该已经作为每个用户的站点包目录在您的 Python 路径上。

If, on the other hand, it did provide a setup.pyfile, simply run

另一方面,如果它确实提供了一个setup.py文件,只需运行

python setup.py install --user

for Python 2.6+.

适用于 Python 2.6+。

回答by Please treat your mods well.

Here is the official FAQ on installing Python Modules: http://docs.python.org/install/index.html

这是关于安装 Python 模块的官方常见问题解答:http: //docs.python.org/install/index.html

There are some tips which might help you.

有一些提示可能会对您有所帮助。

回答by Lennart Regebro

You need to install it in a directory in your home folder, and somehow manipulate the PYTHONPATH so that directory is included.

您需要将它安装在您的主文件夹中的一个目录中,并以某种方式操作 PYTHONPATH 以便包含该目录。

The best and easiest is to use virtualenv. But that requires installation, causing a catch 22. :) But check if virtualenv is installed. If it is installed you can do this:

最好和最简单的是使用 virtualenv。但这需要安装,导致捕获 22。:) 但请检查是否安装了 virtualenv。如果已安装,您可以执行以下操作:

$ cd /tmp
$ virtualenv foo
$ cd foo
$ ./bin/python

Then you can just run the installation as usual, with /tmp/foo/python setup.py install. (Obviously you need to make the virtual environment in your a folder in your home directory, not in /tmp/foo. ;) )

然后你可以像往常一样运行安装,使用 /tmp/foo/python setup.py install。(显然,您需要在主目录的文件夹中创建虚拟环境,而不是在 /tmp/foo 中。;))

If there is no virtualenv, you can install your own local Python. But that may not be allowed either. Then you can install the package in a local directory for packages:

如果没有virtualenv,可以安装自己的本地Python。但这也可能不被允许。然后,您可以将软件包安装在软件包的本地目录中:

$ wget http://pypi.python.org/packages/source/s/six/six-1.0b1.tar.gz#md5=cbfcc64af1f27162a6a6b5510e262c9d
$ tar xvf six-1.0b1.tar.gz 
$ cd six-1.0b1/
$ pythonX.X setup.py   install --install-dir=/tmp/frotz

Now you need to add /tmp/frotz/pythonX.X/site-packagesto your PYTHONPATH, and you should be up and running!

现在您需要添加/tmp/frotz/pythonX.X/site-packages到您的 PYTHONPATH,并且您应该已经启动并运行了!