这是问题所在:
我有一个 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 目录中找不到任何包。那么出了什么问题呢?
--no-index
使其甚至不查看 PyPI?
这适用于每个人:
pip install -r /path/to/requirements.txt
解释:
-r, --requirement <文件名>
从给定的需求文件安装。此选项可以多次使用。
这对我有用:
$ pip install -r requirements.txt --no-index --find-links file:///tmp/packages
--no-index
- 忽略包索引(只查看 --find-links
URL)。
-f, --find-links <URL>
- 如果是 HTML 文件的 URL 或路径,则解析档案链接。
如果本地路径或 file://
URL 是目录,则在目录列表中查找存档。
--no-index
信息 --no-index
忽略包索引(只查看 --find-links
URL)。 来自命令 pip help install 的关于 --find-links
的信息 -f
、--find-links <url>
如果是 html 文件的 URL 或路径,则解析指向档案的链接。如果本地路径或 file:// url 是目录,则在目录列表中查找存档。
requirements.txt
的情况下pip install <some_module>
,但这不会更新 requirements.txt
。另一种方法可能是更新 docker,使其列出所有运行以安装依赖项的 pip install 命令。
python -m pip install -r requirements.txt
。东西安装得很顺利,但是当我执行 pip list 时,当我处于活动的 venv 甚至停用 venv 后,它不会显示该软件包。也无法使用该软件包。不知道这里有什么问题
requirements.txt
中没有 git+ssh
要求,这将起作用。对于 git+ssh
,pip 仍会尝试获取包
让 virtualenv 安装 requirements.txt 文件中的所有文件。
cd 到 requirements.txt 所在的目录激活你的 virtualenv 运行: pip install -r requirements.txt 在你的 shell
pip3 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 从给定的需求文件安装。此选项可以多次使用。
有关一些常用 pip 安装选项的更多信息(这是 pip install 命令的帮助选项):
https://i.stack.imgur.com/NWTio.png
以上是完整的选项集。请使用 pip install --help
获取完整的选项列表。
简短的回答
pip install -r /path/to/requirements.txt
或以另一种形式:
python -m pip install -r /path/to/requirements.txt
解释
这里,-r
是 --requirement
的缩写形式,它要求 pip
从给定的 requirements
文件安装。
pip
只有在检查 requirements
文件中列出的所有项目的可用性后才会开始安装,即使有一个 requirement
不可用,它也不会开始安装。
安装可用软件包的一种解决方法是一一安装列出的软件包。为此,请使用以下命令。将显示红色警告以通知您有关不可用的包裹。
cat requirements.txt | xargs -n 1 pip install
要忽略注释(以 #
开头的行)和空行,请使用:
cat requirements.txt | cut -f1 -d"#" | sed '/^\s*$/d' | xargs -n 1 pip install
首先,创建一个虚拟环境。
在 Python 3.6 中
virtualenv --python=/usr/bin/python3.6 <path/to/new/virtualenv/>
在 Python 2.7 中
virtualenv --python=/usr/bin/python2.7 <path/to/new/virtualenv/>
然后激活环境并安装 requirements.txt 文件中所有可用的包。
source <path/to/new/virtualenv>/bin/activate
pip install -r <path/to/requirement.txt>
<path-to-virtualenv>/Scripts/activate.bat
。要停用环境,请使用:<path-to-virtualenv>/Scripts/deactivate.bat
。
通常,您会希望从本地档案中快速安装,而无需探测 PyPI。
首先,下载满足您要求的档案:
$ pip install --download <DIR> -r requirements.txt
然后,使用 –find-links
和 –no-index
安装:
$ pip install --no-index --find-links=[file://]<DIR> -r requirements.txt
no such option: --download
pip install --download
中必须是 pip download
。
尝试这个:
python -m pip install -r requirements.txt
我使用的许多系统都被开发人员“按照他们在 Internet 上找到的指示”搞砸了。您的 pip
和您的 python
不查看相同的路径/站点包是非常常见的。出于这个原因,当我遇到奇怪的事情时,我会这样做:
$ 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)
那是一个快乐的系统。
下面是一个不愉快的系统。 (或者至少这是一个幸福的无知系统,会导致其他人不开心。)
$ 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
不高兴因为 pip
是 (python3.6 and) 使用 /usr/local/lib/python3.6/site-packages
而 python
是 (python2.7 and) 使用 /usr/local/lib/python2.7/site-packages
当我想确保将要求安装到正确的 python 时,我会这样做:
$ 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
你听说过,“如果它没有坏,就不要试图修复它。” DevOps 版本是,“如果您没有破坏它并且可以解决它,请不要尝试修复它。”
使用 Python 3 在虚拟环境中安装 requirements.txt 文件:
我遇到过同样的问题。我试图在虚拟环境中安装 requirements.txt 文件。我找到了解决方案。
最初,我以这种方式创建了我的 virtualenv:
virtualenv -p python3 myenv
使用以下方法激活环境:
source myenv/bin/activate
现在我使用以下命令安装了 requirements.txt 文件:
pip3 install -r requirements.txt
安装成功,我能够导入模块。
virtualenv -p python myenv
、myenv\Scripts\activate.bat
、pip install -r requirements.txt
requirements.txt
中将本地定义的 deps 安装到 virtualenv 的部分问题的唯一答案。除非我错过了什么?总之感谢!
创建虚拟环境 python3 -m venv virtual-env (对于 windows 使用 python 而不是 python3)
激活你的虚拟环境源 virtual-env/bin/activate
现在安装要求 pip install -r requirements.txt
pip install --user -r requirements.txt
或者
pip3 install --user -r requirements.txt
requirements.txt
文件中指定 --user
?
使用 pip3 install -r requirements.txt
但请确保 requirements.txt 文件已从源中提取并且未添加到 .gitignore
在 Windows 中,这可能会减少与格式相关的路径问题,如果您有
c:\文件夹\子文件夹\requirements.txt
cd c:\folder\subfolder
pip install -r requirements.txt
我已经通过运行以下命令解决了:
py -m pip install ./requirements.txt
上面的命令将为 Django 项目安装所有依赖项和库。
不定期副业成功案例分享
pip install -r /path/to/requirements.txt
。这会检测到更改,升级包,然后不理会其他所有内容。requirements.txt
中的软件包有任何安装失败,则不会安装任何软件包。如果一个必需的模块在其安装过程中导入了一个依赖项(而不是仅仅将其列为需求),即使该依赖项在依赖项列表中位于它之前,它也会失败,从而导致所有模块失败。在安装过程中导入依赖模块可能是一个错误,但也可能出乎意料的是,requirements.txt
中列出的依赖项不是按顺序安装的,而是一次安装的。package.json
和requirements.txt
保留在整个项目的顶级目录中,或者保留在特定语言的子目录中。在这一点上,这是你的选择。