如何手动安装python库 [英] How to install a python library manually
问题描述
我为我的其中一个构建了quickfix引擎( http://www.quickfixengine.org/)任务,并内置了对它的python支持.
I built quickfix engine (http://www.quickfixengine.org/) for one of my tasks and also built in python support for it.
不幸的是,这是一个多用户环境,我无权访问python的安装路径.因此,make install命令尝试复制文件并失败.我设法注释掉了尝试执行此操作并完成安装的两行.由于无法将文件放在此处,我可以将创建的 .so 文件放在哪里?
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 .so file created?
我如何让python知道它在那里?我查看了python.org文档,但它仅描述了 setup.py 安装过程.
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.py installations.
我也尝试将 .so 的路径放在sys.path
中,这没有用.还有关于python包剖析的文档吗?谢谢.
Also I tried putting the path for the .so in sys.path
, that didnt work. And is there any documents about the anatomy of a python package? Thanks.
推荐答案
我假设编译QuickFix软件包不会产生setup.py
文件,而只会编译Python绑定并依赖make install
来将它们放在适当的位置.
I'm going to assume compiling the QuickFix package does not produce a setup.py
file, but rather only compiles the Python bindings and relies on make install
to put them in the appropriate place.
在这种情况下,一个快速且肮脏的修复方法是编译QuickFix源,找到Python扩展模块(您在系统上以.so
扩展名指示这些扩展模块),然后将该目录添加到您的PYTHONPATH
环境中变量,例如添加
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 .so
extension), and add that directory to your PYTHONPATH
environmental variable e.g., add
export PYTHONPATH=~/path/to/python/extensions:PYTHONPATH
或外壳程序配置文件中的类似行.
or similar line in your shell configuration file.
更强大的解决方案将包括确保使用./configure --prefix=$HOME/.local
进行编译.假设QuickFix知道将Python文件放在适当的site-packages
中,则在执行make install
时,应将文件安装到~/.local/lib/pythonX.Y/site-packages
,对于Python 2.6+,该文件应已作为每用户站点软件包目录.
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.
另一方面,如果它确实提供了setup.py
文件,则只需运行
If, on the other hand, it did provide a setup.py
file, simply run
python setup.py install --user
适用于Python 2.6 +.
for Python 2.6+.
这篇关于如何手动安装python库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!