Cri*_*cri 67 python pip shared-libraries pyodbc include-path
我正在使用pip并尝试安装一个名为pyodbc的python模块,它对unixodbc-dev,unixodbc-bin,unixodbc等非python库有一些依赖性.我目前无法在系统中安装这些依赖项,因为我只是在玩,所以我已将它们安装在非标准位置.我如何告诉pip在哪里寻找这些依赖项?更确切地说,如何通过包含dirs(gcc -I)和库dirs(gcc -L -l)的pip来传递信息,以便在构建pyodbc扩展时使用?
Tho*_*fin 91
皮普有--global-option一面旗帜
您可以使用它来传递其他标志build_ext.
例如,要添加--library-dirs(-L)标志:
pip install --global-option=build_ext --global-option="-L/path/to/local" pyodbc
gcc还支持环境变量:http: //gcc.gnu.org/onlinedocs/gcc/Environment-Variables.html
我找不到任何build_ext文档,所以这里是命令行帮助
Options for 'build_ext' command:
--build-lib (-b) directory for compiled extension modules
--build-temp (-t) directory for temporary files (build by-products)
--plat-name (-p) platform name to cross-compile for, if supported
(default: linux-x86_64)
--inplace (-i) ignore build-lib and put compiled extensions into the
source directory alongside your pure Python modules
--include-dirs (-I) list of directories to search for header files
(separated by ':')
--define (-D) C preprocessor macros to define
--undef (-U) C preprocessor macros to undefine
--libraries (-l) external C libraries to link with
--library-dirs (-L) directories to search for external C libraries
(separated by ':')
--rpath (-R) directories to search for shared C libraries at runtime
--link-objects (-O) extra explicit link objects to include in the link
--debug (-g) compile/link with debugging information
--force (-f) forcibly build everything (ignore file timestamps)
--compiler (-c) specify the compiler type
--swig-cpp make SWIG create C++ files (default is C)
--swig-opts list of SWIG command line options
--swig path to the SWIG executable
--user add user include, library and rpath
--help-compiler list available compilers
Run Code Online (Sandbox Code Playgroud)
小智 20
基于Thorfin的答案并假设您所需的包含和库位置在/ usr/local中,您可以像这样传递两者:
sudo pip install --global-option=build_ext --global-option="-I/usr/local/include/" --global-option="-L/usr/local/lib" <you package name>
Run Code Online (Sandbox Code Playgroud)
bre*_*att 11
仅供参考...如果您在使用pip安装软件包时遇到问题,那么您可以使用
--no-clean选项,看看究竟发生了什么(也就是说,为什么构建不起作用).例如,如果numpy没有正确安装,你可以试试
pip install --no-clean numpy
然后查看Temporary文件夹以查看构建的程度.在Windows机器上,它应该位于以下内容:
C:\Users\Bob\AppData\Local\Temp\pip_build_Bob\numpy
为了清楚起见, - no-clean选项试图安装包,但不会自行清理,让你看看pip正在尝试做什么.
否则,如果您只想下载源代码,那么我会使用该-d标志.例如,要将Numpy源代码.tar文件下载到当前目录,请使用:
pip install -d %cd% numpy
Run Code Online (Sandbox Code Playgroud)
指示包含文件和库位置的另一种方法是在运行pip之前设置相关的环境变量,例如
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
pip install cryptography
Run Code Online (Sandbox Code Playgroud)
Thorfin 的回答也帮助了我;我正在 Windows 上构建 GTK3+ 并安装 pygobject,我在如何使用 pip install 包含多个文件夹方面遇到了困难。
我尝试根据 pip 文档创建 pip 配置文件。但失败了。一个工作是使用命令行:
pip install --global-option=build_ext --global-option="-IlistOfDirectories"
# and/or with: --global-option="-LlistofDirectories"
Run Code Online (Sandbox Code Playgroud)
在 Windows 中处理多个文件夹的分隔符是';' 分号,而不是冒号 ':' 在其他操作系统中可能会有所不同。
示例工作命令行:
pip install --global-option=build_ext --global-option="-Ic:/gtk-build/gtk/x64/release/include;d:/gtk-build/gtk/x64/release/include/gobject-introspection-1.0" --global-option="-Lc:\gtk-build\gtk\x64\release\lib" pygobject==3.27.1
Run Code Online (Sandbox Code Playgroud)
您可以使用 '' 或 '/' 作为路径,但请确保不要在“
下面这将失败,因为双引号旁边有反斜杠
pip install --global-option=build_ext --global-option="-Ic:\willFail\" --global-option="-Lc:\willFail\" pygobject==3.27.1
Run Code Online (Sandbox Code Playgroud)
Cri*_*cri -2
以防万一它对某人有帮助,我仍然找不到通过 pip 来完成此操作的方法,因此最终只是下载了该包并通过其“setup.py”进行操作。还切换到似乎更容易安装的 API,称为“pymssql”。