python pip는 라이브러리 디렉토리와 포함 디렉토리를 지정합니다.
나는 pip를 사용하고 unixodbc-dev, unixodbc-bin, unixodbc와 같은 비 파이썬 라이브러리에 대한 종속성이있는 pyodbc라는 파이썬 모듈을 설치하려고합니다. 지금은 플레이 중이므로 이러한 종속성을 시스템 전체에 설치할 수 없으므로 비표준 위치에 설치했습니다. 이러한 종속성을 찾을 위치를 pip에 어떻게 알립니 까? 더 정확하게는 pyodbc 확장을 빌드 할 때 사용할 include dirs (gcc -I) 및 library dirs (gcc -L -l)의 pip를 통해 정보를 전달하는 방법은 무엇입니까?
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
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>
참고로 ... 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
포함 파일 및 라이브러리의 위치를 나타내는 또 다른 방법은 pip를 실행하기 전에 관련 환경 변수를 설정합니다.
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
pip install cryptography
virtualenv를 사용한 적이 있습니까? 하나의 컴퓨터에서 여러 개의 격리 된 환경을 만들고 유지 관리 할 수있는 Python 패키지입니다. 각각은 시스템 라이브러리 또는 별도의 가상 환경에서 종속성을 망치지 않고 서로 독립적으로 서로 다른 모듈을 사용할 수 있습니다.
루트 권한이없는 경우 소스에서 virtualenv 패키지를 다운로드하여 사용할 수 있습니다 .
$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
$ tar xvfz virtualenv-X.X.tar.gz
$ cd virtualenv-X.X
$ python virtualenv.py myVE
I followed the above steps this weekend on Ubuntu Server 12.0.4 and it worked perfectly. Each new virtual environment you create comes with PIP by default so installing packages into your new environment is easy.
I was also helped by Thorfin's answer; I was building GTK3+ on windows and installing pygobject, I was having difficulties on how to include multiple folders with pip install.
I tried creating pip config file as per pip documentation. but failed. the one working is with the command line:
--global-option=build_ext followed by --global-option="-IlistOfDirectories" and/or --global-option="-LlistofDirectories"
the separator that works with multiple folders in windows is ';' semicolon, NOT colon ':' it might be different in other OS.
sample working command line:
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
you can use '\' or '/' for path, but make sure do not type backslash next to "
this below will fail because there is backslash next to double quote
pip install --global-option=build_ext --global-option="-Ic:\willFail\" --global-option="-Lc:\willFail\" pygobject==3.27.1
Just in case it's of help to somebody, I still could not find a way to do it through pip, so ended up simply downloading the package and doing through its 'setup.py'. Also switched to what seems an easier to install API called 'pymssql'.
'Nice programing' 카테고리의 다른 글
여러 연결에서 동시에 SQLite 데이터베이스를 읽고 쓸 수 있습니까? (0) | 2020.11.17 |
---|---|
모든 하위 디렉토리에서 특정 파일 유형을 tar하는 방법은 무엇입니까? (0) | 2020.11.17 |
Vim : 단어 대 WORD (0) | 2020.11.17 |
배열을 반복하는 동안 Array # delete를 어떻게 사용할 수 있습니까? (0) | 2020.11.17 |
목록이 있는지 확인하는 가장 빠른 방법 (0) | 2020.11.17 |