로컬 디렉터리에서 requirements.txt 파일에 따라 pip를 사용하여 패키지를 설치하는 방법은 무엇입니까?
여기에 문제가 있습니다
다음과 같은 requirements.txt가 있습니다.
BeautifulSoup==3.2.0
Django==1.3
Fabric==1.2.0
Jinja2==2.5.5
PyYAML==3.09
Pygments==1.4
SQLAlchemy==0.7.1
South==0.7.3
amqplib==0.6.1
anyjson==0.3
...
모든 패키지 + 기타를 포함하는 로컬 아카이브 디렉토리가 있습니다.
나는 새로운 virtualenv를 만들었습니다.
bin/virtualenv testing
활성화시 로컬 아카이브 디렉토리의 requirements.txt에 따라 패키지를 설치하려고 시도했습니다.
source bin/activate
pip install -r /path/to/requirements.txt -f file:///path/to/archive/
설치가 정상임을 나타내는 출력이 있습니다.
Downloading/unpacking Fabric==1.2.0 (from -r ../testing/requirements.txt (line 3))
Running setup.py egg_info for package Fabric
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no files found matching 'fabfile.py'
Downloading/unpacking South==0.7.3 (from -r ../testing/requirements.txt (line 8))
Running setup.py egg_info for package South
....
그러나 나중에 확인하면 패키지가 제대로 설치되지 않은 것으로 나타났습니다. 패키지를 가져올 수 없으며 내 virtualenv의 site-packages 디렉토리에 아무것도 없습니다. 그래서 무엇이 잘못 되었습니까?
이것은 나를 위해 작동합니다.
$ pip install -r requirements.txt --no-index --find-links file:///tmp/packages
--no-index
-패키지 색인을 무시합니다 ( --find-links
대신 URL 만 확인 ).
-f, --find-links <URL>
-URL 또는 html 파일 경로 인 경우 아카이브 링크를 구문 분석합니다. file://
디렉토리 인 로컬 경로 또는 URL 인 경우 디렉토리 목록에서 아카이브를 찾으십시오.
나는 위의 내용을 읽었으며 이것이 오래된 질문이라는 것을 깨달았지만 완전히 해결되지 않았으며 여전히 내 Google 검색 결과의 상단에 있으므로 모든 사람에게 적합한 답변이 있습니다.
pip install -r /path/to/requirements.txt
virtualenv가 requirements.txt 파일의 모든 파일을 설치합니다.
- requirements.txt가있는 디렉토리로 이동합니다.
- virtualenv 활성화
- 실행 :
pip install -r requirements.txt
쉘에서
비슷한 문제가있었습니다. 나는 이것을 시도했다 :
pip install -U -r requirements.txt
(-U = 이미 설치된 경우 업데이트)
그러나 문제는 계속되었습니다. 개발 용 일반 라이브러리 중 일부가 누락되었음을 깨달았습니다.
sudo apt-get install libtiff5-dev libjpeg8-dev zlib1g-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
이것이 당신에게 도움이 될지 모르겠습니다.
pip install -r requirements.txt
자세한 내용은 도움말 옵션을 확인하십시오.
pip install --help
'-r'옵션을 찾을 수 있습니다.
-r, --requirement Install from the given requirements file. This option can be used multiple times.
Further information on some commonly used pip install options: (This is the help option on pip install command)
Also the above is the complete set of options. Please use pip install --help for complete list of options.
Often, you will want a fast install from local archives, without probing PyPI.
First, download the archives that fulfill your requirements:
$ pip install --download <DIR> -r requirements.txt
Then, install using –find-links
and –no-index
:
$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
Short answer
pip install -r /path/to/requirements.txt
or in another form:
python -m pip install -r /path/to/requirements.txt
Explanation
Here, -r
is short form of --requirement
and it asks the pip
to install from the given requirements
file.
pip
will start installation only after checking the availability of all listed items in the requirements
file and it won't start installation even if one requirement
is unavailable.
One workaround to install the available packages is installing listed packages one by one. Use the following command for that. A red color warning will be shown to notify you about the unavailable packages.
cat requirements.txt | xargs -n 1 pip install
To ignore comments (lines starting with a #
) and blank lines, use:
cat requirements.txt | cut -f1 -d"#" | sed '/^\s*$/d' | xargs -n 1 pip install
I work with a lot of systems that have been mucked by developers "following directions they found on the internet". It is extremely common that your pip
and your python
are not looking at the same paths/site-packages. For this reason, when I encounter oddness I start by doing this:
$ python -c 'import sys; print(sys.path)'
['', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages']
$ pip --version
pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)
That is a happy system.
Below is an unhappy system. (Or at least it's a blissfully ignorant system that causes others to be unhappy.)
$ pip --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
$ python -c 'import sys; print(sys.path)'
['', '/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
$ which pip pip2 pip3
/usr/local/bin/pip
/usr/local/bin/pip3
It is unhappy because pip
is (python3.6 and) using /usr/local/lib/python3.6/site-packages
while python
is (python2.7 and) using /usr/local/lib/python2.7/site-packages
When I want to make sure I'm installing requirements to the right python, I do this:
$ which -a python python2 python3
/usr/local/bin/python
/usr/bin/python
/usr/local/bin/python2
/usr/local/bin/python3
$ /usr/bin/python -m pip install -r requirements.txt
You've heard, "If it ain't broke, don't try to fix it." The DevOps version of that is, "If you didn't break it and you can work around it, don't try to fix it."
Installing requirements.txt file inside virtual env with python 3:
I had the same issue. I was trying to install requirements.txt file inside a virtual environament. I found the solution.
Initially, I created my virtual env in this way:
virtualenv -p python3 myenv
Activate the environment using:
source myenv/bin/activate
Now I installed the requirements.txt using:
pip3 install -r requirements.txt
Installation was successful and I was able to import the modules.
try this
python -m pip install -r requirements.txt
pip install --user -r requirements.txt
OR
pip3 install --user -r requirements.txt
'program tip' 카테고리의 다른 글
GitHub 저장소에서 단일 폴더 또는 디렉토리 다운로드 (0) | 2020.09.28 |
---|---|
RecyclerView에 onItemClickListener ()가없는 이유는 무엇입니까? (0) | 2020.09.28 |
Node.js를 사용하여 JSON을 구문 분석하는 방법은 무엇입니까? (0) | 2020.09.28 |
사용자가 외부를 클릭 할 때 jQuery를 사용하여 DIV를 숨 깁니다. (0) | 2020.09.28 |
Ubuntu의 Apache 서버 벤치마킹 도구 AB를 포함하는 패키지는 무엇입니까? (0) | 2020.09.25 |