python pip 指定一个库目录和一个包含目录

标签 python shared-libraries pip include-path pyodbc

我正在使用 pip 并尝试安装一个名为 pyodbc 的 python 模块,该模块对 unixodbc-dev、unixodbc-bin、unixodbc 等非 python 库有一些依赖关系。我目前无法在系统范围内安装这些依赖项,因为我只是在玩游戏,所以我将它们安装在非标准位置。如何告诉 pip 在哪里查找这些依赖项?更准确地说,如何通过包含目录 (gcc -I) 和库目录 (gcc -L -l) 的 pip 传递信息以在构建 pyodbc 扩展时使用?

最佳答案

pip 有一个 --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

关于python pip 指定一个库目录和一个包含目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18783390/

相关文章:

python - 适用于Python3的PIP安装问题:请考虑将此目录添加到PATH

python - 在神经网络的学习阶段反向传播后会发生什么?

python - 使用列表中的值作为另一个列表的索引的最pythonic方式

python - 此 TensorFlow 二进制文件使用 Intel(R) MKL-DNN 进行了优化,可在性能关键的情况下使用以下 CPU 指令

c++ - 如何使用沙漏模式在库/模块边界之间传递 vector <T>?

Android NDK,两个静态库和链接

Python - 阶乘之和

c++ - Go 共享库作为 C++ 插件

python - 安装后找不到pip命令

Python Subversion 绑定(bind)哪个与 `pip` 很好地打包?